Enterprise Integration Zone is brought to you in partnership with:

My name is Zemian Deng, and I am a Senior Application Engineer working at Oracle for the Enterprise Knowledge Management product. NOTE: The views expressed on my blog and social network are my own and do not necessarily reflect the views of my employer. Zemian is a DZone MVB and is not an employee of DZone and has posted 84 posts at DZone. You can read more from them at their website. View Full User Profile

Exploring Apache Camel Core - Timer Component

  • submit to reddit

Camel Timer is a simple and yet useful component. It brings the JDK’s timer functionality into your camel Route with very simple config.

    .process(new Processor() {
        public void process(Exchange msg) {
            LOG.info("Processing {}", msg);

That will generate a timer event message every second. You may short hand 1000 with 1s instead. It supports mfor minutes, or h for hours as well. Pretty handy.

Another useful timer feature is that it can limit (stop) the number of timer messages after a certain count. You simply need to add repeatCount option toward the url.

Couple of properties from the event message would be useful when handling the timer message. Here is an example how to read them.

    .process(new Processor() {
        public void process(Exchange msg) {
            java.util.Date fireTime = msg.getProperty(Exchange.TIMER_FIRED_TIME, java.util.Date.class);
            int eventCount = msg.getProperty(Exchange.TIMER_COUNTER, Integer.class);
            LOG.info("We received {}th timer event that was fired on {}", eventCount, fireTime);

There are more options availabe from Timer component that you may explore. Try it out with a Route and see it for yourself.

Published at DZone with permission of Zemian Deng, 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.)