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

Parameter | Default | Description
--- | --- | ---
`cron` |  | Specifies a cron expression. This option is not compatible with the `trigger.\*` or `job.\*` options.
`trigger.repeatCount` | `0` | Specifies how many times the timer repeats.
`trigger.repeatInterval` | `0` | Specifies 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.
`stateful` | `false` | Specifies if the timer uses a Quartz `StatefulJob` instead of the default job.
`fireNow` | `false` | Specifies 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

Name | Type | Description
--- | --- | ---
`properties` | `Properties` | Specifies a `java.util.Propoperties` instance containing the Quartz properties.
`propertiesFile` | `String` | Specifies 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

Name | Default | Description
--- | --- | ---
`startDelayedSeconds` | `0` | Specifies the number of seconds to wait before starting the quartz scheduler.
`autoStartScheduler` | `true` | Specifies 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