You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by zappee <ar...@gmail.com> on 2016/01/08 14:47:15 UTC

timer reschedule / loop between routes

Hi,

I am new in Apache Camel and have an interesting scenario. Could you please
help me?

My current route looks like this:
(1) mainRoute > timer://xxx?period=10000, to: "direct:apiCaller"
(2) apiCaller > retrieve data from restapi, to: "direct:persistData"
(3) persistData > save data to database

So every x second a restapi is called and the received data is persisted. It
works fine. But I need to call the restapi continuously until it receives an
empty answer in the rest response so I need to do a loop with (2) and (3)
steps. And then if there is no more data at moment then have to wait till
the next timer event is fired to start downloading the newcomer data if we
have.

So my route needs to do this:
(1) route1 > timer://xxx?period=10000, to: "direct:apiCaller"
--> do
(2) apiCaller > retrieve data from restapi, to: "direct:persistData"
(3) persistData > save data to database
--> while (answer of restapi is empty)

My first idea was to reschedule the timer from 1 minutes to 1 sec in case of
I have more data to download. And when we do not have more data to download
then reschedule my timer from 1 sec to 1 min just because of wait till a
little bit.

But I am not able to reschedule the timer runntime so it needs to be some
different solution to handle my use case.

What is the best way to reach my target?




--
View this message in context: http://camel.465427.n5.nabble.com/timer-reschedule-loop-between-routes-tp5776017.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: timer reschedule / loop between routes

Posted by Ravindra Godbole <go...@gmail.com>.
Can you maintain a persistent state for directcaller ? If you can do that
....

1. Timer always executes at predefined interval [ 1 sec or whatever
2. direct:apiCaller maintains a state STARTED, INPROGRESS, FINISHED.
3. if next call from timer sees that state is INPROGRESS then nothing
happens. If it is FINISHED then new execution started.

-Ravi


On Fri, Jan 8, 2016 at 7:17 PM, zappee <ar...@gmail.com> wrote:

> Hi,
>
> I am new in Apache Camel and have an interesting scenario. Could you please
> help me?
>
> My current route looks like this:
> (1) mainRoute > timer://xxx?period=10000, to: "direct:apiCaller"
> (2) apiCaller > retrieve data from restapi, to: "direct:persistData"
> (3) persistData > save data to database
>
> So every x second a restapi is called and the received data is persisted.
> It
> works fine. But I need to call the restapi continuously until it receives
> an
> empty answer in the rest response so I need to do a loop with (2) and (3)
> steps. And then if there is no more data at moment then have to wait till
> the next timer event is fired to start downloading the newcomer data if we
> have.
>
> So my route needs to do this:
> (1) route1 > timer://xxx?period=10000, to: "direct:apiCaller"
> --> do
> (2) apiCaller > retrieve data from restapi, to: "direct:persistData"
> (3) persistData > save data to database
> --> while (answer of restapi is empty)
>
> My first idea was to reschedule the timer from 1 minutes to 1 sec in case
> of
> I have more data to download. And when we do not have more data to download
> then reschedule my timer from 1 sec to 1 min just because of wait till a
> little bit.
>
> But I am not able to reschedule the timer runntime so it needs to be some
> different solution to handle my use case.
>
> What is the best way to reach my target?
>
>
>
>
> --
> View this message in context:
> http://camel.465427.n5.nabble.com/timer-reschedule-loop-between-routes-tp5776017.html
> Sent from the Camel - Users mailing list archive at Nabble.com.
>



-- 
- Ravi

*[ View My Youtube Channel ] <https://www.youtube.com/c/RavindraGodbole>*

Phone: +91 *98 509 760 91*

Re: timer reschedule / loop between routes

Posted by zappee <ar...@gmail.com>.
thx!



--
View this message in context: http://camel.465427.n5.nabble.com/timer-reschedule-loop-between-routes-tp5776017p5776100.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: timer reschedule / loop between routes

Posted by Torsten Kirschner <to...@sandbox.no>.
http://camel.apache.org/polling-consumer.html

NB Timer based polling consumer (this has a solution for you in source)
NB Scheduled Poll Components (which may be a more elegant way to og)



zappee <ar...@gmail.com> skrev følgende den 08.01.16, 14.47:

>Hi,
>
>I am new in Apache Camel and have an interesting scenario. Could you please
>help me?
>
>My current route looks like this:
>(1) mainRoute > timer://xxx?period=10000, to: "direct:apiCaller"
>(2) apiCaller > retrieve data from restapi, to: "direct:persistData"
>(3) persistData > save data to database
>
>So every x second a restapi is called and the received data is persisted. It
>works fine. But I need to call the restapi continuously until it receives an
>empty answer in the rest response so I need to do a loop with (2) and (3)
>steps. And then if there is no more data at moment then have to wait till
>the next timer event is fired to start downloading the newcomer data if we
>have.
>
>So my route needs to do this:
>(1) route1 > timer://xxx?period=10000, to: "direct:apiCaller"
>--> do
>(2) apiCaller > retrieve data from restapi, to: "direct:persistData"
>(3) persistData > save data to database
>--> while (answer of restapi is empty)
>
>My first idea was to reschedule the timer from 1 minutes to 1 sec in case of
>I have more data to download. And when we do not have more data to download
>then reschedule my timer from 1 sec to 1 min just because of wait till a
>little bit.
>
>But I am not able to reschedule the timer runntime so it needs to be some
>different solution to handle my use case.
>
>What is the best way to reach my target?
>
>
>
>
>--
>View this message in context: http://camel.465427.n5.nabble.com/timer-reschedule-loop-between-routes-tp5776017.html
>Sent from the Camel - Users mailing list archive at Nabble.com.