动态生成多个from()Apache Camel RouteBuilder [英] Generate multiple from() dynamically Apache Camel RouteBuilder
问题描述
我使用的是camel-core 2.24.1,并且能够执行以下操作:
I was using camel-core 2.24.1 and was able to do the following:
from( sources.toArray(new String[0]) )
其中sources是我从配置设置中获得的URI列表.我正在尝试更新代码以使用Camel 3(camel-core 3.0.0-RC2),但是上面提到的方法已删除,我找不到另一种方法来完成此任务.
where sources is a list of URIs that I get from a configuration settings. I am trying to update the code to use Camel 3 (camel-core 3.0.0-RC2) but the method mentioned above was removed and I can't find another way to accomplish the same.
基本上我需要类似的东西:
Basically I need something like:
from( String uri : sources )
{
// add the uri as from(uri) before continuing with the route
}
如果这有助于更好地理解,则最终路线应如下所示:
In case this would help understand better, the final route should look like:
from( sources.toArray(new String[0]) )
.routeId(Constants.ROUTE_ID)
.split().method(WorkRequestSplitter.class, "splitMessage")
.id(Constants.WORK_REQUEST_SPLITTER_ID)
.split().method(RequestSplitter.class, "splitMessage")
.id(Constants.REQUEST_SPLITTER_ID)
.choice()
.when(useReqProc)
.log(LoggingLevel.INFO, "Found the request processor using it")
.to("bean:" + reqName)
.endChoice()
.otherwise()
.log(LoggingLevel.ERROR, "requestProcessor not found, stopping route")
.stop()
.endChoice()
.end()
.log("Sending the request the URI")
.recipientList(header(Constants.HDR_ARES_URI))
.choice()
.when(useResProc)
.log(LoggingLevel.INFO, "Found the results processor using it")
.to("bean:" + resName)
.endChoice()
.otherwise()
.log(LoggingLevel.INFO, "resultProcessor not found, sending 'as is'")
.endChoice()
.end()
.log("Sending the request to all listeners")
.to( this.destinations.toArray( new String[0] ) );
任何帮助将不胜感激.
推荐答案
此功能已删除,没有直接替换在 CAMEL-6589 .
This feature was removed with no direct replacement in CAMEL-6589.
请参见迁移指南:>
在Camel 2.x中,您可能有2个或更多的Camel路由输入,但是在Camel中并非所有用例都支持此输入,因此很少使用此功能.Camel 2.x也已弃用该功能.在Camel 3中,我们删除了用于指定路线的多个输入的其余代码,现在仅可以指定路线的1个输入.
In Camel 2.x you could have 2 or more inputs to Camel routes, however this was not supported in all use-cases in Camel, and this functionality is seldom in use. This has also been deprecated in Camel 2.x. In Camel 3 we have removed the remaining code for specifying multiple inputs to routes, and its now only possible to specify exactly only 1 input to a route.
您始终可以使用直接端点.也可以使用for-each动态生成.
You can always split your route definition to logical blocks with Direct endpoint. This can be also generated dynamically with for-each.
for(String uri : sources){
from(uri).to("direct:commonProcess");
}
from("direct:commonProcess")
.routeId(Constants.ROUTE_ID)
//...
.log("Sending the request to all listeners")
.to(this.destinations.toArray(new String[0]));
这篇关于动态生成多个from()Apache Camel RouteBuilder的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!