2014-01-21 256 views
0

我是Apache骆驼的新手。我有很常见的用例,我正在努力配置骆驼路线。用例是执行上下文Apache骆驼嵌套路由

  1. 使用执行上下文更新数据库。
  2. 然后,使用上的执行上下文事件,创建一个字节的消息,并发送在MQ。
  3. 然后,在下一步骤中再次使用的执行上下文,并执行事件处理。
  4. 使用执行上下文更新数据库。

所以基本上它的种类嵌套路线。在下面的配置中,我需要访问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

所以你需要在不同的点在路由访问此executionContext在你的豆?

如果我理解正确的话,你可以把这个执行上下文在交换Property,它会持续整个路线。

设置交换性能可以通过Exchange.setProperty()方法或各种骆驼DSL功能来完成,例如是这样的:

from("direct:xyz) 
    .setProperty("awesome", constant("YES")) 
    //... 

可以从豆中加入Exchange类型的方法参数访问交换性能,如这样的:

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

这假定您正在使用更高版本的骆驼。

这是否帮助?