Name

Quartz — provides a scheduled delivery of messages using the Quartz scheduler

Dependencies

Maven users will need to add the dependency shown in Example 15, “Quartz dependency” to their pom.xml to use this component.

Example 15. Quartz dependency

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

URI format

quartz://groupName/timerName?options
quartz://groupName/timerName/?cron=expression&options
quartz://timerName?options
quartz://timerName?cron=expression&options

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.

Options

Table 45, “Quartz options” lists the options for a Quartz endpoint.

Table 45. Quartz options

ParameterDefaultDescription
cron Specifies a cron expression. This option is not compatible with the trigger.\* or job.\* options.
trigger.repeatCount0Specifies how many times the timer repeats.
trigger.repeatInterval0Specifies the amount of time, in milliseconds, between repeated triggers.
job.name Specifies the job name.
job.XXX Specifies the job option with the XXX setter name.
trigger.XXX Specifies the trigger option with the XXX setter name.
statefulfalseSpecifies if the timer uses a Quartz StatefulJob instead of the default job.
fireNowfalseSpecifies if the endpoint will fire the trigger at route start-up when using SimpleTrigger.

Configuring quartz.properties file

By default Quartz will look for a quartz.properties file in the root of the classpath. If you deploy your route as a WAR, the default location for the quartz.properties file is WEB-INF/classes.

The Quartz endpoint allows you to configure properties using either a URI option or Spring XML configuration. Table 46, “Quartz properties options” lists the options for setting the Quartz properties.

Table 46. Quartz properties options

NameTypeDescription
propertiesPropertiesSpecifies a java.util.Propoperties instance containing the Quartz properties.
propertiesFileStringSpecifies the file name of the properties to load from the classpath.

Example 16, “Setting the Quartz properties” show how to set the file name in Spring XML.

Example 16. Setting the Quartz properties

<bean id="quartz" class="org.apache.camel.component.quartz.QuartzComponent">
    <property name="propertiesFile" value="com/mycompany/myquartz.properties"/>
</bean>

Starting the Quartz scheduler

The Quartz endpoint can configure the Quartz scheduler be started delayed, or not auto started at all. Table 47, “Quartz scheduler start up options” lists the options for configuring how the Quartz scheduler is started.

Table 47. Quartz scheduler start up options

NameDefaultDescription
startDelayedSeconds0Specifies the number of seconds to wait before starting the quartz scheduler.
autoStartSchedulertrueSpecifies if the scheduler should be auto started.

Example 17, “Setting the Quartz scheduler delay” show how to set the scheduler delay in Spring XML.

Example 17. Setting the Quartz scheduler delay

<bean id="quartz" class="org.apache.camel.component.quartz.QuartzComponent">
    <property name="startDelayedSeconds" value="5"/>
</bean>

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.

Related topics

Timer