[英]Apache Camel / Java DSL / How to add a list of processors?
In my project I have several routes, which all have a similar setup.在我的项目中,我有几条路线,它们都有相似的设置。 Concrete values for endpoints and property-values as well as which processors should be used are resolved from a config-file.
端点和属性值的具体值以及应使用的处理器从配置文件中解析。
Thus, I created a method to setup those routes.因此,我创建了一种方法来设置这些路由。 One parameter is a List or Array of processor-names.
一个参数是处理器名称列表或数组。 Is there a possibility to add a this list of processor-references to the route-definition?
是否有可能将此处理器引用列表添加到路由定义中?
protected void setupRoute(String routeKey, String nbiSystemName, String requestEndpointUrl,
String defaultSbi, String reqSwitchRouteId, ArrayList<String> processorNames) {
from(requestEndpointUrl)
.routeId(routeKey).transacted()
.setProperty(PROPERTY_CBS_STARTTIME, simple("${date:now:yyyy-MM-dd'T'HH:mm:ss.SSS'Z'}"))
.setProperty(PROPERTY_CBS_NBI, constant(nbiSystemName))
.setProperty(PROPERTY_CBS_SBI, constant(defaultSbi))
// At this place I want to add all of the processors like
// .process("processorName")
.to("direct:" + reqSwitchRouteId );
}
As a workaround I considered using .loop()
or .loopDoWhile()
with beans instead of processors.作为一种解决方法,我考虑将
.loop()
或.loopDoWhile()
与 bean 而不是处理器一起使用。 But this is the wrong approach from my point of view, because I already know which processors should be used when I setup the route-definition.但从我的角度来看,这是错误的方法,因为我已经知道在设置路由定义时应该使用哪些处理器。
The simplest solution here is just iterating over the list and updating the route definition:这里最简单的解决方案就是遍历列表并更新路由定义:
RouteDefinition route = from(requestEndpointUrl)
.routeId(routeKey).transacted()
.setProperty(PROPERTY_CBS_STARTTIME,
simple("${date:now:yyyy-MM-dd'T'HH:mm:ss.SSS'Z'}"))
.setProperty(PROPERTY_CBS_NBI, constant(nbiSystemName))
.setProperty(PROPERTY_CBS_SBI, constant(defaultSbi));
for(String processorName: processorNames)
route = route.process(processorName);
route.to("direct:" + reqSwitchRouteId );
An alternative solution would be to use the RoutingSlip
pattern, where you dynamically prepare (and store in a header) the list of the next endpoints.另一种解决方案是使用
RoutingSlip
模式,您可以在其中动态准备(并存储在标头中)下一个端点的列表。 But of course, this requires you to turn your processors into endpoints.但是,当然,这需要您将处理器变成端点。
More info at: https://camel.apache.org/components/latest/eips/routingSlip-eip.html更多信息: https://camel.apache.org/components/latest/eips/routingSlip-eip.html
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.