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?
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"