2013-08-15

Apache Camel 2.12 - Even easier cron scheduled routes

In the upcoming Apache Camel 2.12 we have recently introduced a SPI that allows to plugin different schedulers for scheduled based consumers.

So the motivation is that some Camel components has scheduled consumers, most know is the file and ftp consumers. By default they use the scheduler from the JVM that can schedule based on a fixed period. Though with the SPI we now allows a different scheduler to be used instead.

We have two cron based schedulers ready out of the box in the camel-quartz2 and camel-spring components. So you pick you favorite, or dive in and build your own scheduler.

CRON expression
So if you want to pickup files during working hours (polling every 10th second) on weekdays you can easily do this now (notice we use + as space separator)

... with Spring

<route>
<from uri="file:inbox?scheduler=spring&scheduler.cron=0/10+6-18+*+*+MON-FRI"/>
...

... with Quartz

<route>
<from uri="file:inbox?scheduler=quartz2&scheduler.cron=0/10+6-18+*+*+MON-FRI"/>
...

In older releases of Camel you would need to sort to use a route policy, to implement a similar solution. There is a cron based route policy that can be used to setup cron expressions when a route should be started, and when it should be stopped. Though with this new functionality in Camel 2.12, its even easier to just define the cron expression in the endpoint uri directly.

There is more details in the Camel docs at

And yeah camel-quartz2 is also a new component in the upcoming Apache Camel 2.12 release. In fact we have already 14 new components. You can peak at the work in progress release notes to see what is coming down the road.

No comments: