Quartz has been edited by Claus Ibsen (Feb 28, 2009).

(View changes)

Content:

Quartz Component

The quartz: component provides a scheduled delivery of messages using the Quartz scheduler.
Each endpoint represents a different timer (in Quartz terms, a Trigger and JobDetail).

Setting cron _expression_

Setting the cron _expression_ in Camel 1.6.0 or older is based on path separators. We changed this for newer versions to be a single URI parameter instead.
Also its not possible to set the / cron special character (for increaments) in Camel 1.6.0 or older.

URI format

quartz://timerName?parameters
quartz://groupName/timerName?parameters
quartz://groupName/timerName/cronExpression       (@deprecated)
quartz://groupName/timerName/?cron=_expression_     (Camel 1.6.1 or newer)
quartz://timerName?cron=_expression_                (Camel 1.6.1 or newer)

Camel will either use a SimpleTrigger or a CronTrigger. If no cron _expression_ is given it will use a simple trigger.
If no groupName is provided Camel will use Camel as group name.

You can configure the Trigger and JobDetail using the parameters (if not using cron _expression_)

Parameter Default Description
trigger.repeatCount 0 SimpleTrigger: How many times should the timer repeat for?
trigger.repeatInterval 0 SimpleTrigger: The amount of time in milliseconds between repeated triggers
job.name null Sets the name of the job
job.XXX null Sets the job option with the XXX setter name
trigger.XXX null Sets the trigger option with the XXX setter name
stateful false Uses a Quartz StatefulJob instead of the default Job

For example the following routing rule will fire 2 timer events to the endpoint mock:results

from("quartz://myGroup/myTimerName?trigger.repeatInterval=2&trigger.repeatCount=1").to("mock:result");

When using a StatefulJob the JobDataMap is re-persisted after every execution of the job, thus preserving state for the next execution.

Message Headers

Camel adds the getters from Quartz Execution Context as header values. These headers is added:
calendar, fireTime, jobDetail, jobInstance, jobRuntTime, mergedJobDataMap, nextFireTime, previousFireTime, refireCount, result, scheduledFireTime, scheduler, trigger, triggerName, triggerGroup.

The fireTime header contains the java.util.Date for when the exchange was fired.

Using Cron Triggers

Avaiable as of Camel 1.6.1 or newer
Quartz supports Cron-like expressions for specifying timers in a handy format. You can use these expressions in the cron URI parameter; though to preserve valid URI encoding we allow _ to be used instead of spaces. Quartz provides a little tutorial on how to use cron expressions.

For example the following will fire a message at 12pm (noon) every day

from("quartz://myGroup/myTimerName?cron=0_0_12_*_*_?").to("activemq:Totally.Rocks");

which is equivalent to using the cron _expression_

0 0 12 * * ?

The following table shows the URI character encodings we use to preserve valid URI syntax

URI Character Cron character
'$' '?'

Using Cron Triggers in Camel 1.6.0 or older

@deprecated
Quartz supports Cron-like expressions for specifying timers in a handy format. You can use these expressions in the URI; though to preserve valid URI encoding we allow / to be used instead of spaces and $ to be used instead of ?.

For example the following will fire a message at 12pm (noon) every day

from("quartz://myGroup/myTimerName/0/0/12/*/*/$").to("activemq:Totally.Rocks");

which is equivalent to using the cron _expression_

0 0 12 * * ?

The following table shows the URI character encodings we use to preserve valid URI syntax

URI Character Cron character
'/' ' '
'$' '?'

See Also

Reply via email to