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 > Quartz
Date Mon, 02 Dec 2013 21:27:01 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/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 (2)</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" >{code} <br> <br></td></tr>
            <tr><td class="diff-added-lines" style="background-color: #dfd;">h3.
Enabling Quartz scheduler in JMX <br></td></tr>
            <tr><td class="diff-unchanged" > <br></td></tr>
            <tr><td class="diff-added-lines" style="background-color: #dfd;">You
need to configure the quartz scheduler properties to enable JMX. <br>That is typically
setting the option {{&quot;org.quartz.scheduler.jmx.export&quot;}} to a {{true}} value
in the configuration file. <br> <br>From Camel 2.13 onwards Camel will automatic
set this option to true, unless explicit disabled. <br> <br></td></tr>
            <tr><td class="diff-unchanged" >h3. Starting the Quartz scheduler
<br>*Available as of Camel 2.4* <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 1.x </a>. <br/>
Each endpoint represents a different timer (in Quartz terms, a Trigger and JobDetail).</p>

<div class='panelMacro'><table class='tipMacro'><colgroup><col width='24'><col></colgroup><tr><td
valign='top'><img src="/confluence/images/icons/emoticons/check.gif" width="16" height="16"
align="absmiddle" alt="" border="0"></td><td>If you are using Quartz 2.x then
from Camel 2.12 onwards there is a <a href="/confluence/display/CAMEL/Quartz2" title="Quartz2">Quartz2</a>
component you should use</td></tr></table></div>

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

<h3><a name="Quartz-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;">
quartz://timerName?options
quartz://groupName/timerName?options
quartz://groupName/timerName?cron=expression
quartz://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="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>
<tr>
<td class='confluenceTd'> <tt>deleteJob</tt> </td>
<td class='confluenceTd'> <tt>true</tt> </td>
<td class='confluenceTd'> <b>Camel 2.12:</b> 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. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>pauseJob</tt> </td>
<td class='confluenceTd'> <tt>false</tt> </td>
<td class='confluenceTd'> <b>Camel 2.12:</b> 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. </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">
<script type="syntaxhighlighter" class="theme: Default; brush: xml; gutter: false"><![CDATA[
from("quartz://myGroup/myTimerName?trigger.repeatInterval=2&amp;trigger.repeatCount=1").routeId("myRoute").to("mock:result");
]]></script>
</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="theme: Default; brush: xml; gutter: false" style="font-size:12px; font-family:
ConfluenceInstalledFont,monospace;">
&lt;bean id="quartz" class="org.apache.camel.component.quartz.QuartzComponent"&gt;
    &lt;property name="propertiesFile" value="com/mycompany/myquartz.properties"/&gt;
&lt;/bean&gt;
</pre>
</div></div>

<h3><a name="Quartz-EnablingQuartzschedulerinJMX"></a>Enabling Quartz scheduler
in JMX</h3>

<p>You need to configure the quartz scheduler properties to enable JMX.<br/>
That is typically setting the option <tt>"org.quartz.scheduler.jmx.export"</tt>
to a <tt>true</tt> value in the configuration file.</p>

<p>From Camel 2.13 onwards Camel will automatic set this option to true, unless explicit
disabled.</p>

<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="theme: Default; brush: xml; gutter: false" style="font-size:12px; font-family:
ConfluenceInstalledFont,monospace;">
&lt;bean id="quartz" class="org.apache.camel.component.quartz.QuartzComponent"&gt;
    &lt;property name="startDelayedSeconds" value="5"/&gt;
&lt;/bean&gt;
</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="theme: Default; brush: java; gutter: false" style="font-size:12px; font-family:
ConfluenceInstalledFont,monospace;">
from("quartz://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="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="theme: Default; brush: java; gutter: false" style="font-size:12px; font-family:
ConfluenceInstalledFont,monospace;">
quartz://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>

<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/Quartz2" title="Quartz2">Quartz2</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/Quartz">View Online</a>
        |
        <a href="https://cwiki.apache.org/confluence/pages/diffpagesbyversion.action?pageId=54900&revisedVersion=51&originalVersion=50">View
Changes</a>
            </div>
</div>
</div>
</div>
</div>
</body>
</html>

Mime
View raw message