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/04/02 17:03:21 UTC

Re: It is possible with Camel to use dynamic consumer? **after context start**

Hi

There is a ticket scheduled for Camel 3.0 to allow enrich and
pollEnrich to support "dynamic uris" like the recipient list can do.

Though implementing this requires an API change and thus scheduled for 3.0.

You can always use a java bean to consume from an dynamic computed
endpoint. For example using consumer template etc.

For ftp endpoints you may want to set disconnect=true, to avoid having
the connection running for a longer period.




On Sun, Mar 31, 2013 at 10:08 PM, Chris Wolf <cw...@gmail.com> wrote:
> Claus,
>
> You addressed the issue of "dynamic URIs for Consumers" back in July-2009:
>
> http://camel.465427.n5.nabble.com/Dynamic-consumers-with-Camel-td476433.html
>
> However, all those use-cases, except for maybe #4, web console, which
> I can't run all are about
> calculating the URI *before* the context is started.  What I'm looking
> for is a way to create and insert
> or update a polling consumer's URI - at runtime - *after* the context
> is started.
>
> For example:
>
>                  from("direct:start")
>                 .beanRef("config")
>                 .convertBodyTo(Document.class)
>                 .setHeader("Ftp_URI").xquery(
>                     "concat('ftp://'" +...some more xpaths into the
> inbound config doc...), String.class)
>                  .pollEnrich(/* whoops! this is referenced at route
> setup time, not route runtime... - it won't work */)
>                  .to("log:...");
>
> So the question, more generally, is is it possible to alter the route
> definition - at runtime? i.e. after the route/context are started?
>
> You sorted of hinted at this in that July-2009 posting when you said:
>
> "2) You can always stop, modify and start a route in Camel at runtime."
>
> I don't see how that would work since I would likely be attempting to
> modify the route at runtime
> from a bean method in the route - or are you suggesting one route
> stops/modifies another route?
>
> So the way I see it is - I would create the ftp route with a bogus URI
> and option "&startScheduler=false",
> on the ftp endpoint, or autoStart=false on the route.  Then in
> *another* route - the "configurer" route,
> I guess, access the ftp route and reconfigure the endpoint with the
> real settings, then start it's poll scheduler (or start it's route).
>
> Something like that?  Any easier, more direct way?
>
> Thanks,
>
>
> Chris



-- 
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: It is possible with Camel to use dynamic consumer? **after context start**

Posted by Chris Wolf <cw...@gmail.com>.
I actually was basing my current attempts based on what I read on that
page.  I thought if you used
a ScheduledPollingConsumer, that it would loop for you and didn't need
a while-loop.

I will just try plain PollingConsumer in a while-loop.

BTW, I found the ticket for dynamic URIs for FTP consumers:  CAMEL-4596

Thanks,


Chris

