Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Maven users will need to add the following dependency to their pom.xml for this component:

Code Block
xml
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>

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 Quartz component instead.

URI format

Code Block

quartz2://timerName?options
quartz2://groupName/timerName?options
quartz2://groupName/timerName?cron=expression
quartz2://timerName?cron=expression

...

Wiki Markup
{div:class=confluenceTableSmall}
|| 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}} | {{1000}} | SimpleTrigger: The amount of time in milliseconds between repeated triggers. Must enable {{trigger.repeatCount}} to use the simple trigger using this interval. |
| {{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 {{@PersistJobDataAfterExecution}} and {{@DisallowConcurrentExecution}} instead of the default job. |
| {{fireNow}} | {{false}} | If it is true will fire the trigger when the route is start when using SimpleTrigger.|
| {{deleteJob}} | {{true}} | 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. |
| {{pauseJob}} | {{false}} | 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. |
| {{durableJob}} | {{false}} | *Camel 2.12.4/2.13*: Whether or not the job should remain stored after it is orphaned (no triggers point to it). |
| {{recoverableJob}} | {{false}} | *Camel 2.12.4/2.13*: Instructs the scheduler whether or not the job should be re-executed if a 'recovery' or 'fail-over' situation is
 encountered. | 
{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");

...

To do this you can configure this in Spring XML as follows

Code Block
xml
xml

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

...

To do this you can configure this in Spring XML as follows

Code Block
xml
xml

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

...

For example, the following will fire a message every five minutes starting at 12pm (noon) to 6pm on weekdays:

Code Block

from("quartz2://myGroup/myTimerName?cron=0+0/5+12-18+?+*+MON-FRI").to("activemq:Totally.Rocks");

which is equivalent to using the cron expression

Code Block

0 0/5 12-18 ? * MON-FRI

The following table shows the URI character encodings we use to preserve valid URI syntax:

...

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

quartz2://groupName/timerName?cron=0+0/5+12-18+?+*+MON-FRI&trigger.timeZone=Europe/Stockholm

...

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");

...

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
Endpoint See Also
Endpoint See Also