我是Apache骆驼的新手。我有一个非常常见的用例,我正在努力配置骆驼路由。用例是采用执行上下文
所以基本上是它的嵌套路线。在下面的配置中,我需要访问executionController在updateSchedulerState,sendNotification,processEvent和updateSchedulerState中创建的executionContext,即分别注释为1,2,3和4的步骤。
from("direct:processMessage")
.routeId("MessageExecutionRoute")
.beanRef("executionController", "getEvent", true)
.beanRef("executionController", "updateSchedulerState", true) (1)
.beanRef("executionController", "sendNotification", true) (2)
.beanRef("messageTransformer", "transform", true)
.to("wmq:NOTIFICATION")
.beanRef("executionController", "processEvent", true) (3)
.beanRef("eventProcessor", "process", true)
.beanRef("messageTransformer", "transform", true)
.to("wmq:EVENT")
.beanRef("executionController", "updateSchedulerState", true); (4)
请告诉我如何为上述用例配置路由。
谢谢, Vaibhav的
答案 0 :(得分:0)
所以你需要在路径中的不同点访问bean中的executionContext
吗?
如果我理解正确,您可以将此executionContext放在交换Property
中,它将在整个路径中保留。
设置交换属性可以通过Exchange.setProperty()
方法或各种camel dsl函数完成,例如:
from("direct:xyz)
.setProperty("awesome", constant("YES"))
//...
您可以通过添加类型Exchange
的方法参数来访问bean的交换属性,如下所示:
public class MyBean {
public void foo(Something something, Exchange exchange) {
if ("YES".equals(exchange.getProperty("awesome"))) {
// ...
}
}
}
或者通过@Property
这样:
public class MyBean {
public void foo(Something something, @Property String awesome) {
if ("YES".equals(awesome)) {
// ...
}
}
}
这假设您正在使用更高版本的驼峰。
这有帮助吗?