camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From conflue...@apache.org
Subject [CONF] Apache Camel > Quartz
Date Fri, 10 May 2013 12:02:00 GMT
<html>
<head>
    <base href="https://cwiki.apache.org/confluence">
            <link rel="stylesheet" href="/confluence/s/2042/9/1/_/styles/combined.css?spaceKey=CAMEL&amp;forWysiwyg=true"
type="text/css">
    </head>
<body style="background: white;" bgcolor="white" class="email-body">
<div id="pageContent">
<div id="notificationFormat">
<div class="wiki-content">
<div class="email">
    <h2><a href="https://cwiki.apache.org/confluence/display/CAMEL/Quartz">Quartz</a></h2>
    <h4>Page <b>edited</b> by             <a href="https://cwiki.apache.org/confluence/display/~davsclaus">Claus
Ibsen</a>
    </h4>
        <br/>
                         <h4>Changes (1)</h4>
                                 
    
<div id="page-diffs">
                    <table class="diff" cellpadding="0" cellspacing="0">
    
            <tr><td class="diff-snipped" >...<br></td></tr>
            <tr><td class="diff-unchanged" >h3. Configuring quartz.properties
file <br> <br></td></tr>
            <tr><td class="diff-changed-lines" >By default Quartz will look for
a {{quartz.properties}} file in the <span class="diff-deleted-words"style="color:#999;background-color:#fdd;text-decoration:line-through;">root</span>
<span class="diff-added-words"style="background-color: #dfd;">{{org/quartz}} directory</span>
of the classpath. If you are using WAR deployments this means just drop the quartz.properties
in <span class="diff-changed-words">{{WEB-INF/classes<span class="diff-added-chars"style="background-color:
#dfd;">/org/quartz</span>}}.</span> <br></td></tr>
            <tr><td class="diff-unchanged" > <br>However the Camel [Quartz]
component also allows you to configure properties: <br></td></tr>
            <tr><td class="diff-snipped" >...<br></td></tr>
    
            </table>
    </div>                            <h4>Full Content</h4>
                    <div class="notificationGreySide">
        <h2><a name="Quartz-QuartzComponent"></a>Quartz Component</h2>

<p>The <b>quartz:</b> component provides a scheduled delivery of messages
using the <a href="http://www.quartz-scheduler.org/" class="external-link" rel="nofollow">Quartz
scheduler</a>. <br/>
Each endpoint represents a different timer (in Quartz terms, a Trigger and JobDetail).</p>

<p>Maven users will need to add the following dependency to their <tt>pom.xml</tt>
for this component:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-xml">
<span class="code-tag">&lt;dependency&gt;</span>
    <span class="code-tag">&lt;groupId&gt;</span>org.apache.camel<span
class="code-tag">&lt;/groupId&gt;</span>
    <span class="code-tag">&lt;artifactId&gt;</span>camel-quartz<span
class="code-tag">&lt;/artifactId&gt;</span>
    <span class="code-tag">&lt;version&gt;</span>x.x.x<span class="code-tag">&lt;/version&gt;</span>
    <span class="code-tag"><span class="code-comment">&lt;!-- use the same
version as your Camel core version --&gt;</span></span>
<span class="code-tag">&lt;/dependency&gt;</span>
</pre>
</div></div>

<h3><a name="Quartz-URIformat"></a>URI format</h3>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
quartz:<span class="code-comment">//timerName?options
</span>quartz:<span class="code-comment">//groupName/timerName?options
</span>quartz:<span class="code-comment">//groupName/timerName?cron=expression
</span>quartz:<span class="code-comment">//timerName?cron=expression</span>
</pre>
</div></div>

<p>The component uses either a <tt>CronTrigger</tt> or a <tt>SimpleTrigger</tt>.
If no cron expression is provided, the component uses a simple trigger. If no <tt>groupName</tt>
is provided, the quartz component uses the <tt>Camel</tt> group name.</p>

<p>You can append query options to the URI in the following format, <tt>?option=value&amp;option=value&amp;...</tt></p>

<h3><a name="Quartz-Options"></a>Options</h3>
<div class="confluenceTableSmall"><div class='table-wrap'>
<table class='confluenceTable'><tbody>
<tr>
<th class='confluenceTh'> Parameter </th>
<th class='confluenceTh'> Default </th>
<th class='confluenceTh'> Description </th>
</tr>
<tr>
<td class='confluenceTd'> <tt>cron</tt> </td>
<td class='confluenceTd'> <em>None</em> </td>
<td class='confluenceTd'> Specifies a <tt>cron</tt> expression (not compatible
with the <tt>trigger.&#42;</tt> or <tt>job.&#42;</tt> options).
</td>
</tr>
<tr>
<td class='confluenceTd'> <tt>trigger.repeatCount</tt> </td>
<td class='confluenceTd'> <tt>0</tt> </td>
<td class='confluenceTd'> SimpleTrigger: How many times should the timer repeat? </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>trigger.repeatInterval</tt> </td>
<td class='confluenceTd'> <tt>0</tt> </td>
<td class='confluenceTd'> SimpleTrigger: The amount of time in milliseconds between
repeated triggers. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>job.name</tt> </td>
<td class='confluenceTd'> <tt>null</tt> </td>
<td class='confluenceTd'> Sets the job name. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>job.<em>XXX</em></tt> </td>
<td class='confluenceTd'> <tt>null</tt> </td>
<td class='confluenceTd'> Sets the job option with the <tt><em>XXX</em></tt>
setter name. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>trigger.<em>XXX</em></tt> </td>
<td class='confluenceTd'> <tt>null</tt> </td>
<td class='confluenceTd'> Sets the trigger option with the <tt><em>XXX</em></tt>
setter name. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>stateful</tt> </td>
<td class='confluenceTd'> <tt>false</tt> </td>
<td class='confluenceTd'> Uses a Quartz <tt>StatefulJob</tt> instead of
the default job. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>fireNow</tt> </td>
<td class='confluenceTd'> <tt>false</tt> </td>
<td class='confluenceTd'> New to Camel 2.2.0, if it is true will fire the trigger when
the route is start when using SimpleTrigger.</td>
</tr>
</tbody></table>
</div>
</div>

<p>For example, the following routing rule will fire two timer events to the <tt>mock:results</tt>
endpoint:</p>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-xml">from(<span class="code-quote">"quartz://myGroup/myTimerName?trigger.repeatInterval=2&amp;trigger.repeatCount=1"</span>).routeId(<span
class="code-quote">"myRoute"</span>).to(<span class="code-quote">"mock:result"</span>);
</pre>
</div></div>

<p>When using a <a href="http://quartz-scheduler.org/api/2.0.0/org/quartz/StatefulJob.html"
class="external-link" rel="nofollow">StatefulJob</a>, the <a href="http://quartz-scheduler.org/api/2.0.0/org/quartz/JobDataMap.html"
class="external-link" rel="nofollow">JobDataMap</a> is re-persisted after every execution
of the job, thus preserving state for the next execution.</p>

<div class='panelMacro'><table class='infoMacro'><colgroup><col width='24'><col></colgroup><tr><td
valign='top'><img src="/confluence/images/icons/emoticons/information.gif" width="16"
height="16" align="absmiddle" alt="" border="0"></td><td><b>Running in
OSGi and having multiple bundles with quartz routes</b><br />If you run in OSGi
such as Apache ServiceMix, or Apache Karaf, and have multiple bundles with Camel routes that
start from <a href="/confluence/display/CAMEL/Quartz" title="Quartz">Quartz</a>
endpoints, then make sure if you assign<br/>
an <tt>id</tt> to the &lt;camelContext&gt; that this id is unique, as
this is required by the <tt>QuartzScheduler</tt> in the OSGi container. If you
do not set any <tt>id</tt> on &lt;camelContext&gt; then<br/>
a unique id is auto assigned, and there is no problem.</td></tr></table></div>

<h3><a name="Quartz-Configuringquartz.propertiesfile"></a>Configuring quartz.properties
file</h3>

<p>By default Quartz will look for a <tt>quartz.properties</tt> file in
the <tt>org/quartz</tt> directory of the classpath. If you are using WAR deployments
this means just drop the quartz.properties in <tt>WEB-INF/classes/org/quartz</tt>.</p>

<p>However the Camel <a href="/confluence/display/CAMEL/Quartz" title="Quartz">Quartz</a>
component also allows you to configure properties:</p>
<div class="confluenceTableSmall"><div class='table-wrap'>
<table class='confluenceTable'><tbody>
<tr>
<th class='confluenceTh'> Parameter </th>
<th class='confluenceTh'> Default </th>
<th class='confluenceTh'> Type </th>
<th class='confluenceTh'> Description </th>
</tr>
<tr>
<td class='confluenceTd'> <tt>properties</tt> </td>
<td class='confluenceTd'> <tt>null</tt> </td>
<td class='confluenceTd'> <tt>Properties</tt> </td>
<td class='confluenceTd'> <b>Camel 2.4</b>: You can configure a <tt>java.util.Properties</tt>
instance. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>propertiesFile</tt> </td>
<td class='confluenceTd'> <tt>null</tt> </td>
<td class='confluenceTd'> <tt>String</tt> </td>
<td class='confluenceTd'> <b>Camel 2.4</b>: File name of the properties
to load from the classpath </td>
</tr>
</tbody></table>
</div>
</div>

<p>To do this you can configure this in Spring XML as follows</p>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-xml">
<span class="code-tag">&lt;bean id=<span class="code-quote">"quartz"</span>
class=<span class="code-quote">"org.apache.camel.component.quartz.QuartzComponent"</span>&gt;</span>
    <span class="code-tag">&lt;property name=<span class="code-quote">"propertiesFile"</span>
value=<span class="code-quote">"com/mycompany/myquartz.properties"</span>/&gt;</span>
<span class="code-tag">&lt;/bean&gt;</span>
</pre>
</div></div>


<h3><a name="Quartz-StartingtheQuartzscheduler"></a>Starting the Quartz
scheduler</h3>
<p><b>Available as of Camel 2.4</b></p>

<p>The <a href="/confluence/display/CAMEL/Quartz" title="Quartz">Quartz</a>
component offers an option to let the Quartz scheduler be started delayed, or not auto started
at all.</p>
<div class="confluenceTableSmall"><div class='table-wrap'>
<table class='confluenceTable'><tbody>
<tr>
<th class='confluenceTh'> Parameter </th>
<th class='confluenceTh'> Default </th>
<th class='confluenceTh'> Type </th>
<th class='confluenceTh'> Description </th>
</tr>
<tr>
<td class='confluenceTd'> <tt>startDelayedSeconds</tt> </td>
<td class='confluenceTd'> <tt>0</tt> </td>
<td class='confluenceTd'> <tt>int</tt> </td>
<td class='confluenceTd'> <b>Camel 2.4</b>: Seconds to wait before starting
the quartz scheduler. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>autoStartScheduler</tt> </td>
<td class='confluenceTd'> <tt>true</tt> </td>
<td class='confluenceTd'> <tt>boolean</tt> </td>
<td class='confluenceTd'> <b>Camel 2.4:</b> Whether or not the scheduler
should be auto started. </td>
</tr>
</tbody></table>
</div>
</div>

<p>To do this you can configure this in Spring XML as follows</p>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-xml">
<span class="code-tag">&lt;bean id=<span class="code-quote">"quartz"</span>
class=<span class="code-quote">"org.apache.camel.component.quartz.QuartzComponent"</span>&gt;</span>
    <span class="code-tag">&lt;property name=<span class="code-quote">"startDelayedSeconds"</span>
value=<span class="code-quote">"5"</span>/&gt;</span>
<span class="code-tag">&lt;/bean&gt;</span>
</pre>
</div></div>


<h3><a name="Quartz-Clustering"></a>Clustering</h3>
<p><b>Available as of Camel 2.4</b></p>

<p>If you use Quartz in clustered mode, e.g. the <tt>JobStore</tt> is clustered.
Then from Camel 2.4 onwards the <a href="/confluence/display/CAMEL/Quartz" title="Quartz">Quartz</a>
component will <b>not</b> pause/remove triggers when a node is being stopped/shutdown.
This allows the trigger to keep running on the other nodes in the cluster.</p>

<p><b>Note</b>: When running in clustered node no checking is done to ensure
unique job name/group for endpoints. </p>


<h3><a name="Quartz-MessageHeaders"></a>Message Headers</h3>
<p>Camel adds the getters from the Quartz Execution Context as header values. The following
headers are added:<br/>
<tt>calendar</tt>, <tt>fireTime</tt>, <tt>jobDetail</tt>,
<tt>jobInstance</tt>, <tt>jobRuntTime</tt>, <tt>mergedJobDataMap</tt>,
<tt>nextFireTime</tt>, <tt>previousFireTime</tt>, <tt>refireCount</tt>,
<tt>result</tt>, <tt>scheduledFireTime</tt>, <tt>scheduler</tt>,
<tt>trigger</tt>, <tt>triggerName</tt>, <tt>triggerGroup</tt>.</p>

<p>The <tt>fireTime</tt> header contains the <tt>java.util.Date</tt>
of when the exchange was fired.</p>

<h3><a name="Quartz-UsingCronTriggers"></a>Using Cron Triggers</h3>
<p>Quartz supports <a href="http://www.quartz-scheduler.org/documentation/quartz-2.1.x/tutorials/crontrigger"
class="external-link" rel="nofollow">Cron-like expressions</a> for specifying timers
in a handy format. You can use these expressions in the <tt>cron</tt> URI parameter;
though to preserve valid URI encoding we allow + to be used instead of spaces. Quartz provides
a <a href="http://www.quartz-scheduler.org/docs/tutorials/crontrigger.html" class="external-link"
rel="nofollow">little tutorial</a> on how to use cron expressions.</p>

<p>For example, the following will fire a message every five minutes starting at 12pm
(noon) to 6pm on weekdays:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
from(<span class="code-quote">"quartz:<span class="code-comment">//myGroup/myTimerName?cron=0+0/5+12-18+?+*+MON-FRI"</span>).to(<span
class="code-quote">"activemq:Totally.Rocks"</span>);</span>
</pre>
</div></div>

<p>which is equivalent to using the cron expression</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
0 0/5 12-18 ? * MON-FRI
</pre>
</div></div>

<p>The following table shows the URI character encodings we use to preserve valid URI
syntax:</p>
<div class="confluenceTableSmall"><div class='table-wrap'>
<table class='confluenceTable'><tbody>
<tr>
<th class='confluenceTh'>URI Character</th>
<th class='confluenceTh'>Cron character</th>
</tr>
<tr>
<td class='confluenceTd'> <tt>&#43;</tt> </td>
<td class='confluenceTd'> <em>Space</em> </td>
</tr>
</tbody></table>
</div>
</div>

<h3><a name="Quartz-Specifyingtimezone"></a>Specifying time zone</h3>
<p><b>Available as of Camel 2.8.1</b><br/>
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:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
quartz:<span class="code-comment">//groupName/timerName?cron=0+0/5+12-18+?+*+MON-FRI&amp;trigger.timeZone=Europe/Stockholm</span>
</pre>
</div></div>

<p>The timeZone value is the values accepted by <tt>java.util.TimeZone</tt>.</p>

<p>In Camel 2.8.0 or older versions you would have to provide your custom <tt>String</tt>
to <tt>java.util.TimeZone</tt> <a href="/confluence/display/CAMEL/Type+Converter"
title="Type Converter">Type Converter</a> to be able configure this from the endpoint
uri.<br/>
>From Camel 2.8.1 onwards we have included such a <a href="/confluence/display/CAMEL/Type+Converter"
title="Type Converter">Type Converter</a> in the camel-core.</p>

<h3><a name="Quartz-SeeAlso"></a>See Also</h3>
<ul>
	<li><a href="/confluence/display/CAMEL/Configuring+Camel" title="Configuring Camel">Configuring
Camel</a></li>
	<li><a href="/confluence/display/CAMEL/Component" title="Component">Component</a></li>
	<li><a href="/confluence/display/CAMEL/Endpoint" title="Endpoint">Endpoint</a></li>
	<li><a href="/confluence/display/CAMEL/Getting+Started" title="Getting Started">Getting
Started</a></li>
</ul>

<ul>
	<li><a href="/confluence/display/CAMEL/Timer" title="Timer">Timer</a></li>
</ul>


    </div>
        <div id="commentsSection" class="wiki-content pageSection">
        <div style="float: right;">
            <a href="https://cwiki.apache.org/confluence/users/viewnotifications.action"
class="grey">Change Notification Preferences</a>
        </div>
        <a href="https://cwiki.apache.org/confluence/display/CAMEL/Quartz">View Online</a>
        |
        <a href="https://cwiki.apache.org/confluence/pages/diffpagesbyversion.action?pageId=54900&revisedVersion=46&originalVersion=45">View
Changes</a>
                |
        <a href="https://cwiki.apache.org/confluence/display/CAMEL/Quartz?showComments=true&amp;showCommentArea=true#addcomment">Add
Comment</a>
            </div>
</div>
</div>
</div>
</div>
</body>
</html>

Mime
View raw message