动态生成多个 from() Apache Camel RouteBuilder [英] Generate multiple from() dynamically Apache Camel RouteBuilder
问题描述
我使用的是camel-core 2.24.1并且能够执行以下操作:
from(sources.toArray(new String[0]))
其中来源是我从配置设置中获得的 URI 列表.我正在尝试更新代码以使用 Camel 3(camel-core 3.0.0-RC2),但上面提到的方法已被删除,我找不到其他方法来完成相同的操作.
基本上我需要这样的东西:
from( 字符串 uri : 来源 ){//在继续路由之前将 uri 添加为 from(uri)}
如果这有助于更好地理解,最终路线应如下所示:
from( sources.toArray(new String[0]) ).routeId(Constants.ROUTE_ID).split().method(WorkRequestSplitter.class, "splitMessage").id(常量.WORK_REQUEST_SPLITTER_ID).split().method(RequestSplitter.class, "splitMessage").id(常量.REQUEST_SPLITTER_ID).选择().when(useReqProc).log(LoggingLevel.INFO, "找到使用它的请求处理器").to("bean:" + reqName).endChoice().除此以外().log(LoggingLevel.ERROR, "requestProcessor not found, 停止路由").停止().endChoice().结尾().log("发送请求的URI").recipientList(header(Constants.HDR_ARES_URI)).选择().when(useResProc).log(LoggingLevel.INFO, "找到使用它的结果处理器").to("bean:" + resName).endChoice().除此以外().log(LoggingLevel.INFO,未找到 resultProcessor,按原样发送").endChoice().结尾().log("发送请求给所有监听器").to( this.destinations.toArray( new String[0] ) );
任何帮助将不胜感激.
此功能在 CAMEL-6589.
请参阅迁移指南::><块引用>
在 Camel 2.x 中,您可以为 Camel 路由提供 2 个或更多输入,但是 Camel 中的所有用例都不支持此功能,并且此功能很少使用.这在 Camel 2.x 中也已被弃用.在 Camel 3 中,我们删除了用于为路由指定多个输入的剩余代码,现在只能为路由指定仅 1 个输入.
您始终可以使用 直接端点.这也可以使用 for-each 动态生成.
for(String uri : 来源){from(uri).to("direct:commonProcess");}从(直接:commonProcess").routeId(Constants.ROUTE_ID)//....log("发送请求给所有监听器").to(this.destinations.toArray(new String[0]));
I was using camel-core 2.24.1 and was able to do the following:
from( sources.toArray(new String[0]) )
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] ) );
Any help will be greatly appreciated.
This feature was removed with no direct replacement in CAMEL-6589.
See Migration guide:
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.
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屋!