camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Claus Ibsen (Confluence)" <conflue...@apache.org>
Subject [CONF] Apache Camel > Quartz2
Date Tue, 13 Aug 2013 12:15:00 GMT
<html>
<head>
    <base href="https://cwiki.apache.org/confluence">
            <link rel="stylesheet" href="/confluence/s/en/2176/1/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/Quartz2">Quartz2</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" >The timeZone value is the values accepted
by {{java.util.TimeZone}}. <br> <br></td></tr>
            <tr><td class="diff-added-lines" style="background-color: #dfd;">
<br>h2. Using QuartzScheduledPollConsumerScheduler <br> <br>The [Quartz2]
component provides a [Polling Consumer] scheduler which allows to use cron based scheduling
for [Polling Consumers] such as the [File|File2] and [FTP|FTP2] consumers. <br> <br>For
example to use a cron based expression to poll for files every 2nd second, then a Camel route
can be define simply as: <br>{code} <br>    from(&quot;file:inbox?scheduler=quartz2&amp;scheduler.cron=0/2+*+*+*+*+?&quot;)
<br>       .to(&quot;bean:process&quot;); <br>{code} <br> <br>Notice
we define the {{scheduler=quartz2}} to instruct Camel to use the [Quartz2] based scheduler.
Then we use {{scheduler.xxx}} options to configure the scheduler. The [Quart2] scheduler requires
the cron option to be set.  <br> <br>The following options is supported: <br>
<br>{div:class=confluenceTableSmall} <br>|| Parameter || Default || Type || Description
|| <br>| {{quartzScheduler}} | {{null}} | {{org.quartz.Scheduler}} | To use a custom
Quartz scheduler. If none configure then the shared scheduler from the [Quartz2] component
is used. | <br>| {{cron}} | {{null}} | {{String}} | *Mandatory*: To define the cron
expression for triggering the polls. | <br>| {{triggerId}} | {{null}} | {{String}} |
To specify the trigger id. If none provided then an UUID is generated and used. | <br>|
{{triggerGroup}} | {{QuartzScheduledPollConsumerScheduler}} | {{String}} | To specify the
trigger group. | <br>{div} <br> <br> <br></td></tr>
            <tr><td class="diff-unchanged" >{include:Endpoint See Also} <br>*
[Quartz] <br></td></tr>
            <tr><td class="diff-snipped" >...<br></td></tr>
    
            </table>
    </div>                            <h4>Full Content</h4>
                    <div class="notificationGreySide">
        <h2><a name="Quartz2-Quartz2Component"></a>Quartz2 Component</h2>

<p><b>Available as of Camel 2.12.0</b></p>

<p>The <b>quartz2:</b> component provides a scheduled delivery of messages
using the <a href="http://www.quartz-scheduler.org/" class="external-link" rel="nofollow">Quartz
Scheduler 2.x </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="theme: Default; brush: xml; gutter: false" style="font-size:12px; font-family:
ConfluenceInstalledFont,monospace;">
&lt;dependency&gt;
    &lt;groupId&gt;org.apache.camel&lt;/groupId&gt;
    &lt;artifactId&gt;camel-quartz2&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>

<p><b>NOTE:</b> Quartz 2.x API is not compatible with Quartz 1.x. If you
need to remain on old Quartz 1.x, please<br/>
use the old <a href="/confluence/display/CAMEL/Quartz" title="Quartz">Quartz</a>
component instead.</p>

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

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="theme: Default; brush: java; gutter: false" style="font-size:12px; font-family:
ConfluenceInstalledFont,monospace;">
quartz2://timerName?options
quartz2://groupName/timerName?options
quartz2://groupName/timerName?cron=expression
quartz2://timerName?cron=expression
</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="Quartz2-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>@PersistJobDataAfterExecution</tt>
and <tt>@DisallowConcurrentExecution</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'> If it is true will fire the trigger when the route is start
when using SimpleTrigger.</td>
</tr>
<tr>
<td class='confluenceTd'> <tt>deleteJob</tt> </td>
<td class='confluenceTd'> <tt>true</tt> </td>
<td class='confluenceTd'> 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.
</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="theme: Default; brush: java; gutter: false" style="font-size:12px; font-family:
ConfluenceInstalledFont,monospace;">
from("quartz2://myGroup/myTimerName?trigger.repeatInterval=2&amp;trigger.repeatCount=1").routeId("myRoute").to("mock:result");
</pre>
</div></div>

<p>When using <tt>stateful=true</tt>, 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/Quartz2" title="Quartz2">Quartz2</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="Quartz2-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/Quartz2" title="Quartz2">Quartz2</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'> 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'> 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="theme: Default; brush: xml; gutter: false" style="font-size:12px; font-family:
ConfluenceInstalledFont,monospace;">
&lt;bean id="quartz" class="org.apache.camel.component.quartz2.QuartzComponent"&gt;
    &lt;property name="propertiesFile" value="com/mycompany/myquartz.properties"/&gt;
&lt;/bean&gt;
</pre>
</div></div>


<h3><a name="Quartz2-StartingtheQuartzscheduler"></a>Starting the Quartz
scheduler</h3>

<p>The <a href="/confluence/display/CAMEL/Quartz2" title="Quartz2">Quartz2</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'> 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'> 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="theme: Default; brush: xml; gutter: false" style="font-size:12px; font-family:
ConfluenceInstalledFont,monospace;">
&lt;bean id="quartz" class="org.apache.camel.component.quartz2.QuartzComponent"&gt;
    &lt;property name="startDelayedSeconds" value="5"/&gt;
