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, 28 Apr 2010 16:20:00 GMT
<html>
<head>
    <base href="http://cwiki.apache.org/confluence">
            <link rel="stylesheet" href="/confluence/s/1810/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="http://cwiki.apache.org/confluence/display/CAMEL/Timer">Timer</a></h2>
    <h4>Page <b>edited</b> by             <a href="http://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" >{tip} <br> <br></td></tr>
            <tr><td class="diff-added-lines" style="background-color: #dfd;">{tip:title=Specify
time in human friendly format} <br>In *Camel 2.3* onwards you can specify the time in
[human friendly syntax|How do I specify time period in a human friendly syntax]. <br>{tip}
<br> <br></td></tr>
            <tr><td class="diff-unchanged" >h3. Options <br> <br></td></tr>
            <tr><td class="diff-snipped" >...<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='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'> <b>Camel 1.6.2/2.0:</b> 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>
</tbody></table>
</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='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>org.apache.camel.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>org.apache.camel.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>org.apache.camel.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>org.apache.camel.timer.firedTime</tt> </td>
<td class='confluenceTd'> <tt>Date</tt> </td>
<td class='confluenceTd'> <b>Camel 1.5</b>: The time when the consumer fired.
</td>
</tr>
</tbody></table>
</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='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>firedTime</tt> </td>
<td class='confluenceTd'> <tt>java.util.Date</tt> </td>
<td class='confluenceTd'> Camel 1.5: The time when the consumer fired </td>
</tr>
</tbody></table>
</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>

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

<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="http://cwiki.apache.org/confluence/users/viewnotifications.action"
class="grey">Change Notification Preferences</a>
        </div>
        <a href="http://cwiki.apache.org/confluence/display/CAMEL/Timer">View Online</a>
        |
        <a href="http://cwiki.apache.org/confluence/pages/diffpagesbyversion.action?pageId=52137&revisedVersion=18&originalVersion=17">View
Changes</a>
                |
        <a href="http://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