Enterprise Integration Zone is brought to you in partnership with:

Claus Ibsen is a principal software engineer from FuseSource. Claus is a full time committer on the open source integration framework Apache Camel (http://camel.apache.org) and author of the Camel in Action book (http://www.manning.com/ibsen). Claus is the most active contributor to Apache Camel and is very active in the Camel community. Claus is a frequent speaker at various conferences. Claus is a DZone MVB and is not an employee of DZone and has posted 51 posts at DZone. You can read more from them at their website. View Full User Profile

Apache Camel 2.12 - Even Easier Cron Scheduled Routes

  • submit to reddit

In the upcoming release of Apache Camel 2.12 we have introduced an SPI that allows users to plugin different schedulers for schedule-based consumers.

The motivation for this feature came from the fact that some Camel components have scheduled consumers.  Usually file and FTP consumers. By default, they use the scheduler from the JVM that can schedule based on a fixed period. Now, with the SPI, we allow a different scheduler to be used instead.

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

CRON expression
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 a space separator).

Example with Spring:

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

  Example with Quartz:

<from uri="file:inbox?scheduler=quartz2&scheduler.cron=0/10+6-18+*+*+MON-FRI"/>
To implement a similar solution in older releases of Camel, you would need to use sort in order to use a route policy. 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. With this new functionality in Camel 2.12, it's even easier to just define the cron expression in the endpoint URI directly.
There are more details in the Camel docs: - Polling Consumer - Quarz2 Component Camel-quartz2 is also a new component in the upcoming Apache Camel 2.12 release. In fact, we already have 14 new components. You can take a peek at the work-in-progress release notes to see what is coming down the road.
Published at DZone with permission of Claus Ibsen, author and DZone MVB. (source)

(Note: Opinions expressed in this article and its replies are the opinions of their respective authors and not those of DZone, Inc.)