&lt;/bean&gt;
</pre>
</div></div>


<h3><a name="Quartz2-Clustering"></a>Clustering</h3>

<p>If you use Quartz in clustered mode, e.g. the <tt>JobStore</tt> is clustered.
Then the <a href="/confluence/display/CAMEL/Quartz2" title="Quartz2">Quartz2</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="Quartz2-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="Quartz2-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="theme: Default; brush: java; gutter: false" style="font-size:12px; font-family:
ConfluenceInstalledFont,monospace;">
from("quartz2://myGroup/myTimerName?cron=0+0/5+12-18+?+*+MON-FRI").to("activemq:Totally.Rocks");
</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="theme: Default; brush: java; gutter: false" style="font-size:12px; font-family:
ConfluenceInstalledFont,monospace;">
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="Quartz2-Specifyingtimezone"></a>Specifying time zone</h3>

<p>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="theme: Default; brush: java; gutter: false" style="font-size:12px; font-family:
ConfluenceInstalledFont,monospace;">
quartz2://groupName/timerName?cron=0+0/5+12-18+?+*+MON-FRI&amp;trigger.timeZone=Europe/Stockholm
</pre>
</div></div>

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


<h2><a name="Quartz2-UsingQuartzScheduledPollConsumerScheduler"></a>Using
QuartzScheduledPollConsumerScheduler</h2>

<p>The <a href="/confluence/display/CAMEL/Quartz2" title="Quartz2">Quartz2</a>
component provides a <a href="/confluence/display/CAMEL/Polling+Consumer" title="Polling
Consumer">Polling Consumer</a> scheduler which allows to use cron based scheduling
for <a href="/confluence/pages/createpage.action?spaceKey=CAMEL&amp;title=Polling+Consumers&amp;linkCreation=true&amp;fromPageId=34014213"
class="createlink">Polling Consumers</a> such as the <a href="/confluence/display/CAMEL/File2"
title="File2">File</a> and <a href="/confluence/display/CAMEL/FTP2" title="FTP2">FTP</a>
consumers.</p>

<p>For example to use a cron based expression to poll for files every 2nd second, then
a Camel route can be define simply as:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="theme: Default; brush: java; gutter: false" style="font-size:12px; font-family:
ConfluenceInstalledFont,monospace;">
    from("file:inbox?scheduler=quartz2&amp;scheduler.cron=0/2+*+*+*+*+?")
       .to("bean:process");
</pre>
</div></div>

<p>Notice we define the <tt>scheduler=quartz2</tt> to instruct Camel to
use the <a href="/confluence/display/CAMEL/Quartz2" title="Quartz2">Quartz2</a>
based scheduler. Then we use <tt>scheduler.xxx</tt> options to configure the scheduler.
The <a href="/confluence/pages/createpage.action?spaceKey=CAMEL&amp;title=Quart2&amp;linkCreation=true&amp;fromPageId=34014213"
class="createlink">Quart2</a> scheduler requires the cron option to be set. </p>

<p>The following options is supported:</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>quartzScheduler</tt> </td>
<td class='confluenceTd'> <tt>null</tt> </td>
<td class='confluenceTd'> <tt>org.quartz.Scheduler</tt> </td>
<td class='confluenceTd'> To use a custom Quartz scheduler. If none configure then the
shared scheduler from the <a href="/confluence/display/CAMEL/Quartz2" title="Quartz2">Quartz2</a>
component is used. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>cron</tt> </td>
<td class='confluenceTd'> <tt>null</tt> </td>
<td class='confluenceTd'> <tt>String</tt> </td>
<td class='confluenceTd'> <b>Mandatory</b>: To define the cron expression
for triggering the polls. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>triggerId</tt> </td>
<td class='confluenceTd'> <tt>null</tt> </td>
<td class='confluenceTd'> <tt>String</tt> </td>
<td class='confluenceTd'> To specify the trigger id. If none provided then an UUID is
generated and used. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>triggerGroup</tt> </td>
<td class='confluenceTd'> <tt>QuartzScheduledPollConsumerScheduler</tt>
</td>
<td class='confluenceTd'> <tt>String</tt> </td>
<td class='confluenceTd'> To specify the trigger group. </td>
</tr>
</tbody></table>
</div>
</div>


<h3><a name="Quartz2-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/Quartz" title="Quartz">Quartz</a></li>
	<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;" class="grey">
                        <a href="https://cwiki.apache.org/confluence/users/removespacenotification.action?spaceKey=CAMEL">Stop
watching space</a>
            <span style="padding: 0px 5px;">|</span>
                <a href="https://cwiki.apache.org/confluence/users/editmyemailsettings.action">Change
email notification preferences</a>
</div>
        <a href="https://cwiki.apache.org/confluence/display/CAMEL/Quartz2">View Online</a>
        |
        <a href="https://cwiki.apache.org/confluence/pages/diffpagesbyversion.action?pageId=34014213&revisedVersion=4&originalVersion=3">View
Changes</a>
                |
        <a href="https://cwiki.apache.org/confluence/display/CAMEL/Quartz2?showComments=true&amp;showCommentArea=true#addcomment">Add
Comment</a>
            </div>
</div>
</div>
</div>
</div>
</body>
</html>

Mime
View raw message