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 不发布它们……
这篇关于我如何专门发送到已开始的骆驼路线?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:我如何专门发送到已开始的骆驼路线?
基础教程推荐
- 问题http://apache.org/xml/features/xinclude测试日志4j 2 2022-01-01
- RabbitMQ:消息保持“未确认"; 2022-01-01
- Spring AOP错误无法懒惰地为此建议构建thisJoinPoin 2022-09-13
- 修改 void 函数的输入参数,然后读取 2022-01-01
- 存储 20 位数字的数据类型 2022-01-01
- 无法复制:“比较方法违反了它的一般约定!" 2022-01-01
- 如何对 Java Hashmap 中的值求和 2022-01-01
- REST Web 服务返回 415 - 不支持的媒体类型 2022-01-01
- 使用堆栈算法进行括号/括号匹配 2022-01-01
- Struts2 URL 无法访问 2022-01-01
