You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by Christian Schäfer <sy...@yahoo.de> on 2013/01/20 23:40:51 UTC

How to force http consuming route to run only once?

Hello,
is there a way to force the execution of a http consuming route to run only once?

My use case: I have a route (from("http//server.com/file.txt").to(...) ) that is created with autostart false.

Another route is responsible to trigger that http route to consume the file.

My problem: sometimes when suspending/stopping of the http route (via camelcontext) isn't fast enough the http route route runs again.

Is there a way / parameter to prevent this?

I just found a an ugly workaround by setting a high delay at the end of the route.
But I don't think that it is good because suspension or stopping of the route seems to me like aborting or killing the route (which is "busy" with delaying)

Would appreciate any suggestion?

regards,
Chris

Re: How to force http consuming route to run only once?

Posted by Henryk Konsek <he...@gmail.com>.
> In fact, I tried the following which seemed to work
> from("timer:httpRequestTrigger?repeatCount=1").to("http..

Great to hear that :) .

> Isthere actually a real use case where from(http://...) makes sense?

HTTP consumer is a polling one. It makes perfect sense to use it when
you want to periodically scan HTTP address for the updates.

> Whats are the reasons to prefer
> from(...).enrich("http://...").to("file://...")
> to
> from(...).to("http://...").to("file://...")

As far as I know, unless you don't specify aggregation strategy (what
is possible in the case of 'enrich') these to notations works exactly
in the same way. As far as I know :) .

I personally prefer to use "enrich" as it explicitly refers to the EIP
and is obvious even for non-Camel users. Using "double-to" may be
confused with the multicast [1].

> For this question, RTFM would be a valid answeri guess...but maybe someone could give a brief answer, please?
> (as I didn't find an obvious reason on http://camel.apache.org/http.html)

Indeed HTTP component documentation doesn't say how to use it as a
polling consumer (i.e. from("http://...). I've added it to my personal
backlog and will try to add this information to our documentation.
Thanks for pointing this lack.

If you find anything else unclear in Camel reference documentation -
just drop us a line here on the mailing list. We promise to fix it :)
.

Best regards.

[1] http://camel.apache.org/multicast.html

--
Henryk Konsek
http://henryk-konsek.blogspot.com

Re: How to force http consuming route to run only once?

Posted by Christian Schäfer <sy...@yahoo.de>.
Thanks Willem, thanks Henryk for your suggestions.

Will try that to find out what makes most sense.

In fact, I tried the following which seemed to work
from("timer:httpRequestTrigger?repeatCount=1").to("http..


Isthere actually a real use case where from(http://...) makes sense?

Whats are the reasons to prefer 
from(...).enrich("http://...").to("file://...")
to
from(...).to("http://...").to("file://...")

For this question, RTFM would be a valid answeri guess...but maybe someone could give a brief answer, please?
(as I didn't find an obvious reason on http://camel.apache.org/http.html)


 
Thank your for your comments

kind regards,
Christian


________________________________
 Von: Henryk Konsek <he...@gmail.com>
An: users@camel.apache.org 
Gesendet: 16:23 Montag, 21.Januar 2013
Betreff: Re: How to force http consuming route to run only once?
 
> I think you can change your route from pulling request to direct producer mode.

Just a little addition to Willem's answer.

If you need to issue HTTP request on demand (for example once) do not
use HTTP pull consumer, as you don't want to scan the endpoint
continuously. Instead trigger the HTTP enricher [1] on some event.

from(...).enrich("http://...").to("file://...")
or
from(...).to("http://...").to("file://...")

Some event sources you might be interested in:

___DIRECT___ [2]
Route:
from("direct:httpRequest").enrich("http://...")...

Client:
producerTemplate.sendBody("direct:httpRequest", new MyHttpRequest())


___TIMER (ONCE)___ [3]

Route:
from("timer:httpRequestTrigger?repeatCount=1").enrich("http://...")...

No client code is needed in this case.


___GUAVA EVENT BUS___ [4]
Route:
from("guava-eventbus:httpRequestBus?eventClass=MyHttpRequest").enrich("http://...")...

Client:
@Inject EventBus httpRequestBus;
...
httpRequestBus.post(new MyHttpRequest())
_______________________

Best regards.


[1] http://camel.apache.org/content-enricher.html
[2] http://camel.apache.org/direct.html
[3] http://camel.apache.org/timer.html
[4] http://camel.apache.org/guava-eventbus.html

Re: How to force http consuming route to run only once?

Posted by Henryk Konsek <he...@gmail.com>.
> I think you can change your route from pulling request to direct producer mode.

Just a little addition to Willem's answer.

If you need to issue HTTP request on demand (for example once) do not
use HTTP pull consumer, as you don't want to scan the endpoint
continuously. Instead trigger the HTTP enricher [1] on some event.

from(...).enrich("http://...").to("file://...")
or
from(...).to("http://...").to("file://...")

Some event sources you might be interested in:

___DIRECT___ [2]
Route:
from("direct:httpRequest").enrich("http://...")...

Client:
producerTemplate.sendBody("direct:httpRequest", new MyHttpRequest())


___TIMER (ONCE)___ [3]

Route:
from("timer:httpRequestTrigger?repeatCount=1").enrich("http://...")...

No client code is needed in this case.


___GUAVA EVENT BUS___ [4]
Route:
from("guava-eventbus:httpRequestBus?eventClass=MyHttpRequest").enrich("http://...")...

Client:
@Inject EventBus httpRequestBus;
...
httpRequestBus.post(new MyHttpRequest())
_______________________

Best regards.


[1] http://camel.apache.org/content-enricher.html
[2] http://camel.apache.org/direct.html
[3] http://camel.apache.org/timer.html
[4] http://camel.apache.org/guava-eventbus.html

Re: How to force http consuming route to run only once?

Posted by Willem jiang <wi...@gmail.com>.
Hi,

I think you can change your route from pulling request to direct producer mode.
The route is just like this:
from("direct:start").to("http://server.com/file.txt").

If you need to pulling the file from the server just once, you can send a empty message to the "direct:start" with the camel ProducerTemplate[1].

[1]http://camel.apache.org/producertemplate.html  

--  
Willem Jiang

Red Hat, Inc.
FuseSource is now part of Red Hat
Web: http://www.fusesource.com | http://www.redhat.com
Blog: http://willemjiang.blogspot.com (http://willemjiang.blogspot.com/) (English)
          http://jnn.iteye.com (http://jnn.javaeye.com/) (Chinese)
Twitter: willemjiang  
Weibo: 姜宁willem





On Monday, January 21, 2013 at 6:40 AM, Christian Schäfer wrote:

> Hello,
> is there a way to force the execution of a http consuming route to run only once?
>  
> My use case: I have a route (from("http//server.com/file.txt (http://server.com/file.txt)").to(...) ) that is created with autostart false.
>  
> Another route is responsible to trigger that http route to consume the file.
>  
> My problem: sometimes when suspending/stopping of the http route (via camelcontext) isn't fast enough the http route route runs again.
>  
> Is there a way / parameter to prevent this?
>  
> I just found a an ugly workaround by setting a high delay at the end of the route.
> But I don't think that it is good because suspension or stopping of the route seems to me like aborting or killing the route (which is "busy" with delaying)
>  
> Would appreciate any suggestion?
>  
> regards,
> Chris