On Wed, Apr 3, 2013 at 5:07 AM, Claus Ibsen <cl...@gmail.com> wrote:
> You may want to see a little about consumer template here
> http://camel.apache.org/polling-consumer.html
>
> Notice the the consumer template polls one message at a time.
>
> If you want to "download all available files" you would need to run
> the code in a while loop as the example on that link.
>
> Though you can also add a new route at runtime with the from uri
> computed. And then stop and remove the route if not longer needed.
>
>
> On Tue, Apr 2, 2013 at 9:36 PM, Chris Wolf <cw...@gmail.com> wrote:
>> May I have the ticket #?  (so I can watch/follow)
>>
>> When you say, "use a java bean" - what do you mean?
>>
>> Instantiate the FTP component like?
>>
>>                         FtpComponent comp = new FtpComponent(context);
>>                         @SuppressWarnings("unchecked")
>>                         FtpEndpoint<FTPFile> endpt = (FtpEndpoint<FTPFile>)
>>
>> comp.createEndpoint("ftp://localhost/download?localWorkDirectory=/tmp/local/data&noop=true&username=fred&password=secret");
>>                         final FtpConsumer cons = (FtpConsumer)
>>                         endpt.createConsumer(new Processor() {
>>                             @Override
>>                             public void process(Exchange exchange)
>> throws Exception {
>>                                 System.out.printf("%s\n",
>> exchange.toString());
>>                             }
>>                         });
>>                         cons.setStartScheduler(true);
>>                         comp.start();
>>                         endpt.start();
>>                         cons.start();
>>
>> On Tue, Apr 2, 2013 at 11:03 AM, Claus Ibsen <cl...@gmail.com> wrote:
>>> Hi
>>>
>>> There is a ticket scheduled for Camel 3.0 to allow enrich and
>>> pollEnrich to support "dynamic uris" like the recipient list can do.
>>>
>>> Though implementing this requires an API change and thus scheduled for 3.0.
>>>
>>> You can always use a java bean to consume from an dynamic computed
>>> endpoint. For example using consumer template etc.
>>>
>>> For ftp endpoints you may want to set disconnect=true, to avoid having
>>> the connection running for a longer period.
>>>
>>>
>>>
>>>
>>> On Sun, Mar 31, 2013 at 10:08 PM, Chris Wolf <cw...@gmail.com> wrote:
>>>> Claus,
>>>>
>>>> You addressed the issue of "dynamic URIs for Consumers" back in July-2009:
>>>>
>>>> http://camel.465427.n5.nabble.com/Dynamic-consumers-with-Camel-td476433.html
>>>>
>>>> However, all those use-cases, except for maybe #4, web console, which
>>>> I can't run all are about
>>>> calculating the URI *before* the context is started.  What I'm looking
>>>> for is a way to create and insert
>>>> or update a polling consumer's URI - at runtime - *after* the context
>>>> is started.
>>>>
>>>> For example:
>>>>
>>>>                  from("direct:start")
>>>>                 .beanRef("config")
>>>>                 .convertBodyTo(Document.class)
>>>>                 .setHeader("Ftp_URI").xquery(
>>>>                     "concat('ftp://'" +...some more xpaths into the
>>>> inbound config doc...), String.class)
>>>>                  .pollEnrich(/* whoops! this is referenced at route
>>>> setup time, not route runtime... - it won't work */)
>>>>                  .to("log:...");
>>>>
>>>> So the question, more generally, is is it possible to alter the route
>>>> definition - at runtime? i.e. after the route/context are started?
>>>>
>>>> You sorted of hinted at this in that July-2009 posting when you said:
>>>>
>>>> "2) You can always stop, modify and start a route in Camel at runtime."
>>>>
>>>> I don't see how that would work since I would likely be attempting to
>>>> modify the route at runtime
>>>> from a bean method in the route - or are you suggesting one route
>>>> stops/modifies another route?
>>>>
>>>> So the way I see it is - I would create the ftp route with a bogus URI
>>>> and option "&startScheduler=false",
>>>> on the ftp endpoint, or autoStart=false on the route.  Then in
>>>> *another* route - the "configurer" route,
>>>> I guess, access the ftp route and reconfigure the endpoint with the
>>>> real settings, then start it's poll scheduler (or start it's route).
>>>>
>>>> Something like that?  Any easier, more direct way?
>>>>
>>>> Thanks,
>>>>
>>>>
>>>> Chris
>>>
>>>
>>>
>>> --
>>> 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
>
>
>
> --
> 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: It is possible with Camel to use dynamic consumer? **after context start**

Posted by Chris Wolf <cw...@gmail.com>.
Sorry, but I'm still a little confused...

Can you compare and contrast EventDrivenPollingConsumer vs.
ScheduledBatchPollingConsumer?

They both seem to support reading multiple times in an exchange...

Thanks,

Chris

