2015-02-05 65 views
0

我试图路由基于三个不同的标准的对象。骆驼路由与自定义方法

我的问题是:

1)为什么我有没有即路由对象转到过滤器中的一个随机的方式,而不是线性的?

2)如果这不起作用(示例),我应该怎么做,如果我用“选择”和“何时”来做,我可以使用自定义方法来路由吗?就像这个例子使用过滤器

非常感谢

示例所示IM:

camelContext.addRoutes(new RouteBuilder() { 
@Override 
public void configure() throws Exception {         

    from("activemq:cfes.queue").filter().method(CustomCamelFilter.class, "methodOne") 
     .to("file://c:/u01/tomcat_conf/folder1");    

    from("activemq:cfes.queue").filter().method(CustomCamelFilter.class, "methodTwo") 
     .to("file://c:/u01/tomcat_conf/folder2"); 

    from("activemq:cfes.queue").filter().method(CustomCamelFilter.class, "methodThree") 
     .to("file://c:/u01/tomcat_conf/folder3"); 

回答

0

这是不正确的在这里使用的.filter()模式,当它看来你确实应该使用.choice()模式相反,像这样:

.choice() 
    .when(method(MyBean.class, "methodOne")).log("HELLO1") 
    .when(method(MyBean.class, "methodTwo")).log("HELLO2") 
    .when(method(MyBean.class, "methodThree")).log("HELLO3") 
    .otherwise().log("OOPS!") 
.end() 
+0

正是我所需要的。谢谢 – rogerbax 2015-02-05 13:40:56

+0

不用担心,不客气。 – vikingsteve 2015-02-05 13:44:40