Camel: Content based routing, from different froms

1.3k views Asked by At

I have two programs, made up of three routes.

[  
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.  
] 

I want to run the one program based on input from my property file

<context:property-placeholder location="./run.properties"
    ignore-resource-not-found="false" />

But all I can find for content-based-routing, is examples where the choose is below the from. eg.

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

I want a way to rearrange to something like this:

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

There are 2 answers

0
djb On

The way I ended up doing it:

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();
3
Ben ODay On

you don't need content based routing to control whether routes are started...

just use the autoStartup(boolean) API to control this...

for example...

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

see http://camel.apache.org/configuring-route-startup-ordering-and-autostartup.html