本文介绍了如何独家发送到开始的骆驼路线?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
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?
推荐答案
通过建议使用交易所中的上下文并使用 ProducerTemplate .这就是我最终得到的:
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.我必须弄清楚为什么骆驼不释放它们...
这篇关于如何独家发送到开始的骆驼路线?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!