Oeg Bizz
Oeg Bizz

Reputation: 114

Generate multiple from() dynamically Apache Camel RouteBuilder

I was using camel-core 2.24.1 and was able to do the following:

from( sources.toArray(new String[0]) )

where sources is a list of URIs that I get from a configuration settings. I am trying to update the code to use Camel 3 (camel-core 3.0.0-RC2) but the method mentioned above was removed and I can't find another way to accomplish the same.

Basically I need something like:

from( String uri : sources )
{
   // add the uri as from(uri) before continuing with the route
}

In case this would help understand better, the final route should look like:

      from( sources.toArray(new String[0]) )
      .routeId(Constants.ROUTE_ID)
      .split().method(WorkRequestSplitter.class, "splitMessage")
        .id(Constants.WORK_REQUEST_SPLITTER_ID)
      .split().method(RequestSplitter.class, "splitMessage")
        .id(Constants.REQUEST_SPLITTER_ID)
      .choice()
        .when(useReqProc)
          .log(LoggingLevel.INFO, "Found the request processor using it")
          .to("bean:" + reqName)
        .endChoice()
        .otherwise()
          .log(LoggingLevel.ERROR, "requestProcessor not found, stopping route")
          .stop()
        .endChoice()
      .end()
      .log("Sending the request the URI")
      .recipientList(header(Constants.HDR_ARES_URI))
      .choice()
        .when(useResProc)
          .log(LoggingLevel.INFO, "Found the results processor using it")
          .to("bean:" + resName)
        .endChoice()
        .otherwise()
          .log(LoggingLevel.INFO, "resultProcessor not found, sending 'as is'")
        .endChoice()
      .end()
      .log("Sending the request to all listeners")
      .to( this.destinations.toArray( new String[0] ) );

Any help will be greatly appreciated.

Upvotes: 2

Views: 2533

Answers (1)

Bedla
Bedla

Reputation: 4929

This feature was removed with no direct replacement in CAMEL-6589.

See Migration guide:

In Camel 2.x you could have 2 or more inputs to Camel routes, however this was not supported in all use-cases in Camel, and this functionality is seldom in use. This has also been deprecated in Camel 2.x. In Camel 3 we have removed the remaining code for specifying multiple inputs to routes, and its now only possible to specify exactly only 1 input to a route.

You can always split your route definition to logical blocks with Direct endpoint. This can be also generated dynamically with for-each.

for(String uri : sources){
    from(uri).to("direct:commonProcess");
}

from("direct:commonProcess")
    .routeId(Constants.ROUTE_ID)
    //...
    .log("Sending the request to all listeners")
    .to(this.destinations.toArray(new String[0]));

Upvotes: 9

Related Questions