...
Quartz2
...
Component
...
Available
...
as
...
of
...
Camel
...
2.12.0
...
The
...
quartz2:
...
component
...
provides
...
a
...
scheduled
...
delivery
...
of
...
messages
...
using
...
the
...
...
...
2.x .
Each endpoint represents a different timer (in Quartz terms, a Trigger and JobDetail).
Maven users will need to add the following dependency to their pom.xml
for this component:
Code Block | ||||
---|---|---|---|---|
| ||||
|http://www.quartz-scheduler.org/]. Each endpoint represents a different timer (in Quartz terms, a Trigger and JobDetail). Maven users will need to add the following dependency to their {{pom.xml}} for this component: {code:xml} <dependency> <groupId>org.apache.camel</groupId> <artifactId>camel-quartz2</artifactId> <version>x.x.x</version> <!-- use the same version as your Camel core version --> </dependency> {code} * |
NOTE:
...
Quartz
...
2.x
...
API
...
is
...
not
...
compatible
...
with
...
Quartz
...
1.x.
...
If
...
you
...
need
...
to
...
remain
...
on
...
old
...
Quartz
...
1.x,
...
please
...
use
...
the
...
old
...
...
component
...
instead.
...
URI
...
format
Code Block |
---|
{code} quartz2://timerName?options quartz2://groupName/timerName?options quartz2://groupName/timerName?cron=expression quartz2://timerName?cron=expression {code} |
The
...
component
...
uses
...
either
...
a
...
CronTrigger
...
or
...
a
...
SimpleTrigger
...
.
...
If
...
no
...
cron
...
expression
...
is
...
provided,
...
the
...
component
...
uses
...
a
...
simple
...
trigger.
...
If
...
no
...
groupName
...
is
...
provided,
...
the
...
quartz
...
component
...
uses
...
the
...
Camel
...
group
...
name.
...
You
...
can
...
append
...
query
...
options
...
to
...
the
...
URI
...
in
...
the
...
following
...
format,
...
?option=value&option=value&...
...
Options
Div | |||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| |||||||||||||||||||||||||||||||||||||||||||||
|
For example, the following routing rule will fire two timer events to the mock:results
endpoint:
Code Block | ||
---|---|---|
| ||
from("quartz2://myGroup/myTimerName?trigger.repeatInterval=2&trigger.repeatCount=1").routeId("myRoute").to("mock:result");
|
When using stateful=true
, the JobDataMap is re-persisted after every execution of the job, thus preserving state for the next execution.
Info | ||
---|---|---|
| ||
If you run in OSGi such as Apache ServiceMix, or Apache Karaf, and have multiple bundles with Camel routes that start from Quartz2 endpoints, then make sure if you assign |
Configuring quartz.properties file
By default Quartz will look for a quartz.properties
file in the org/quartz
directory of the classpath. If you are using WAR deployments this means just drop the quartz.properties in WEB-INF/classes/org/quartz
...
.
...
However
...
the
...
Camel
...
...
component
...
also
...
allows
...
you
...
to
...
configure
...
properties:
Div | ||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| ||||||||||||||
=confluenceTableSmall}
|| Parameter || Default || Type || Description ||
| {{properties}} | {{null}} | {{Properties}} | You can configure a {{
|
To do this you can configure this in Spring XML as follows
Code Block | ||||
---|---|---|---|---|
| ||||
| | {{propertiesFile}} | {{null}} | {{String}} | File name of the properties to load from the classpath | {div} To do this you can configure this in Spring XML as follows {code:xml} <bean id="quartz" class="org.apache.camel.component.quartz2.QuartzComponent"> <property name="propertiesFile" value="com/mycompany/myquartz.properties"/> </bean> {code} h3. Starting the Quartz scheduler The [Quartz2] component offers an option to let the Quartz scheduler be started delayed, or not auto started at all. {div:class=confluenceTableSmall} || Parameter || Default || Type || Description || | {{startDelayedSeconds}} | {{0}} | {{int}} | Seconds to wait before starting the quartz scheduler. | | {{autoStartScheduler}} | {{true}} | {{boolean}} | Whether or not the scheduler should be auto started. | {div} To do this you can configure this in Spring XML as follows {code:xml} <bean id="quartz |
Enabling Quartz scheduler in JMX
You need to configure the quartz scheduler properties to enable JMX.
That is typically setting the option "org.quartz.scheduler.jmx.export"
to a true
value in the configuration file.
From Camel 2.13 onwards Camel will automatic set this option to true, unless explicit disabled.
Starting the Quartz scheduler
The Quartz2 component offers an option to let the Quartz scheduler be started delayed, or not auto started at all.
Div | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
| ||||||||||||
|
To do this you can configure this in Spring XML as follows
Code Block | ||||
---|---|---|---|---|
| ||||
<bean id="quartz2" class="org.apache.camel.component.quartz2.QuartzComponent"> <property name="startDelayedSeconds" value="5"/> </bean> {code} h3. Clustering If you use Quartz in clustered mode, |
Clustering
If you use Quartz in clustered mode, e.g.
...
the
...
JobStore
...
is
...
clustered.
...
Then
...
the
...
...
component
...
will
...
not
...
pause/remove
...
triggers
...
when
...
a
...
node
...
is
...
being
...
stopped/shutdown.
...
This
...
allows
...
the
...
trigger
...
to
...
keep
...
running
...
on
...
the
...
other
...
nodes
...
in
...
the
...
cluster.
...
Note
...
:
...
When
...
running
...
in
...
clustered
...
node
...
no
...
checking
...
is
...
done
...
to
...
ensure
...
unique
...
job
...
name/group
...
for
...
endpoints.
Message Headers
Camel adds the getters from the Quartz Execution Context as header values. The following headers are added:
calendar
, fireTime
, jobDetail
, jobInstance
, jobRuntTime
, mergedJobDataMap
, nextFireTime
, previousFireTime
, refireCount
, result
, scheduledFireTime
, scheduler
, trigger
, triggerName
, triggerGroup
.
The fireTime
header contains the java.util.Date
of when the exchange was fired.
Using Cron Triggers
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.
For example, the following will fire a message every five minutes starting at 12pm (noon) to 6pm on weekdays:
Code Block |
---|
h3. Message Headers Camel adds the getters from the Quartz Execution Context as header values. The following headers are added: {{calendar}}, {{fireTime}}, {{jobDetail}}, {{jobInstance}}, {{jobRuntTime}}, {{mergedJobDataMap}}, {{nextFireTime}}, {{previousFireTime}}, {{refireCount}}, {{result}}, {{scheduledFireTime}}, {{scheduler}}, {{trigger}}, {{triggerName}}, {{triggerGroup}}. The {{fireTime}} header contains the {{java.util.Date}} of when the exchange was fired. h3. Using Cron Triggers Quartz supports [Cron-like expressions|http://www.quartz-scheduler.org/documentation/quartz-2.1.x/tutorials/crontrigger] 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|http://www.quartz-scheduler.org/docs/tutorials/crontrigger.html] on how to use cron expressions. For example, the following will fire a message every five minutes starting at 12pm (noon) to 6pm on weekdays: {code} from("quartz2://myGroup/myTimerName?cron=0+0/5+12-18+?+*+MON-FRI").to("activemq:Totally.Rocks"); {code} |
which
...
is
...
equivalent
...
to
...
using
...
the
...
cron
...
expression
Code Block |
---|
} 0 0/5 12-18 ? * MON-FRI {code} |
The
...
following
...
table
...
shows
...
the
...
URI
...
character
...
encodings
...
we
...
use
...
to
...
preserve
...
valid
...
URI
...
syntax:
Div | ||||
---|---|---|---|---|
| ||||
|
Specifying time zone
The Quartz Scheduler allows you to configure time zone per trigger. For example to use a timezone of your country, then you can do as follows:
Code Block |
---|
=confluenceTableSmall} ||URI Character||Cron character|| | {{\+}} | _Space_ | {div} h3. Specifying time zone The Quartz Scheduler allows you to configure time zone per trigger. For example to use a timezone of your country, then you can do as follows: {code} quartz2://groupName/timerName?cron=0+0/5+12-18+?+*+MON-FRI&trigger.timeZone=Europe/Stockholm {code} |
The
...
timeZone
...
value
...
is
...
the
...
values
...
accepted
...
by
...
java.util.TimeZone
...
.
Using QuartzScheduledPollConsumerScheduler
The Quartz2 component provides a Polling Consumer scheduler which allows to use cron based scheduling for Polling Consumer such as the File and FTP consumers.
For example to use a cron based expression to poll for files every 2nd second, then a Camel route can be define simply as:
Code Block |
---|
from("file:inbox?scheduler=quartz2&scheduler.cron=0/2+*+*+*+*+?")
.to("bean:process");
|
Notice we define the scheduler=quartz2
to instruct Camel to use the Quartz2 based scheduler. Then we use scheduler.xxx
options to configure the scheduler. The Quartz2 scheduler requires the cron option to be set.
The following options is supported:
Div | ||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| ||||||||||||||||||||||||
|
Important: Remember configuring these options from the endpoint URIs must be prefixed with scheduler.
.
For example to configure the trigger id and group:
Code Block |
---|
from("file:inbox?scheduler=quartz2&scheduler.cron=0/2+*+*+*+*+?&scheduler.triggerId=myId&scheduler.triggerGroup=myGroup")
.to("bean:process");
|
There is also a CRON scheduler in Spring, so you can use the following as well:
Code Block |
---|
from("file:inbox?scheduler=spring&scheduler.cron=0/2+*+*+*+*+?")
.to("bean:process");
|
Include Page | ||||
---|---|---|---|---|
|