Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Apache Camel timer: "period" vs "fixedRate"

Tags:

apache-camel

What is the exact use of "period" and "fixedRate" together ? does it really make sense because if i specified the "period" value then anyways timer will trigger after that interval. So what is the exact use of "fixedRate" flag?

I am confused please help me out !

like image 613
user2606572 Avatar asked Jul 22 '13 11:07

user2606572


People also ask

What is timer in Apache Camel?

The Timer component is used to generate message exchanges when a timer fires. You can only consume events from this endpoint.

What is Bean in Apache Camel?

The Bean EIP is used for invoking a method on a bean, and the returned value is the new message body. The Bean EIP is similar to the Bean component which also is used for invoking beans, but in the form as a Camel component.

What is direct in camel?

The Direct component provides direct, synchronous invocation of any consumers when a producer sends a message exchange. This endpoint can be used to connect existing routes in the same camel context.


2 Answers

You can read the javadoc api of the java.util.Timer at: http://docs.oracle.com/javase/7/docs/api/java/util/Timer.html

They explain the difference between fixed rate and delayed.

like image 163
Claus Ibsen Avatar answered Oct 07 '22 06:10

Claus Ibsen


The Camel Timer Endpoint uses java.util.Timer.

If you set the fixedRate flag to true the following method is used :

java.util.Timer#scheduleAtFixedRate(java.util.TimerTask, java.util.Date, long)

Otherwise the following method is used :

java.util.Timer#schedule(java.util.TimerTask, java.util.Date, long)


If I understand the Javadoc of the Timer class a fixed-rate execution does not care about the execution time of the previous execution, only of the initial execution.

An example to clarify :

Take a timer with a fixed-rate execution with an initial execution at 12:00 and a period of 1 hour. The timer will (try to) start a third execution at 14:00 - even if, for some reason, the execution which should have started at 13:00 was delayed and actually started at 13:06.

If the timer did not have a fixed-rate execution it would (try to) start the third execution at 14:06.

like image 20
Kevin Vanbockryck Avatar answered Oct 07 '22 06:10

Kevin Vanbockryck