Apache驼峰嵌套路由

时间:2014-01-21 03:52:12

标签: apache apache-camel

我是Apache骆驼的新手。我有一个非常常见的用例,我正在努力配置骆驼路由。用例是采用执行上下文

  1. 使用执行上下文更新数据库。
  2. 然后在执行上下文中使用事件,创建一个字节消息并通过MQ发送。
  3. 然后在下一步中再次使用执行上下文并执行事件处理。
  4. 使用执行上下文更新数据库。
  5. 所以基本上是它的嵌套路线。在下面的配置中,我需要访问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的

1 个答案:

答案 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)) {
            // ...
        }
    }
}

这假设您正在使用更高版本的驼峰。

这有帮助吗?