On Wed, Apr 3, 2013 at 5:07 AM, Claus Ibsen <cl...@gmail.com> wrote:
> You may want to see a little about consumer template here
> http://camel.apache.org/polling-consumer.html
>
> Notice the the consumer template polls one message at a time.
>
> If you want to "download all available files" you would need to run
> the code in a while loop as the example on that link.
>
> Though you can also add a new route at runtime with the from uri
> computed. And then stop and remove the route if not longer needed.
>
>
> On Tue, Apr 2, 2013 at 9:36 PM, Chris Wolf <cw...@gmail.com> wrote:
>> May I have the ticket #?  (so I can watch/follow)
>>
>> When you say, "use a java bean" - what do you mean?
>>
>> Instantiate the FTP component like?
>>
>>                         FtpComponent comp = new FtpComponent(context);
>>                         @SuppressWarnings("unchecked")
>>                         FtpEndpoint<FTPFile> endpt = (FtpEndpoint<FTPFile>)
>>
>> comp.createEndpoint("ftp://localhost/download?localWorkDirectory=/tmp/local/data&noop=true&username=fred&password=secret");
>>                         final FtpConsumer cons = (FtpConsumer)
>>                         endpt.createConsumer(new Processor() {
>>                             @Override
>>                             public void process(Exchange exchange)
>> throws Exception {
>>                                 System.out.printf("%s\n",
>> exchange.toString());
>>                             }
>>                         });
>>                         cons.setStartScheduler(true);
>>                         comp.start();
>>                         endpt.start();
>>                         cons.start();
>>
>> On Tue, Apr 2, 2013 at 11:03 AM, Claus Ibsen <cl...@gmail.com> wrote:
>>> Hi
>>>
>>> There is a ticket scheduled for Camel 3.0 to allow enrich and
>>> pollEnrich to support "dynamic uris" like the recipient list can do.
>>>
>>> Though implementing this requires an API change and thus scheduled for 3.0.
>>>
>>> You can always use a java bean to consume from an dynamic computed
>>> endpoint. For example using consumer template etc.
>>>
>>> For ftp endpoints you may want to set disconnect=true, to avoid having
>>> the connection running for a longer period.
>>>
>>>
>>>
>>>
>>> On Sun, Mar 31, 2013 at 10:08 PM, Chris Wolf <cw...@gmail.com> wrote:
>>>> Claus,
>>>>
>>>> You addressed the issue of "dynamic URIs for Consumers" back in July-2009:
>>>>
>>>> http://camel.465427.n5.nabble.com/Dynamic-consumers-with-Camel-td476433.html
>>>>
>>>> However, all those use-cases, except for maybe #4, web console, which
>>>> I can't run all are about
>>>> calculating the URI *before* the context is started.  What I'm looking
>>>> for is a way to create and insert
>>>> or update a polling consumer's URI - at runtime - *after* the context
>>>> is started.
>>>>
>>>> For example:
>>>>
>>>>                  from("direct:start")
>>>>                 .beanRef("config")
>>>>                 .convertBodyTo(Document.class)
>>>>                 .setHeader("Ftp_URI").xquery(
>>>>                     "concat('ftp://'" +...some more xpaths into the
>>>> inbound config doc...), String.class)
>>>>                  .pollEnrich(/* whoops! this is referenced at route
>>>> setup time, not route runtime... - it won't work */)
>>>>                  .to("log:...");
>>>>
>>>> So the question, more generally, is is it possible to alter the route
>>>> definition - at runtime? i.e. after the route/context are started?
>>>>
>>>> You sorted of hinted at this in that July-2009 posting when you said:
>>>>
>>>> "2) You can always stop, modify and start a route in Camel at runtime."
>>>>
>>>> I don't see how that would work since I would likely be attempting to
>>>> modify the route at runtime
>>>> from a bean method in the route - or are you suggesting one route
>>>> stops/modifies another route?
>>>>
>>>> So the way I see it is - I would create the ftp route with a bogus URI
>>>> and option "&startScheduler=false",
>>>> on the ftp endpoint, or autoStart=false on the route.  Then in
>>>> *another* route - the "configurer" route,
>>>> I guess, access the ftp route and reconfigure the endpoint with the
>>>> real settings, then start it's poll scheduler (or start it's route).
>>>>
>>>> Something like that?  Any easier, more direct way?
>>>>
>>>> Thanks,
>>>>
>>>>
>>>> Chris
>>>
>>>
>>>
>>> --
>>> 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
>
>
>
> --
> 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: It is possible with Camel to use dynamic consumer? **after context start**

