camel-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From edvicif <>
Subject Re: How to grab a (only one) file with camel ?
Date Thu, 23 Feb 2012 16:10:36 GMT
I have a solution. Not sure this is the final form.

Dynamic Router Factory

I've created a DynamicRouteBuilder. Which dynamically create a route, with a
direct entry point and a configurable exit point.

class DynamicRouteBuilder extends RouteBuilder{
  private final String enrichUri;
  private final String outUri;
  private final String routeId;
  private static final AggregationStrategy MY_AGGREGATION_STRATEGY = new

  public DynamicRouteBuilder(String enrichUri, String outUri, String
routeId) {
    this.enrichUri = enrichUri;
    this.outUri = outUri;
    this.routeId = routeId;

  //Dynamic route creation
  public void configure() throws Exception {
    from("direct:"+routeId).id(routeId) //Dynamic entry point
      .pollEnrich(enrichUri, 2000, MY_AGGREGATION_STRATEGY)
      .to(outUri) //Exit point, where we can wait staically to continue
      .process(new *ShutDownProcessor*());
  //Route shutdown it self after completion
  private final class *ShutDownProcessor* implements Processor {
    public void process(Exchange exchange) throws Exception {
      CamelContext camelContext = exchange.getContext();
  ... Aggregation Strategy implemetation left off to spare some space

The router expects a name, which will be served as an entry point to this
route. We enrich it, than forwardingit to an existing static route.

After sending out the message basically we call the Shutdown processor,
which destroys the route. So basically the route exist for one message.
There could be an issue if because async we send multiple message. But that
is why routeId is configruable. Maybe with combining dynamic router EIP  it can be

Invoking Dynamic Route

            .process(new Processor() {
              public void process(Exchange exchange) throws Exception {
                String fileName = exchange.getIn().getBody(String.class);
                DynamicRouteBuilder dynamicRouteBuilder = new
DynamicRouteBuilder("file:target/test-classes/fileTest?fileName=" +
                    "*eventFilePooler*"); //dynamic route name
            .to("direct:*eventFilePooler*"); //sending the message to the
dynamic route

The fileCopier route just creates the dynamic route with a specific direct
endpoint. It specify the file, what he want to consume using enpoint uri and
where I'd like to route the results (direct:eventFileProducer)

Exitpoint of Dynamic Route

So from now on I have a statical route to continue the processing
from("direct:*eventFileProducer*").to("log:doEverything as usual");

I don't know this is what we are looking for.

View this message in context:
Sent from the Camel - Users mailing list archive at

View raw message