1

I need to create a route, which periodically calls some process with a small delay between iterations.

When I look at documentation for looping:

The Loop allows for processing a message a number of times, possibly in a different way for each iteration. Useful mostly during testing.

So this is not useful for me, since I need to do an infinite loop (without the CamelLoopSize explicitly specified).

My second idea was using kind of a "recursion":

from("direct:updateLoop").routeId("updateLoop")
  .process(someProcess)
  ...
  .filter(someFilter)  // Can be used to stop the workflow
  .delay(18000000)  // Wait 5 hours and start again
  .to("direct:updateLoop")

This works well for a few days, however after about 600 iterations, this fails with StackOverflowException

Is there a better way to run my process in an infinite loop?

Peter
  • 580
  • 8
  • 22
  • 1
    Why not to use quartz or timer component? – Konstantin V. Salikhov Oct 09 '14 at 08:33
  • Because I cannot determine in advance how long it will take the process to be finished. The process can take few minutes or few days to be done. When I set up just a timer, there will be a possibility of concurrent processing of the same data set. Setting-up a delay simply fits better for my use case. – Peter Oct 09 '14 at 08:38
  • How about polling consumer pattern? – vikingsteve Oct 09 '14 at 09:10

2 Answers2

4

Use Camel Timer component:

from("timer://foo?fixedRate=false&period=18000000")
     .process(someProcess);

If fixedRate is false, then no overlapping will occur, see Apache Camel timer: "period" vs "fixedRate"

Community
  • 1
  • 1
Peter Keller
  • 7,526
  • 2
  • 26
  • 29
2

For recursion you can use camel's seda component.

from("seda:updateLoop").routeId("updateLoop")
    .process(someProcess)
    ...
    .filter(someFilter)  // Can be used to stop the workflow
    .delay(18000000)  // Wait 5 hours and start again
    .to("seda:updateLoop");
Ben Keil
  • 1,050
  • 1
  • 10
  • 30
  • 1
    I have upvoted because it is solution for really long processing - I mean I had many data, which were transported using camel from destination A to destination B, until there is something in A.. That caused stackoverflow, just because the stack was too long (without recursion!) – Cipous Jun 10 '16 at 09:49