javaapache-camelcamel-sqlcamel-jdbc

Is there any component available in Camel to run standalone route?


I want a child route to run from a Timer route but the following code is not running properly:

Child route:

from("direct:processOrder").id("dd")
//  .setBody(constant("select * from customer"))
//  .to("jdbc:testdb")
    .to("sql:select * from EMPLOYEE?dataSource=masterdata")
    .log(LoggingLevel.INFO, "DB")
    .to("log:?level=INFO&showBody=true").end();

Main route:

from("timer://foo?period=30000")
    .log(LoggingLevel.INFO, "Triggered Company")
    .process(new Processor() {
      public void process(Exchange exchange) throws Exception {
        exchange.getContext().startRoute("dd");
      }
    })
    .end();

Output:

20/03/05 13:28:07 INFO impl.DefaultCamelContext: StreamCaching is not in use. If using streams then its recommended to enable stream caching. See more details at http://camel.apache.org/stream-caching.html
20/03/05 13:28:08 INFO impl.DefaultCamelContext: Route: dd started and consuming from: Endpoint[direct://processOrder]
20/03/05 13:28:08 INFO impl.DefaultCamelContext: Route: route1 started and consuming from: Endpoint[timer://foo?period=30000]
20/03/05 13:28:08 INFO impl.DefaultCamelContext: Total 2 routes, of which 2 is started.
20/03/05 13:28:08 INFO impl.DefaultCamelContext: Apache Camel 2.15.1 (CamelContext: camel-1) started in 0.400 seconds
20/03/05 13:28:09 INFO route1: Triggered Company
20/03/05 13:28:09 INFO impl.DefaultCamelContext: Route: dd started and consuming from: Endpoint[direct://processOrder]

What component to be used in from of the child route so that it just runs when we .startRoute from the main route program?


Solution

  • According to your log, both routes started correctly, so you don't need to execute .startRoute explicitly.

    To pass a signal to another route, call .to("direct:processOrder") in your parent route instead of running the processor you have now:

    from("timer://foo?period=30000")
      .log(LoggingLevel.INFO, "Triggered Company")
      .to("direct:processOrder")
      .end()