From commits-return-16115-apmail-camel-commits-archive=camel.apache.org@camel.apache.org Tue Jul 12 20:08:31 2011 Return-Path: X-Original-To: apmail-camel-commits-archive@www.apache.org Delivered-To: apmail-camel-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 2588F65F6 for ; Tue, 12 Jul 2011 20:08:31 +0000 (UTC) Received: (qmail 20877 invoked by uid 500); 12 Jul 2011 20:08:30 -0000 Delivered-To: apmail-camel-commits-archive@camel.apache.org Received: (qmail 20817 invoked by uid 500); 12 Jul 2011 20:08:30 -0000 Mailing-List: contact commits-help@camel.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@camel.apache.org Delivered-To: mailing list commits@camel.apache.org Received: (qmail 20810 invoked by uid 99); 12 Jul 2011 20:08:30 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 12 Jul 2011 20:08:30 +0000 X-ASF-Spam-Status: No, hits=-1994.3 required=5.0 tests=ALL_TRUSTED,HTML_FONT_LOW_CONTRAST,HTML_MESSAGE,MIME_HTML_ONLY X-Spam-Check-By: apache.org Received: from [140.211.11.22] (HELO thor.apache.org) (140.211.11.22) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 12 Jul 2011 20:08:22 +0000 Received: from thor (localhost [127.0.0.1]) by thor.apache.org (8.13.8+Sun/8.13.8) with ESMTP id p6CK805V001203 for ; Tue, 12 Jul 2011 20:08:00 GMT Date: Tue, 12 Jul 2011 16:08:00 -0400 (EDT) From: confluence@apache.org To: commits@camel.apache.org Message-ID: <12515261.7607.1310501280063.JavaMail.confluence@thor> Subject: [CONF] Apache Camel > Quartz MIME-Version: 1.0 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Auto-Submitted: auto-generated X-Virus-Checked: Checked by ClamAV on apache.org

Quartz

Page edited by Richard Kettelerij

Comment: CAMEL-4216

Changes (4)

