Questo contenuto non è disponibile nella lingua selezionata.
Chapter 269. Quartz Component (deprecated)
Available as of Camel version 1.0
The quartz: component provides a scheduled delivery of messages using the Quartz Scheduler 1.x.
Each endpoint represents a different timer (in Quartz terms, a Trigger and JobDetail).
If you are using Quartz 2.x then from Camel 2.12 onwards there is a Quartz2 component you should use
Maven users will need to add the following dependency to their pom.xml
for this component:
<dependency> <groupId>org.apache.camel</groupId> <artifactId>camel-quartz</artifactId> <version>x.x.x</version> <!-- use the same version as your Camel core version --> </dependency>
269.1. URI format
quartz://timerName?options quartz://groupName/timerName?options quartz://groupName/timerName?cron=expression quartz://timerName?cron=expression
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&…
269.2. Options
The Quartz component supports 8 options, which are listed below.
Name | Description | Default | Type |
---|---|---|---|
factory (advanced) | To use the custom SchedulerFactory which is used to create the Scheduler. | SchedulerFactory | |
scheduler (advanced) | To use the custom configured Quartz scheduler, instead of creating a new Scheduler. | Scheduler | |
properties (consumer) | Properties to configure the Quartz scheduler. | Properties | |
propertiesFile (consumer) | File name of the properties to load from the classpath | String | |
startDelayedSeconds (scheduler) | Seconds to wait before starting the quartz scheduler. | int | |
autoStartScheduler (consumer) | Whether or not the scheduler should be auto started. This options is default true | true | boolean |
enableJmx (consumer) | Whether to enable Quartz JMX which allows to manage the Quartz scheduler from JMX. This options is default true | true | boolean |
resolveProperty Placeholders (advanced) | Whether the component should resolve property placeholders on itself when starting. Only properties which are of String type can use property placeholders. | true | boolean |
The Quartz endpoint is configured using URI syntax:
quartz:groupName/timerName
with the following path and query parameters:
269.2.1. Path Parameters (2 parameters):
Name | Description | Default | Type |
---|---|---|---|
groupName | The quartz group name to use. The combination of group name and timer name should be unique. | Camel | String |
timerName | Required The quartz timer name to use. The combination of group name and timer name should be unique. | String |
269.2.2. Query Parameters (13 parameters):
Name | Description | Default | Type |
---|---|---|---|
bridgeErrorHandler (consumer) | Allows for bridging the consumer to the Camel routing Error Handler, which mean any exceptions occurred while the consumer is trying to pickup incoming messages, or the likes, will now be processed as a message and handled by the routing Error Handler. By default the consumer will use the org.apache.camel.spi.ExceptionHandler to deal with exceptions, that will be logged at WARN or ERROR level and ignored. | false | boolean |
cron (consumer) | Specifies a cron expression to define when to trigger. | String | |
deleteJob (consumer) | If set to true, then the trigger automatically delete when route stop. Else if set to false, it will remain in scheduler. When set to false, it will also mean user may reuse pre-configured trigger with camel Uri. Just ensure the names match. Notice you cannot have both deleteJob and pauseJob set to true. | true | boolean |
fireNow (consumer) | Whether to fire the scheduler asap when its started using the simple trigger (this option does not support cron) | false | boolean |
pauseJob (consumer) | If set to true, then the trigger automatically pauses when route stop. Else if set to false, it will remain in scheduler. When set to false, it will also mean user may reuse pre-configured trigger with camel Uri. Just ensure the names match. Notice you cannot have both deleteJob and pauseJob set to true. | false | boolean |
startDelayedSeconds (consumer) | Seconds to wait before starting the quartz scheduler. | int | |
stateful (consumer) | Uses a Quartz StatefulJob instead of the default job. | false | boolean |
usingFixedCamelContextName (consumer) | If it is true, JobDataMap uses the CamelContext name directly to reference the CamelContext, if it is false, JobDataMap uses use the CamelContext management name which could be changed during the deploy time. | false | boolean |
exceptionHandler (consumer) | To let the consumer use a custom ExceptionHandler. Notice if the option bridgeErrorHandler is enabled then this option is not in use. By default the consumer will deal with exceptions, that will be logged at WARN or ERROR level and ignored. | ExceptionHandler | |
exchangePattern (consumer) | Sets the exchange pattern when the consumer creates an exchange. | ExchangePattern | |
jobParameters (advanced) | To configure additional options on the job. | Map | |
synchronous (advanced) | Sets whether synchronous processing should be strictly used, or Camel is allowed to use asynchronous processing (if supported). | false | boolean |
triggerParameters (advanced) | To configure additional options on the trigger. | Map |
When using a StatefulJob, the JobDataMap is re-persisted after every execution of the job, thus preserving state for the next execution.
INFO: Running in OSGi and having multiple bundles with quartz routes If you run in OSGi such as Apache ServiceMix, or Apache Karaf, and have multiple bundles with Camel routes that start from Quartz endpoints, then make sure if you assign
an id
to the <camelContext> that this id is unique, as this is required by the QuartzScheduler
in the OSGi container. If you do not set any id
on <camelContext> then
a unique id is auto assigned, and there is no problem.
269.3. 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 Quartz component also allows you to configure properties:
Parameter | Default | Type | Description |
---|---|---|---|
|
|
|
Camel 2.4: You can configure a |
|
|
| Camel 2.4: File name of the properties to load from the classpath |
To do this you can configure this in Spring XML as follows
<bean id="quartz" class="org.apache.camel.component.quartz.QuartzComponent"> <property name="propertiesFile" value="com/mycompany/myquartz.properties"/> </bean>
269.4. 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.
269.5. Starting the Quartz scheduler
This is an example:
<bean id="quartz" class="org.apache.camel.component.quartz.QuartzComponent"> <property name="startDelayedSeconds" value="5"/> </bean>
269.6. Clustering
Available as of Camel 2.4
If you use Quartz in clustered mode, e.g. the JobStore
is clustered. Then from Camel 2.4 onwards the Quartz 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.
269.7. 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.
269.8. 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. Quartz provides a little tutorial 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:
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 |
---|---|
| Space |
269.9. Specifying time zone
Available as of Camel 2.8.1
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:
quartz://groupName/timerName?cron=0+0/5+12-18+?+*+MON-FRI&trigger.timeZone=Europe/Stockholm
The timeZone value is the values accepted by java.util.TimeZone
.
In Camel 2.8.0 or older versions you would have to provide your custom String
to java.util.TimeZone
Type Converter to be able configure this from the endpoint uri.
From Camel 2.8.1 onwards we have included such a Type Converter in the camel-core.