You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by Claus Ibsen <cl...@gmail.com> on 2013/05/01 08:01:40 UTC

Re: How to dynamically configure directory on file consumer

Hi

This seems like a good idea. I have logged a ticket to make this easier
https://issues.apache.org/jira/browse/CAMEL-6329

On Tue, Apr 30, 2013 at 5:22 PM, Erker, Carsten
<Ca...@akquinet.de> wrote:
> Hi,
>
> we got a route starting with a File consumer (from("file://input"...) and a requirement to have the input directory configurable, i.e. in our application there is some admin functionality to change the directory which the file consumer is polling. This is stored in the database. I guess this is a fairly common use case, though I couldn't really find much in the docs / the Camel book, etc.
>
> From what I found I think I have to stop the route, do some magic and start it again. For the magic I tried setting properties on the FileEndpoint, FileConsumer, RouteContext, etc. After restart it always polls the original directory.
>
> How is the proposed way to do this?
>
> Thanks in advance
> Carsten



-- 
Claus Ibsen
-----------------
Red Hat, Inc.
FuseSource is now part of Red Hat
Email: cibsen@redhat.com
Web: http://fusesource.com
Twitter: davsclaus
Blog: http://davsclaus.com
Author of Camel in Action: http://www.manning.com/ibsen

Re: How to dynamically configure directory on file consumer

Posted by "Erker, Carsten" <Ca...@akquinet.de>.
I'd like to share my workaround in case anybody is interested (using Camel 2.11.0):
 
I was successful with the following approach:

        camelContext.stopRoute( "my-file-route", 30, SECONDS );
        camelContext.removeRoute( "my-file-route" );
        MyPollingRoutes newRoutes = new MyPollingRoutes( newPollDir );
        camelContext.addRoutes( newRoutes );

MyPollingRoutes extends RouteBuilder and in configure() I do something like:

        from( "file://" + this.pollDir + "?antInclude=*.xml" ).routeId( "my-file-route" )
                .to( ... );

This simply stops the existing route and replaces it with a new one (using a different path) during runtime.

It is necessary to create and add a new instance of MyPollingRoutes instead of just changing the pollDir member, since Camel wouldn't call configure() again after re-adding it to the context.


Re: How to dynamically configure directory on file consumer

Posted by "Erker, Carsten" <Ca...@akquinet.de>.
Claus,

thanks a lot for opening the ticket, using JMX would be a good way for changing the behavior during runtime.

@Tobias: In the meantime I'll try with your approach. Thanks for hinting to the properties component.




Am 01.05.2013 um 08:01 schrieb Claus Ibsen:

> Hi
> 
> This seems like a good idea. I have logged a ticket to make this easier
> https://issues.apache.org/jira/browse/CAMEL-6329
> 
> On Tue, Apr 30, 2013 at 5:22 PM, Erker, Carsten
> <Ca...@akquinet.de> wrote:
>> Hi,
>> 
>> we got a route starting with a File consumer (from("file://input"...) and a requirement to have the input directory configurable, i.e. in our application there is some admin functionality to change the directory which the file consumer is polling. This is stored in the database. I guess this is a fairly common use case, though I couldn't really find much in the docs / the Camel book, etc.
>> 
>> From what I found I think I have to stop the route, do some magic and start it again. For the magic I tried setting properties on the FileEndpoint, FileConsumer, RouteContext, etc. After restart it always polls the original directory.
>> 
>> How is the proposed way to do this?
>> 
>> Thanks in advance
>> Carsten
> 
> 
> 
> -- 
> Claus Ibsen
> -----------------
> Red Hat, Inc.
> FuseSource is now part of Red Hat
> Email: cibsen@redhat.com
> Web: http://fusesource.com
> Twitter: davsclaus
> Blog: http://davsclaus.com
> Author of Camel in Action: http://www.manning.com/ibsen