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).

Using cron expressions

Configuring the cron _expression_ in Camel 1.x is based on path separators. We changed this to an URI parameter in Camel 2.0 allowing a much nicer configuraiton.
Also its not possible to use the / cron special character (for increaments) in Camel 1.x, which Camel 2.0 also fixes.

URI format

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

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 2.0
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 _ or + 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 * * ?

Or you can use + as space in this complex cron _expression_:

from("quartz://myGroup/myTimerName?cron=0+0/5+12-18+?+*+MON-FRI").to("activemq:Totally.Rocks");

which is equivalent to using the cron _expression_

0 0/5 12-18 ? * MON-FRI

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.x

@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