Camel provides two components for job scheduling and Automating tasks.
The Timer component can be used to generate message exchanges at regular intervals. The following table includes the common URI options used to configure the Timer component:
| Name | Default Value | Description |
|---|---|---|
| time | null | A java.util.Date the first event should be generated. |
| period | 1000 | If greater than 0, 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 option. |
| repeatCount | 0 | Specifies a maximum limit of number of fires. If you set it to 5, it will only fire five times. A value of zero or negative means fire forever. |
Run someMethod define in myBean 5 times every 60 seconds:
<route>
<from uri="timer://foo?repeatCount=5;period=60000"/>
<to uri="bean:myBean?method=someMethod"/>
</route>
The Quartz component provides more control of when tasks get executed. The following table includes the common URI options used to configure the Quartz component:
| Name | Default Value | Description |
|---|---|---|
| cron | none | Specifies a cron expression used to determine when the timer fires. |
| repeatCount | 0 | Specifies the number of times to repeat the trigger. A value of -1 causes the timer to repeat indefinitely. |
| repeatInterval | 0 | Specifies the interval in milliseconds at which to generate events. |
Cron-Expressions are made up of seven sub-expressions, that describe individual details of the schedule.
| Field name | Mandatory? | Allowed values | Allowed special characters |
|---|---|---|---|
| Seconds | Yes | 0-59 | * / , - |
| Minutes | Yes | 0-59 | * / , - |
| Hours | Yes | 0-23 | * / , - |
| Day of month | Yes | 1-31 | * / , - ? L W |
| Month | Yes | 1-12 or JAN-DEC | * / , - |
| Day of week | Yes | 1-7 or SUN-SAT | * / , - ? L # |
| Year | No | 1970�2099 | * / , - |
| Character | Description |
|---|---|
| * | Wild-cards can be used to say "every" possible value of this field. |
| / | can be used to specify increments to values. '0/15' in the Minutes field means 'every 15th minute of the hour, starting at minute zero'. '3/20' in the Minutes field, it would mean 'every 20th minute of the hour, starting at minute three' - same as specifying '3,23,43' . |
| ? | is allowed for the day-of-month and day-of-week fields. It is used to specify "no specific value". |
| L | This character is short-hand for "last". The value "L" in the day-of-month field means "the last day of the month" - day 31 for January, day 28 for February on non-leap years. If used in the day-of-week field by itself, it simply means "7" or "SAT". But if used in the day-of-week field after another value, it means "the last xxx day of the month" � for example "6L" or "FRIL" both mean "the last friday of the month". You can also specify an offset from the last day of the month, such as "L-3" which would mean the third-to-last day of the calendar month. |
| W | used to specify the weekday (Monday-Friday) nearest the given day. As an example, if you were to specify "15W" as the value for the day-of-month field, the meaning is: "the nearest weekday to the 15th of the month". |
| # | is used to specify "the nth" X weekday of the month. "6#3" or "FRI#3" in the day-of-week field means "the third Friday of the month". |
| Cron expression | Description |
|---|---|
| �0 0 12 ? * WED� | every Wednesday at 12:00:00 pm |
| �0 0 23 ? * MON-FRI� | every Monday to Friday at 23:00:00 pm |
| "0 0/5 * * * ?" | every 5 minutes |
| "10 0/5 * * * ?" | every 5 minutes, at 10 seconds after the minute (i.e. 10:00:10 am, 10:05:10 am, etc.). |
| "0 30 10-13 ? * WED,FRI" | at 10:30, 11:30, 12:30, and 13:30, on every Wednesday and Friday. |
<route>
<from uri="quartz://myGroup/myTimerName?cron=0+0+23+?+*+MON-FRI")/>
<to uri="bean:myBean?method=someMethodName"/>
</route>
Execute jdbc query every Monday night at 10PM and convert result to CSV format.
<camel:route id="testjdbc">
<camel:from uri="quartz://jdbcTask?cron=0+0+22+?+*+MON")" />
<camel:setBody>
<camel:constant>select * from employee</camel:constant>
</camel:setBody>
<camel:to uri="jdbc:dataSource"/>
<camel:marshal>
<camel:csv delimiter=","/>
</camel:marshal>
<camel:to uri="file://target/fileName=report.csv" />
</camel:route>