camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From conflue...@apache.org
Subject [CONF] Apache Camel > Timer
Date Wed, 13 Apr 2011 12:44: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/Timer">Timer</a></h2>
    <h4>Page <b>edited</b> by             <a href="https://cwiki.apache.org/confluence/display/~davsclaus">Claus
Ibsen</a>
    </h4>
        <br/>
                         <h4>Changes (11)</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" >|| Name || Default Value || Description
|| <br>| {{time}} | {{null}} | A {{java.util.Date}} the *first* event should be generated.
If using the URI, the pattern expected is: {{yyyy-MM-dd HH:mm:ss}} or {{yyyy-MM-dd&#39;T&#39;HH:mm:ss}}.
| <br></td></tr>
            <tr><td class="diff-changed-lines" >| {{pattern}} | {{null}} | <span
class="diff-deleted-words"style="color:#999;background-color:#fdd;text-decoration:line-through;">*Camel
1.6.2/2.0:*</span> Allows you to specify a custom {{Date}} pattern to use for setting
the time option using URI syntax. | <br></td></tr>
            <tr><td class="diff-unchanged" >| {{period}} | {{1000}} | If greater
than 0, generate periodic events every {{period}} milliseconds. | <br>| {{delay}} |
{{0}} | The number of milliseconds to wait before the first event is generated. Should not
be used in conjunction with the {{time}} option. |  <br>| {{fixedRate}} | {{false}}
| Events take place at approximately regular intervals, separated by the specified period.
|  <br>| {{daemon}} | {{true}} | Specifies whether or not the thread associated with
the timer endpoint runs as a daemon. |  <br></td></tr>
            <tr><td class="diff-added-lines" style="background-color: #dfd;">|
{{repeatCount}} | {{0}} | *Camel 2.8:* Specifies a maximum limit of number of fires. So if
you set it to 1, the timer will only fire once. If you set it to 5, it will only fire five
times. A value of zero or negative means fire forever. | <br></td></tr>
            <tr><td class="diff-unchanged" >{div} <br> <br></td></tr>
            <tr><td class="diff-snipped" >...<br></td></tr>
            <tr><td class="diff-unchanged" >{div:class=confluenceTableSmall} <br>||
Name || Type || Description || <br></td></tr>
            <tr><td class="diff-changed-lines" >| <span class="diff-deleted-words"style="color:#999;background-color:#fdd;text-decoration:line-through;">{{org.apache.camel.timer.name}}</span>
<span class="diff-added-words"style="background-color: #dfd;">{{Exchange.TIMER_NAME}}</span>
| {{String}} | The value of the {{name}} option. | <br></td></tr>
            <tr><td class="diff-changed-lines" >| <span class="diff-deleted-words"style="color:#999;background-color:#fdd;text-decoration:line-through;">{{org.apache.camel.timer.time}}</span>
<span class="diff-added-words"style="background-color: #dfd;">{{Exchange.TIMER_TIME}}</span>
| {{Date}} | The value of the {{time}} option. | <br></td></tr>
            <tr><td class="diff-changed-lines" >| <span class="diff-deleted-words"style="color:#999;background-color:#fdd;text-decoration:line-through;">{{org.apache.camel.timer.period}}</span>
<span class="diff-added-words"style="background-color: #dfd;">{{Exchange.TIMER_PERIOD}}</span>
| {{long}} | The value of the {{period}} option. | <br></td></tr>
            <tr><td class="diff-deleted-lines" style="color:#999;background-color:#fdd;text-decoration:line-through;">|
{{org.apache.camel.timer.firedTime}} | {{Date}} | *Camel 1.5*: The time when the consumer
fired. | <br></td></tr>
            <tr><td class="diff-added-lines" style="background-color: #dfd;">|
{{Exchange.TIMER_FIRED_TIME}} | {{Date}} | The time when the consumer fired. | <br>|
{{Exchange.TIMER_COUNTER}} | {{Long}} | *Camel 2.8:* The current fire counter. Starts from
1. | <br></td></tr>
            <tr><td class="diff-unchanged" >{div} <br> <br></td></tr>
            <tr><td class="diff-snipped" >...<br></td></tr>
            <tr><td class="diff-unchanged" >{div:class=confluenceTableSmall} <br>||
Name || Type || Description || <br></td></tr>
            <tr><td class="diff-deleted-lines" style="color:#999;background-color:#fdd;text-decoration:line-through;">|
{{firedTime}} | {{java.util.Date}} | Camel 1.5: The time when the consumer fired | <br></td></tr>
            <tr><td class="diff-added-lines" style="background-color: #dfd;">|
{{Exchange.TIMER_FIRED_TIME}} | {{java.util.Date}} | The time when the consumer fired | <br></td></tr>
            <tr><td class="diff-unchanged" >{div} <br> <br></td></tr>
            <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;">{tip}
<br>Instead of 60000 you can use period=60s which is more friendly to read. <br>{tip}
<br> <br></td></tr>
            <tr><td class="diff-unchanged" >The above route will generate an event
and then invoke the {{someMethodName}} method on the bean called {{myBean}} in the [Registry]
such as JNDI or [Spring]. <br> <br></td></tr>
            <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;">h4.
Firing only once <br>*Available as of Camel 2.8* <br> <br>You may want to
fire a message in a Camel route only once, such as when starting the route. To do that you
use the repeatCount option as shown: <br>{code:xml} <br>  &lt;route&gt;
<br>    &lt;from uri=&quot;timer://foo?repeatCount=1&quot;/&gt; <br>
   &lt;to uri=&quot;bean:myBean?method=someMethodName&quot;/&gt; <br>
 &lt;/route&gt; <br>{code} <br> <br> <br></td></tr>
            <tr><td class="diff-unchanged" >{include:Endpoint See Also} <br>*
[Quartz] <br></td></tr>
    
            </table>
    </div>                            <h4>Full Content</h4>
                    <div class="notificationGreySide">
        <h2><a name="Timer-TimerComponent"></a>Timer Component</h2>

<p>The <b>timer:</b> component is used to generate message exchanges when
a timer fires You can only consume events from this endpoint.  </p>

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

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
timer:name[?options]
</pre>
</div></div> 

<p>Where <tt>name</tt> is the name of the <tt>Timer</tt> object,
which is created and shared across endpoints. So if you use the same name for all your timer
endpoints, only one <tt>Timer</tt> object and thread will be used.</p>

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

<p><b>Note:</b> The IN body of the generated exchange is <tt>null</tt>.
So <tt>exchange.getIn().getBody()</tt> returns <tt>null</tt>.</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><b>Advanced Scheduler</b><br
/>See also the <a href="/confluence/display/CAMEL/Quartz" title="Quartz">Quartz</a>
component that supports much more advanced scheduling.</td></tr></table></div>

<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><b>Specify time in human
friendly format</b><br />In <b>Camel 2.3</b> onwards you can specify
the time in <a href="/confluence/display/CAMEL/How+do+I+specify+time+period+in+a+human+friendly+syntax"
title="How do I specify time period in a human friendly syntax">human friendly syntax</a>.</td></tr></table></div>

<h3><a name="Timer-Options"></a>Options</h3>
<div class="confluenceTableSmall"><div class='table-wrap'>
<table class='confluenceTable'><tbody>
<tr>
<th class='confluenceTh'> Name </th>
<th class='confluenceTh'> Default Value </th>
<th class='confluenceTh'> Description </th>
</tr>
<tr>
<td class='confluenceTd'> <tt>time</tt> </td>
<td class='confluenceTd'> <tt>null</tt> </td>
<td class='confluenceTd'> A <tt>java.util.Date</tt> the <b>first</b>
event should be generated. If using the URI, the pattern expected is: <tt>yyyy-MM-dd
HH:mm:ss</tt> or <tt>yyyy-MM-dd'T'HH:mm:ss</tt>. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>pattern</tt> </td>
<td class='confluenceTd'> <tt>null</tt> </td>
<td class='confluenceTd'> Allows you to specify a custom <tt>Date</tt> pattern
to use for setting the time option using URI syntax. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>period</tt> </td>
<td class='confluenceTd'> <tt>1000</tt> </td>
<td class='confluenceTd'> If greater than 0, generate periodic events every <tt>period</tt>
milliseconds. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>delay</tt> </td>
<td class='confluenceTd'> <tt>0</tt> </td>
<td class='confluenceTd'> The number of milliseconds to wait before the first event
is generated. Should not be used in conjunction with the <tt>time</tt> option.
</td>
</tr>
<tr>
<td class='confluenceTd'> <tt>fixedRate</tt> </td>
<td class='confluenceTd'> <tt>false</tt> </td>
<td class='confluenceTd'> Events take place at approximately regular intervals, separated
by the specified period. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>daemon</tt> </td>
<td class='confluenceTd'> <tt>true</tt> </td>
<td class='confluenceTd'> Specifies whether or not the thread associated with the timer
endpoint runs as a daemon. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>repeatCount</tt> </td>
<td class='confluenceTd'> <tt>0</tt> </td>
<td class='confluenceTd'> <b>Camel 2.8:</b> Specifies a maximum limit of
number of fires. So if you set it to 1, the timer will only fire once. If you set it to 5,
it will only fire five times. A value of zero or negative means fire forever. </td>
</tr>
</tbody></table>
</div>
</div>

<h3><a name="Timer-ExchangeProperties"></a>Exchange Properties</h3>
<p>When the timer is fired, it adds the following information as properties to the <tt>Exchange</tt>:</p>
<div class="confluenceTableSmall"><div class='table-wrap'>
<table class='confluenceTable'><tbody>
<tr>
<th class='confluenceTh'> Name </th>
<th class='confluenceTh'> Type </th>
<th class='confluenceTh'> Description </th>
</tr>
<tr>
<td class='confluenceTd'> <tt>Exchange.TIMER_NAME</tt> </td>
<td class='confluenceTd'> <tt>String</tt> </td>
<td class='confluenceTd'> The value of the <tt>name</tt> option. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>Exchange.TIMER_TIME</tt> </td>
<td class='confluenceTd'> <tt>Date</tt> </td>
<td class='confluenceTd'> The value of the <tt>time</tt> option. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>Exchange.TIMER_PERIOD</tt> </td>
<td class='confluenceTd'> <tt>long</tt> </td>
<td class='confluenceTd'> The value of the <tt>period</tt> option. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>Exchange.TIMER_FIRED_TIME</tt> </td>
<td class='confluenceTd'> <tt>Date</tt> </td>
<td class='confluenceTd'> The time when the consumer fired. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>Exchange.TIMER_COUNTER</tt> </td>
<td class='confluenceTd'> <tt>Long</tt> </td>
<td class='confluenceTd'> <b>Camel 2.8:</b> The current fire counter. Starts
from 1. </td>
</tr>
</tbody></table>
</div>
</div>

<h3><a name="Timer-MessageHeaders"></a>Message Headers</h3>
<p>When the timer is fired, it adds the following information as headers to the IN message</p>
<div class="confluenceTableSmall"><div class='table-wrap'>
<table class='confluenceTable'><tbody>
<tr>
<th class='confluenceTh'> Name </th>
<th class='confluenceTh'> Type </th>
<th class='confluenceTh'> Description </th>
</tr>
<tr>
<td class='confluenceTd'> <tt>Exchange.TIMER_FIRED_TIME</tt> </td>
<td class='confluenceTd'> <tt>java.util.Date</tt> </td>
<td class='confluenceTd'> The time when the consumer fired </td>
</tr>
</tbody></table>
</div>
</div>

<h3><a name="Timer-Sample"></a>Sample</h3>

<p>To set up a route that generates an event every 60 seconds:</p>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
   from(<span class="code-quote">"timer:<span class="code-comment">//foo?fixedRate=<span
class="code-keyword">true</span>&amp;period=60000"</span>).to(<span
class="code-quote">"bean:myBean?method=someMethodName"</span>);</span>
</pre>
</div></div>

<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>Instead of 60000 you can use period=60s
which is more friendly to read.</td></tr></table></div>

<p>The above route will generate an event and then invoke the <tt>someMethodName</tt>
method on the bean called <tt>myBean</tt> in the <a href="/confluence/display/CAMEL/Registry"
title="Registry">Registry</a> such as JNDI or <a href="/confluence/display/CAMEL/Spring"
title="Spring">Spring</a>.</p>

<p>And the route in Spring DSL:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-xml">
  <span class="code-tag">&lt;route&gt;</span>
    <span class="code-tag">&lt;from uri=<span class="code-quote">"timer://foo?fixedRate=true&amp;amp;period=60000"</span>/&gt;</span>
    <span class="code-tag">&lt;to uri=<span class="code-quote">"bean:myBean?method=someMethodName"</span>/&gt;</span>
  <span class="code-tag">&lt;/route&gt;</span>
</pre>
</div></div>

<h4><a name="Timer-Firingonlyonce"></a>Firing only once</h4>
<p><b>Available as of Camel 2.8</b></p>

<p>You may want to fire a message in a Camel route only once, such as when starting
the route. To do that you use the repeatCount option as shown:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-xml">
  <span class="code-tag">&lt;route&gt;</span>
    <span class="code-tag">&lt;from uri=<span class="code-quote">"timer://foo?repeatCount=1"</span>/&gt;</span>
    <span class="code-tag">&lt;to uri=<span class="code-quote">"bean:myBean?method=someMethodName"</span>/&gt;</span>
  <span class="code-tag">&lt;/route&gt;</span>
</pre>
</div></div>


<h3><a name="Timer-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>
</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/Timer">View Online</a>
        |
        <a href="https://cwiki.apache.org/confluence/pages/diffpagesbyversion.action?pageId=52137&revisedVersion=20&originalVersion=19">View
Changes</a>
                |
        <a href="https://cwiki.apache.org/confluence/display/CAMEL/Timer?showComments=true&amp;showCommentArea=true#addcomment">Add
Comment</a>
            </div>
</div>
</div>
</div>
</div>
</body>
</html>

Mime
View raw message