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, 09 Apr 2010 17:49:00 GMT
<html>
<head>
    <base href="http://cwiki.apache.org/confluence">
            <link rel="stylesheet" href="/confluence/s/1519/1/1/_/styles/combined.css?spaceKey=CAMEL&amp;forWysiwyg=true"
type="text/css">
    </head>
<body style="background-color: white" bgcolor="white">
<div id="pageContent">
<div id="notificationFormat">
<div class="wiki-content">
<div class="email">
     <h2><a href="http://cwiki.apache.org/confluence/display/CAMEL/Quartz">Quartz</a></h2>
     <h4>Page <b>edited</b> by             <a href="http://cwiki.apache.org/confluence/display/~smerp">Scott
Parkerson</a>
    </h4>
     fix example description for camel-quartz 2.x
          <div id="versionComment" class="noteMacro" style="display:none; padding: 5px;">
     fix example description for camel-quartz 2.x<br />
     </div>
          <br/>
     <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.opensymphony.com/quartz/" 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-java">
&lt;dependency&gt;
    &lt;groupId&gt;org.apache.camel&lt;/groupId&gt;
    &lt;artifactId&gt;camel-quartz&lt;/artifactId&gt;
    &lt;version&gt;x.x.x&lt;/version&gt;
    &lt;!-- use the same version as your Camel core version --&gt;
&lt;/dependency&gt;
</pre>
</div></div>


<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>Using cron
expressions</b><br /><p>Configuring 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
configuration.<br/>
Also it is <b>not</b> possible to use the <tt>/</tt> cron special
character (for increments) in Camel 1.x, which Camel 2.0 also fixes.</p></td></tr></table></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/cronExpression
      (@deprecated)
</span>quartz:<span class="code-comment">//groupName/timerName/?cron=expression
    (Camel 2.0)
</span>quartz:<span class="code-comment">//timerName?cron=expression         
      (Camel 2.0)</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>

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

<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>).to(<span
class="code-quote">"mock:result"</span>);
</pre>
</div></div>

<p>When using a <a href="http://www.quartz-scheduler.org/docs/api/org/quartz/StatefulJob.html"
rel="nofollow">StatefulJob</a>, the <a href="http://www.quartz-scheduler.org/docs/api/org/quartz/JobDataMap.html"
rel="nofollow">JobDataMap</a> is re-persisted after every execution of the job, thus
preserving state for the next execution.</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><b>Avaiable as of Camel 2.0</b><br/>
Quartz supports <a href="http://www.opensymphony.com/quartz/api/org/quartz/CronTrigger.html"
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.opensymphony.com/quartz/wikidocs/CronTriggers%20Tutorial.html"
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>
<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>

<h3><a name="Quartz-UsingCronTriggersinCamel1.x"></a>Using Cron Triggers
in Camel 1.x</h3>
<p><b>@deprecated</b><br/>
Quartz supports <a href="http://www.opensymphony.com/quartz/api/org/quartz/CronTrigger.html"
rel="nofollow">Cron-like expressions</a> for specifying timers in a handy format.
You can use these expressions in the URI; though to preserve valid URI encoding we allow <tt>/</tt>
to be used instead of spaces and <tt>$</tt> to be used instead of <tt>?</tt>.</p>

<p>For example, the following endpoint URI will fire a message at 12pm (noon) every
day</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/0/0/12/*/*/$"</span>).to(<span
class="code-quote">"activemq:Totally.Rocks"</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 12 * * ?
</pre>
</div></div>

<p>The following table shows the URI character encodings we use to preserve valid URI
syntax:</p>

<table class='confluenceTable'><tbody>
<tr>
<th class='confluenceTh'>URI Character</th>
<th class='confluenceTh'>Cron character</th>
</tr>
<tr>
<td class='confluenceTd'> <tt>/</tt> </td>
<td class='confluenceTd'> <em>Space</em> </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>$</tt> </td>
<td class='confluenceTd'> <tt>?</tt> </td>
</tr>
</tbody></table>

<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="http://cwiki.apache.org/confluence/users/viewnotifications.action"
class="grey">Change Notification Preferences</a>
       </div>

       <a href="http://cwiki.apache.org/confluence/display/CAMEL/Quartz">View Online</a>
       |
       <a href="http://cwiki.apache.org/confluence/pages/diffpagesbyversion.action?pageId=54900&revisedVersion=26&originalVersion=25">View
Change</a>
              |
       <a href="http://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