=20 =20
=20 =20
h2. Quartz Component
The *quartz:* component p= rovides a scheduled delivery of messages using the [Quartz scheduler|http://www.opensymphony.com/quartz/]. scheduler|htt= p://www.quartz-scheduler.org/].
Each endpoint represents a di= fferent timer (in Quartz terms, a Trigger and JobDetail).

...
{snippet:id=3Dexample|lang=3D= xml|url=3Dcamel/trunk/components/camel-quartz/src/test/java/org/apache/came= l/component/quartz/QuartzRouteTest.java}

When using a [StatefulJob|http://www.quartz-scheduler.org/docs/a= pi/2.0.0/= org/quartz/StatefulJob.html], the [JobDataMap|http://www.quartz-scheduler.org/docs/api/2.0.0/org/quartz= /JobDataMap.html] is re-persisted after every execution of the job, = thus preserving state for the next execution.


...
h3. Using Cron Triggers
*= Avaiable as of Camel 2.0*
Quartz supports [Cron-lik= e expressions|http://www.opensymphony.com/q= uartz/api/org/quartz/CronTrigger.html] expressions|http://www.quartz-schedule= r.org/docs/api/2.0.0/org/quartz/CronTrigger.html] for specifying tim= ers in a handy format. You can use these expressions in the {{cron}} URI pa= rameter; though to preserve valid URI encoding we allow + to be used instea= d of spaces. Quartz provides a [little tuto= rial|http://www.opensymphony.com/quartz/wikidocs/CronTriggers%20Tutorial.ht= ml]
For example, the followi= ng will fire a message every five minutes starting at 12pm (noon) to 6pm on= weekdays:
...
h3. Using Cron Triggers in Ca= mel 1.x
*@deprecated*
Quartz supports [Cron-lik= e expressions|http://www.opensymphony.com/q= uartz/api/org/quartz/CronTrigger.html] expressions|http://www.quartz-schedule= r.org/docs/api/2.0.0/org/quartz/CronTrigger.html] for specifying tim= ers in a handy format. You can use these expressions in the URI; though to = preserve valid URI encoding we allow {{/}} to be used instead of spaces and= {{$}} to be used instead of {{?}}.

For example, the followi= ng endpoint URI will fire a message at 12pm (noon) every day
...

Full Content

Quartz Component

The quartz: component provides a scheduled delivery of messages u= sing the Quartz scheduler.
Each endpoint represents a different timer (in Quartz terms, a Trigger and = JobDetail).

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

<dependency>
    <groupId>org.apache.camel</groupId>
    <artifactId>camel-quartz</artifactId>
    <version>x.x.x</version>
    <!-- use the s=
ame version as your Camel core version -->
</dependency>
3D""Using cron expressions
C= onfiguring the cron expression in Camel 1.x is based on path separators. We= changed this to an URI option in Camel 2.0, allowing a more elegant config= uration.
Also it is not possible to use the / cron special character= (for increments) in Camel 1.x, which Camel 2.0 also fixes.

You may need to escape certain URI charact= ers such as using ? in the quartz cron expression.

URI format

quartz://timerName?options
quartz://groupName/timerName?options
quartz://groupName/timerName/cronExpres=
sion       (@deprecated)
quartz://groupName/timerName/?cron=3Dex=
pression     (Camel 2.0)
quartz://timerName?cron=3Dexpression   =
             (Camel 2.0)

The component uses either a CronTrigger or a SimpleTrigger<= /tt>. If no cron expression is provided, the component uses a simple trigge= r. 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, ?op= tion=3Dvalue&option=3Dvalue&...

Options

Parameter Default Description
cron None Specifies a cron expression (not compa= tible 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 millisecon= ds 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 t= he default job.
fireNow false New to Camel 2.2.0, if it is true will fire the= trigger when the route is start when using SimpleTrigger.

For example, the following routing rule will fire two timer events to th= e mock:results endpoint:

from("quartz://myGroup/m=
yTimerName?trigger.repeatInterval=3D2&trigger.repeatCount=3D1").=
routeId("myRoute").to("mock:result");

When using a Statef= ulJob, the JobDataM= ap is re-persisted after every execution of the job, thus preserving st= ate for the next execution.

Configuring qua= rtz.properties file

By default Quartz will look for a quartz.properties file in the= root of the classpath. If you are using WAR deployments this means just dr= op the quartz.properties in WEB-INF/classes.

However the Camel Quartz component also allows you to configure properties:

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 t= o load from the classpath

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

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

Starting the Quartz s= cheduler

Available as of Camel 2.4

The Quartz= component offers an option to let the Quartz scheduler be started dela= yed, or not auto started at all.

Parameter Default Type Description
startDelayedSeconds 0 int Camel 2.4: Seconds to wait before starti= ng 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=3D"quartz"<=
/span> class=3D"org.apache.camel.component.quart=
z.QuartzComponent">
    <property name=3D"startDelayedSeconds" value=3D"5"=
/>
</bean>

Clustering

Available as of Camel 2.4

If you use Quartz in clustered mode, e.g. the JobStore is clust= ered. 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 ensur= e unique job name/group for endpoints.

Message Headers

Camel adds the getters from the Quartz Execution Context as header value= s. The following headers are added:
calendar, fireTime, jobDetail, jobInstance, jobRuntTime, mergedJobDataMap, nextFireTime= , previousFireTime, refireCount, result, sch= eduledFireTime, scheduler, trigger, triggerName<= /tt>, triggerGroup.

The fireTime header contains the java.util.Date of whe= n the exchange was fired.

Using Cron Triggers

Avaiable as of Camel 2.0
Quartz supports Cron-l= ike expressions for specifying timers in a handy format. You can use th= ese expressions in the cron URI parameter; though to preserve vali= d URI encoding we allow + to be used instead of spaces. Quartz provides a <= a href=3D"http://www.quartz-scheduler.org/docs/tutorials/crontrigger.html" = class=3D"external-link" rel=3D"nofollow">little tutorial on how to use = cron expressions.

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

from("quartz://myGr=
oup/myTimerName?cron=3D0+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

Using Cron Triggers = in Camel 1.x

@deprecated
Quartz supports Cron-l= ike expressions for specifying timers in a handy format. You can use th= ese expressions in the URI; though to preserve valid URI encoding we allow = / to be used instead of spaces and $ to be used instead o= f ?.

For example, the following endpoint URI will fire a message at 12pm (noo= n) every day

from("quartz://myGr=
oup/myTimerName/0/0/12/*/*/$").to("active=
mq:Totally.Rocks");

which is equivalent to using the cron expression

0 0 12 * * ?

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

URI Character Cron character
/ Space
$ ?

See Also