Posted by Claus Ibsen <cl...@gmail.com>.
You may want to see a little about consumer template here
http://camel.apache.org/polling-consumer.html

Notice the the consumer template polls one message at a time.

If you want to "download all available files" you would need to run
the code in a while loop as the example on that link.

Though you can also add a new route at runtime with the from uri
computed. And then stop and remove the route if not longer needed.


On Tue, Apr 2, 2013 at 9:36 PM, Chris Wolf <cw...@gmail.com> wrote:
> May I have the ticket #?  (so I can watch/follow)
>
> When you say, "use a java bean" - what do you mean?
>
> Instantiate the FTP component like?
>
>                         FtpComponent comp = new FtpComponent(context);
>                         @SuppressWarnings("unchecked")
>                         FtpEndpoint<FTPFile> endpt = (FtpEndpoint<FTPFile>)
>
> comp.createEndpoint("ftp://localhost/download?localWorkDirectory=/tmp/local/data&noop=true&username=fred&password=secret");
>                         final FtpConsumer cons = (FtpConsumer)
>                         endpt.createConsumer(new Processor() {
>                             @Override
>                             public void process(Exchange exchange)
> throws Exception {
>                                 System.out.printf("%s\n",
> exchange.toString());
>                             }
>                         });
>                         cons.setStartScheduler(true);
>                         comp.start();
>                         endpt.start();
>                         cons.start();
>
> On Tue, Apr 2, 2013 at 11:03 AM, Claus Ibsen <cl...@gmail.com> wrote:
>> Hi
>>
>> There is a ticket scheduled for Camel 3.0 to allow enrich and
>> pollEnrich to support "dynamic uris" like the recipient list can do.
>>
>> Though implementing this requires an API change and thus scheduled for 3.0.
>>
>> You can always use a java bean to consume from an dynamic computed
>> endpoint. For example using consumer template etc.
>>
>> For ftp endpoints you may want to set disconnect=true, to avoid having
>> the connection running for a longer period.
>>
>>
>>
>>
>> On Sun, Mar 31, 2013 at 10:08 PM, Chris Wolf <cw...@gmail.com> wrote:
>>> Claus,
>>>
>>> You addressed the issue of "dynamic URIs for Consumers" back in July-2009:
>>>
>>> http://camel.465427.n5.nabble.com/Dynamic-consumers-with-Camel-td476433.html
>>>
>>> However, all those use-cases, except for maybe #4, web console, which
>>> I can't run all are about
>>> calculating the URI *before* the context is started.  What I'm looking
>>> for is a way to create and insert
>>> or update a polling consumer's URI - at runtime - *after* the context
>>> is started.
>>>
>>> For example:
>>>
>>>                  from("direct:start")
>>>                 .beanRef("config")
>>>                 .convertBodyTo(Document.class)
>>>                 .setHeader("Ftp_URI").xquery(
>>>                     "concat('ftp://'" +...some more xpaths into the
>>> inbound config doc...), String.class)
>>>                  .pollEnrich(/* whoops! this is referenced at route
>>> setup time, not route runtime... - it won't work */)
>>>                  .to("log:...");
>>>
>>> So the question, more generally, is is it possible to alter the route
>>> definition - at runtime? i.e. after the route/context are started?
>>>
>>> You sorted of hinted at this in that July-2009 posting when you said:
>>>
>>> "2) You can always stop, modify and start a route in Camel at runtime."
>>>
>>> I don't see how that would work since I would likely be attempting to
>>> modify the route at runtime
>>> from a bean method in the route - or are you suggesting one route
>>> stops/modifies another route?
>>>
>>> So the way I see it is - I would create the ftp route with a bogus URI
>>> and option "&startScheduler=false",
>>> on the ftp endpoint, or autoStart=false on the route.  Then in
>>> *another* route - the "configurer" route,
>>> I guess, access the ftp route and reconfigure the endpoint with the
>>> real settings, then start it's poll scheduler (or start it's route).
>>>
>>> Something like that?  Any easier, more direct way?
>>>
>>> Thanks,
>>>
>>>
>>> Chris
>>
>>
>>
>> --
>> 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



