How to I exclusively send to started Camel routes?(我如何专门发送到已开始的骆驼路线?)
问题描述
public class MyRoute extends RouteBuilder {
@Override
public void configure() {
from("servlet://myservlet")
.multicast()
.parallelProcessing().recipientList(bean(this))
.end();
}
@RecipientList
public List<String> route(String body) {
return getContext().getRouteDefinitions().stream()
.filter(i -> i.getStatus(getContext()).isStarted() && i.getId().startsWith("FOO"))
.map(OptionalIdentifiedDefinition::getId)
.collect(toList());
}
}
当我调试时,我看到 getContext().getRouteDefinitions()
是空的,即使路由实际上已经启动.我做错了什么?
When I debug, I see that getContext().getRouteDefinitions()
is empty, even though the routes are actually started. What am I doing wrong?
推荐答案
RomanVottner 通过建议使用交换中的上下文和使用 生产者模板.这是我最终得到的结果:
RomanVottner provided a lot of insight by suggesting using the context from the exchange, and using ProducerTemplate. Here's what I ended up with:
from("servlet://my-endpoint")
.process(exchange -> {
ProducerTemplate template = exchange.getContext().createProducerTemplate();
exchange.getContext().getRouteDefinitions().stream()
.filter(routeDef ->
routeDef.getStatus(getContext()).isStarted() && i.getId().startsWith("FOO"))
.map(OptionalIdentifiedDefinition::getId)
.forEach(endpoint ->
template.asyncSendBody(endpoint, exchange.getIn().getBody()));
});
警告!在生产中使用 asyncSendBody 后,机器很快就用完了 PID.我得弄清楚为什么 Camel 不发布它们……
这篇关于我如何专门发送到已开始的骆驼路线?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:我如何专门发送到已开始的骆驼路线?


基础教程推荐
- 降序排序:Java Map 2022-01-01
- 在 Libgdx 中处理屏幕的正确方法 2022-01-01
- Java:带有char数组的println给出乱码 2022-01-01
- 如何使用 Java 创建 X509 证书? 2022-01-01
- 设置 bean 时出现 Nullpointerexception 2022-01-01
- “未找到匹配项"使用 matcher 的 group 方法时 2022-01-01
- Java Keytool 导入证书后出错,"keytool error: java.io.FileNotFoundException &拒绝访问" 2022-01-01
- 无法使用修饰符“public final"访问 java.util.Ha 2022-01-01
- FirebaseListAdapter 不推送聊天应用程序的单个项目 - Firebase-Ui 3.1 2022-01-01
- 减少 JVM 暂停时间 >1 秒使用 UseConcMarkSweepGC 2022-01-01