The timer: component is used to generate message exchanges when a timer fires You can only consume events from this endpoint.
timer:name?options
Where name of the Timer object which is created and shared across endpoints. So if you use the same name for all your timer endpoints then only one Timer object & thread will be used.
Notice: The IN body of the generated exchange is
null
. So exchange.getIn().getBody()
returns
null
.
![]() | Advanced Scheduler |
---|---|
See also the Quartz component that supports much more advanced scheduling. |
Where options is a query string that can specify any of the following parameters:
Name | Default Value | Description |
---|---|---|
time | null | A java.util.Date the first event
should be generated |
period | 1000 | If greater than 0, then generate periodic events every period milliseconds |
delay | 0 | The number of milliseconds to wait before the first event is generated. Should not be used in conjunction with the time parameter. |
fixedRate | false | Events take place at approximately regular intervals, separated by the specified period |
daemon | true | Should the thread associated with the timer endpoint be run as a daemon |
When the timer is fired it adds the following information as properties to the Exchange.
Name | Type | Description |
---|---|---|
org.apache.camel.timer.name | String | the name option |
org.apache.camel.timer.time | Date | the time option |
org.apache.camel.timer.period | long | the period option |
org.apache.camel.timer.firedTime | Date | FUSE Mediation Router 1.5: the current time when the consumer fired |
When the timer is fired it adds the following information as headers to the IN message
Name | Type | Description |
---|---|---|
firedTime | Date | FUSE Mediation Router 1.5: the current time when the consumer fired |
To setup a route that generates an event every 60 seconds:
from("timer://foo?fixedRate=true&period=60000").to("bean:myBean?method=someMethodName");
The above route will generate an event then invoke the someMethodName on the bean called myBean in the Registry such as JNDI or Spring.
And the route in Spring DSL:
<route> <from uri="timer://foo?fixedRate=true&period=60000"/> <to uri="bean:myBean?method=someMethodName"/> </route>