Camel:基于内容的路由,来自不同的形式

时间:2014-11-10 11:35:58

标签: java apache-camel apache-karaf fuseesb

我有两个程序,由三条路线组成。

[  
one is a route, from JPA database to bean.  
one is a copier, from file system endpoint to file system endpoint  
]

[  
one is a uploader, from file system endpoint to bean.  
] 

我想根据我的属性文件

的输入运行一个程序
<context:property-placeholder location="./run.properties"
    ignore-resource-not-found="false" />

但我所能找到的基于内容的路由,就是选择低于from的示例。例如

from("direct:start")
    .choice()
        .when(body().contains("Camel"))
            .loadBalance().roundRobin().to("mock:foo").to("mock:bar")
        .otherwise()
            .to("mock:result");

我想要一种方法来重新排列这样的东西:

choice()
   .when(body().contains("Camel"))
      from("direct:start1").loadBalance().roundRobin().to("mock:foo").to("mock:bar")
   .otherwise()
      from("direct:start2").to("mock:result");

2 个答案:

答案 0 :(得分:2)

您不需要基于内容的路由来控制路由是否已启动...

只需使用autoStartup(boolean) API来控制此...

例如......

from("activemq:queue:special").autoStartup("{{startupRouteProperty}}").to("file://backup");

请参阅http://camel.apache.org/configuring-route-startup-ordering-and-autostartup.html

答案 1 :(得分:0)

我最终这样做的方式:

static ClassPathXmlApplicationContext context;
static CamelContext camel;

...

        context = new ClassPathXmlApplicationContext(
                "META-INF/spring/camel-context.xml");
        camel = new SpringCamelContext(context);

...

    if (property) {
        camel.addRoutes(new RouteBuilder() {
            public void configure() {
                from(..).to(..)
            }
        });
    } else {
        camel.addRoutes(new RouteBuilder() {
            public void configure() {
                from(..).to(..)
            }
        });
    }

    camel.start();