-- 
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: It is possible with Camel to use dynamic consumer? **after context start**

Posted by Chris Wolf <cw...@gmail.com>.
May I have the ticket #?  (so I can watch/follow)

When you say, "use a java bean" - what do you mean?

Instantiate the FTP component like?

                        FtpComponent comp = new FtpComponent(context);
                        @SuppressWarnings("unchecked")
                        FtpEndpoint<FTPFile> endpt = (FtpEndpoint<FTPFile>)

comp.createEndpoint("ftp://localhost/download?localWorkDirectory=/tmp/local/data&noop=true&username=fred&password=secret");
                        final FtpConsumer cons = (FtpConsumer)
                        endpt.createConsumer(new Processor() {
                            @Override
                            public void process(Exchange exchange)
throws Exception {
                                System.out.printf("%s\n",
exchange.toString());
                            }
                        });
                        cons.setStartScheduler(true);
                        comp.start();
                        endpt.start();
                        cons.start();

On Tue, Apr 2, 2013 at 11:03 AM, Claus Ibsen <cl...@gmail.com> wrote:
> Hi
>
> There is a ticket scheduled for Camel 3.0 to allow enrich and
> pollEnrich to support "dynamic uris" like the recipient list can do.
>
> Though implementing this requires an API change and thus scheduled for 3.0.
>
> You can always use a java bean to consume from an dynamic computed
> endpoint. For example using consumer template etc.
>
> For ftp endpoints you may want to set disconnect=true, to avoid having
> the connection running for a longer period.
>
>
>
>
> On Sun, Mar 31, 2013 at 10:08 PM, Chris Wolf <cw...@gmail.com> wrote:
>> Claus,
>>
>> You addressed the issue of "dynamic URIs for Consumers" back in July-2009:
>>
>> http://camel.465427.n5.nabble.com/Dynamic-consumers-with-Camel-td476433.html
>>
>> However, all those use-cases, except for maybe #4, web console, which
>> I can't run all are about
>> calculating the URI *before* the context is started.  What I'm looking
>> for is a way to create and insert
>> or update a polling consumer's URI - at runtime - *after* the context
>> is started.
>>
>> For example:
>>
>>                  from("direct:start")
>>                 .beanRef("config")
>>                 .convertBodyTo(Document.class)
>>                 .setHeader("Ftp_URI").xquery(
>>                     "concat('ftp://'" +...some more xpaths into the
>> inbound config doc...), String.class)
>>                  .pollEnrich(/* whoops! this is referenced at route
>> setup time, not route runtime... - it won't work */)
>>                  .to("log:...");
>>
>> So the question, more generally, is is it possible to alter the route
>> definition - at runtime? i.e. after the route/context are started?
>>
>> You sorted of hinted at this in that July-2009 posting when you said:
>>
>> "2) You can always stop, modify and start a route in Camel at runtime."
>>
>> I don't see how that would work since I would likely be attempting to
>> modify the route at runtime
>> from a bean method in the route - or are you suggesting one route
>> stops/modifies another route?
>>
>> So the way I see it is - I would create the ftp route with a bogus URI
>> and option "&startScheduler=false",
>> on the ftp endpoint, or autoStart=false on the route.  Then in
>> *another* route - the "configurer" route,
>> I guess, access the ftp route and reconfigure the endpoint with the
>> real settings, then start it's poll scheduler (or start it's route).
>>
>> Something like that?  Any easier, more direct way?
>>
>> Thanks,
>>
>>
>> Chris
>
>
>
> --
> 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