이 콘텐츠는 선택한 언어로 제공되지 않습니다.

Chapter 116. Quartz


Quartz Component

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).
Note
If you are using Quartz 2.x then from Camel 2.12 onwards there is a Quartz2 component you should use

URI format

quartz://timerName?options
quartz://groupName/timerName?options
quartz://groupName/timerName?cron=expression
quartz://timerName?cron=expression
Copy to Clipboard Toggle word wrap
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

Expand
Parameter Default Description
cron None Specifies a cron expression (not compatible with the trigger.\* or job.\* options).
trigger.repeatCount 0 SimpleTrigger: How many times should the timer repeat?
trigger.repeatInterval 0 SimpleTrigger: The amount of time in milliseconds between repeated triggers.
job.name null Sets the job name.
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.
fireNow false Camel 2.2.0: If true, fire the trigger when the route is started when using SimpleTrigger.
deleteJob true Camel 2.12: If true, the trigger automatically delete when route stops. If false, it remains in scheduler and the user may reuse pre-configured trigger with Camel URI. Just ensure the names match. Notice you cannot set both deleteJob and to true.
pauseJob false Camel 2.12: If true, the trigger automatically pauses when route stops. If false, it remains in scheduler and the user may reuse pre-configured trigger with Camel URI. Just ensure the names match. Note you cannot set both deleteJob and pauseJob to true.
usingFixedCamelContextName false Camel 2.15.0: If true, JobDataMap uses the CamelContext name directly to reference the camel context; if false, JobDataMap uses use the CamelContext management name which could be changed during the deploy time.
For example, the following routing rule will fire two timer events to the mock:results endpoint:
from("quartz://myGroup/myTimerName?trigger.repeatInterval=2&trigger.repeatCount=1").routeId("myRoute").to("mock:result");
Copy to Clipboard Toggle word wrap
When using a StatefulJob, the JobDataMap is re-persisted after every execution of the job, thus preserving state for the next execution.
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.

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:
Expand
Parameter Default Type Description
properties null Properties Camel 2.4: You can configure a java.util.Propoperties instance.
propertiesFile null String 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>
Copy to Clipboard Toggle word wrap

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

Available as of Camel 2.4
The Quartz component offers an option to let the Quartz scheduler be started delayed, or not auto started at all.
Expand
Parameter Default Type Description
startDelayedSeconds 0 int Camel 2.4: Seconds to wait before starting the quartz scheduler.
autoStartScheduler true boolean Camel 2.4: Whether or not the scheduler should be auto started.
To do this you can configure this in Spring XML as follows
<bean id="quartz" class="org.apache.camel.component.quartz.QuartzComponent">
    <property name="startDelayedSeconds" value="5"/>
</bean>
Copy to Clipboard Toggle word wrap

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.

Message Headers

Apache 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

Avaiable as of Apache 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 + 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");
Copy to Clipboard Toggle word wrap
which is equivalent to using the cron expression
0 0/5 12-18 ? * MON-FRI
Copy to Clipboard Toggle word wrap
The following table shows the URI character encodings we use to preserve valid URI syntax:
Expand
URI Character Cron character
\+ Space

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
Copy to Clipboard Toggle word wrap
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.
맨 위로 이동
Red Hat logoGithubredditYoutubeTwitter

자세한 정보

평가판, 구매 및 판매

커뮤니티

Red Hat 문서 정보

Red Hat을 사용하는 고객은 신뢰할 수 있는 콘텐츠가 포함된 제품과 서비스를 통해 혁신하고 목표를 달성할 수 있습니다. 최신 업데이트를 확인하세요.

보다 포괄적 수용을 위한 오픈 소스 용어 교체

Red Hat은 코드, 문서, 웹 속성에서 문제가 있는 언어를 교체하기 위해 최선을 다하고 있습니다. 자세한 내용은 다음을 참조하세요.Red Hat 블로그.

Red Hat 소개

Red Hat은 기업이 핵심 데이터 센터에서 네트워크 에지에 이르기까지 플랫폼과 환경 전반에서 더 쉽게 작업할 수 있도록 강화된 솔루션을 제공합니다.

Theme

© 2025 Red Hat