camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From build...@apache.org
Subject svn commit: r997330 [2/3] - in /websites/production/camel/content: book-in-one-page.html book-pattern-appendix.html cache/main.pageCache polling-consumer.html
Date Tue, 13 Sep 2016 20:20:25 GMT
Modified: websites/production/camel/content/book-pattern-appendix.html
==============================================================================
--- websites/production/camel/content/book-pattern-appendix.html (original)
+++ websites/production/camel/content/book-pattern-appendix.html Tue Sep 13 20:20:25 2016
@@ -3777,16 +3777,16 @@ from("file://inbox").sort(body
 </div></div><p>&#160;</p><p>For more details see</p><ul><li><a shape="rect" href="message.html">Message</a></li><li><a shape="rect" href="message-endpoint.html">Message Endpoint</a></li></ul><p></p><h4 id="BookPatternAppendix-UsingThisPattern.36">Using This Pattern</h4>
 
 <p>If you would like to use this EIP Pattern then please read the <a shape="rect" href="getting-started.html">Getting Started</a>, you may also find the <a shape="rect" href="architecture.html">Architecture</a> useful particularly the description of <a shape="rect" href="endpoint.html">Endpoint</a> and <a shape="rect" href="uris.html">URIs</a>. Then you could try out some of the <a shape="rect" href="examples.html">Examples</a> first before trying this pattern out.</p>
-<h3 id="BookPatternAppendix-PollingConsumer">Polling Consumer</h3><p>Camel supports implementing the <a shape="rect" class="external-link" href="http://www.enterpriseintegrationpatterns.com/PollingConsumer.html" rel="nofollow">Polling Consumer</a> from the <a shape="rect" href="enterprise-integration-patterns.html">EIP patterns</a> using the <a shape="rect" class="external-link" href="http://camel.apache.org/maven/current/camel-core/apidocs/org/apache/camel/PollingConsumer.html">PollingConsumer</a> interface which can be created via the <a shape="rect" class="external-link" href="http://camel.apache.org/maven/current/camel-core/apidocs/org/apache/camel/Endpoint.html#createPollingConsumer()">Endpoint.createPollingConsumer()</a> method.</p><p><span class="confluence-embedded-file-wrapper"><img class="confluence-embedded-image confluence-external-resource" src="http://www.enterpriseintegrationpatterns.com/img/PollingConsumerSolution.gif" data-image-src="http://www.enterpriseintegration
 patterns.com/img/PollingConsumerSolution.gif"></span></p><p>So in your Java code you can do</p><div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl">
+<h3 id="BookPatternAppendix-PollingConsumer">Polling Consumer</h3><p>Camel supports implementing the <a shape="rect" class="external-link" href="http://www.enterpriseintegrationpatterns.com/PollingConsumer.html" rel="nofollow">Polling Consumer</a> from the <a shape="rect" href="enterprise-integration-patterns.html">EIP patterns</a> using the <a shape="rect" class="external-link" href="http://camel.apache.org/maven/current/camel-core/apidocs/org/apache/camel/PollingConsumer.html">PollingConsumer</a> interface which can be created via the <a shape="rect" class="external-link" href="http://camel.apache.org/maven/current/camel-core/apidocs/org/apache/camel/Endpoint.html#createPollingConsumer()">Endpoint.createPollingConsumer()</a> method.</p><p><span class="confluence-embedded-file-wrapper"><img class="confluence-embedded-image confluence-external-resource" src="http://www.enterpriseintegrationpatterns.com/img/PollingConsumerSolution.gif" data-image-src="http://www.enterpriseintegration
 patterns.com/img/PollingConsumerSolution.gif"></span></p><p>In Java:</p><div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl">
 <script class="brush: java; gutter: false; theme: Default" type="syntaxhighlighter"><![CDATA[Endpoint endpoint = context.getEndpoint(&quot;activemq:my.queue&quot;);
 PollingConsumer consumer = endpoint.createPollingConsumer();
 Exchange exchange = consumer.receive();
 ]]></script>
-</div></div><p>The <code>ConsumerTemplate</code> (discussed below) is also available.</p><p>There are 3 main polling methods on <a shape="rect" class="external-link" href="http://camel.apache.org/maven/current/camel-core/apidocs/org/apache/camel/PollingConsumer.html">PollingConsumer</a></p><div class="table-wrap"><table class="confluenceTable"><tbody><tr><th colspan="1" rowspan="1" class="confluenceTh"><p>Method name</p></th><th colspan="1" rowspan="1" class="confluenceTh"><p>Description</p></th></tr><tr><td colspan="1" rowspan="1" class="confluenceTd"><p><a shape="rect" class="external-link" href="http://camel.apache.org/maven/current/camel-core/apidocs/org/apache/camel/PollingConsumer.html#receive()">receive()</a></p></td><td colspan="1" rowspan="1" class="confluenceTd"><p>Waits until a message is available and then returns it; potentially blocking forever</p></td></tr><tr><td colspan="1" rowspan="1" class="confluenceTd"><p><a shape="rect" class="external-link" href="http://camel.
 apache.org/maven/current/camel-core/apidocs/org/apache/camel/PollingConsumer.html#receive(long)">receive(long)</a></p></td><td colspan="1" rowspan="1" class="confluenceTd"><p>Attempts to receive a message exchange, waiting up to the given timeout and returning null if no message exchange could be received within the time available</p></td></tr><tr><td colspan="1" rowspan="1" class="confluenceTd"><p><a shape="rect" class="external-link" href="http://camel.apache.org/maven/current/camel-core/apidocs/org/apache/camel/PollingConsumer.html#receiveNoWait()">receiveNoWait()</a></p></td><td colspan="1" rowspan="1" class="confluenceTd"><p>Attempts to receive a message exchange immediately without waiting and returning null if a message exchange is not available yet</p></td></tr></tbody></table></div><h3 id="BookPatternAppendix-EventDrivenPollingConsumerOptions">EventDrivenPollingConsumer Options</h3><p>The EventDrivePollingConsumer (the default implementation) supports the following options:
 </p><div class="confluenceTableSmall"><div class="table-wrap"><table class="confluenceTable"><tbody><tr><th colspan="1" rowspan="1" class="confluenceTh"><p>Option</p></th><th colspan="1" rowspan="1" class="confluenceTh"><p>Default</p></th><th colspan="1" rowspan="1" class="confluenceTh"><p>Description</p></th></tr><tr><td colspan="1" rowspan="1" class="confluenceTd"><p><code>pollingConsumerQueueSize</code></p></td><td colspan="1" rowspan="1" class="confluenceTd"><p><code>1000</code></p></td><td colspan="1" rowspan="1" class="confluenceTd"><p><strong>Camel 2.14/2.13.1/2.12.4:</strong> The queue size for the internal handoff queue between the polling consumer, and producers sending data into the queue.</p></td></tr><tr><td colspan="1" rowspan="1" class="confluenceTd"><p><code>pollingConsumerBlockWhenFull</code></p></td><td colspan="1" rowspan="1" class="confluenceTd"><p><code>true</code></p></td><td colspan="1" rowspan="1" class="confluenceTd"><p><strong>Camel 2.14/2.13.1/2.12/4:</str
 ong> Whether to block any producer if the internal queue is full.</p></td></tr><tr><td colspan="1" rowspan="1" class="confluenceTd"><span><code>pollingConsumerBlockTimeout</code></span></td><td colspan="1" rowspan="1" class="confluenceTd">0</td><td colspan="1" rowspan="1" class="confluenceTd"><strong>Camel 2.16:</strong> To use a timeout when the producer is blocked if the internal queue is full. The timeout value is in milli seconds. If the value is 0 or negative then no timeout is in use. If a timeout is triggered then a ExchangeTimedOutException is thrown.</td></tr></tbody></table></div></div><p>Notice that some Camel&#160;<a shape="rect" href="components.html">Components</a>&#160;has their own implementation of&#160;<code>PollingConsumer</code> and therefore do not support the options above.</p><p>You can configure these options in endpoints&#160;<a shape="rect" href="uris.html">URIs</a>, such as shown below:</p><div class="code panel pdl" style="border-width: 1px;"><div class="
 codeContent panelContent pdl">
+</div></div><p>The <strong><code>ConsumerTemplate</code></strong> (discussed below) is also available.</p><p>There are three main polling methods on <a shape="rect" class="external-link" href="http://camel.apache.org/maven/current/camel-core/apidocs/org/apache/camel/PollingConsumer.html">PollingConsumer</a></p><div class="table-wrap"><table class="confluenceTable"><tbody><tr><th colspan="1" rowspan="1" class="confluenceTh"><p>Method name</p></th><th colspan="1" rowspan="1" class="confluenceTh"><p>Description</p></th></tr><tr><td colspan="1" rowspan="1" class="confluenceTd"><p><a shape="rect" class="external-link" href="http://camel.apache.org/maven/current/camel-core/apidocs/org/apache/camel/PollingConsumer.html#receive()">receive()</a></p></td><td colspan="1" rowspan="1" class="confluenceTd"><p>Waits until a message is available and then returns it; potentially blocking forever</p></td></tr><tr><td colspan="1" rowspan="1" class="confluenceTd"><p><a shape="rect" class="external-link
 " href="http://camel.apache.org/maven/current/camel-core/apidocs/org/apache/camel/PollingConsumer.html#receive(long)">receive(long)</a></p></td><td colspan="1" rowspan="1" class="confluenceTd"><p>Attempts to receive a message exchange, waiting up to the given timeout and returning null if no message exchange could be received within the time available</p></td></tr><tr><td colspan="1" rowspan="1" class="confluenceTd"><p><a shape="rect" class="external-link" href="http://camel.apache.org/maven/current/camel-core/apidocs/org/apache/camel/PollingConsumer.html#receiveNoWait()">receiveNoWait()</a></p></td><td colspan="1" rowspan="1" class="confluenceTd"><p>Attempts to receive a message exchange immediately without waiting and returning null if a message exchange is not available yet</p></td></tr></tbody></table></div><h3 id="BookPatternAppendix-EventDrivenPollingConsumerOptions">EventDrivenPollingConsumer Options</h3><p>The&#160;<strong><code>EventDrivePollingConsumer</code></strong> (the
  default implementation) supports the following options:</p><div class="confluenceTableSmall"><div class="table-wrap"><table class="confluenceTable"><tbody><tr><th colspan="1" rowspan="1" class="confluenceTh"><p>Option</p></th><th colspan="1" rowspan="1" class="confluenceTh"><p>Default</p></th><th colspan="1" rowspan="1" class="confluenceTh"><p>Description</p></th></tr><tr><td colspan="1" rowspan="1" class="confluenceTd"><p><code>pollingConsumerQueueSize</code></p></td><td colspan="1" rowspan="1" class="confluenceTd"><p><code>1000</code></p></td><td colspan="1" rowspan="1" class="confluenceTd"><p><strong>Camel 2.14/2.13.1/2.12.4:</strong> The queue size for the internal hand-off queue between the polling consumer, and producers sending data into the queue.</p></td></tr><tr><td colspan="1" rowspan="1" class="confluenceTd"><p><code>pollingConsumerBlockWhenFull</code></p></td><td colspan="1" rowspan="1" class="confluenceTd"><p><code>true</code></p></td><td colspan="1" rowspan="1" class
 ="confluenceTd"><p><strong>Camel 2.14/2.13.1/2.12/4:</strong> Whether to block any producer if the internal queue is full.</p></td></tr><tr><td colspan="1" rowspan="1" class="confluenceTd"><span><code>pollingConsumerBlockTimeout</code></span></td><td colspan="1" rowspan="1" class="confluenceTd">0</td><td colspan="1" rowspan="1" class="confluenceTd"><strong>Camel 2.16:</strong> To use a timeout (in milliseconds) when the producer is blocked if the internal queue is full. If the value is&#160;<strong><code>0</code></strong> or negative then no timeout is in use. If a timeout is triggered then a&#160;<strong><code>ExchangeTimedOutException</code></strong> is thrown.</td></tr></tbody></table></div></div><p>Notice that some Camel&#160;<a shape="rect" href="components.html">Components</a>&#160;has their own implementation of&#160;<strong><code>PollingConsumer</code></strong> and therefore do not support the options above.</p><p>You can configure these options in endpoints&#160;<a shape="r
 ect" href="uris.html">URIs</a>, such as shown below:</p><div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl">
 <script class="brush: java; gutter: false; theme: Default" type="syntaxhighlighter"><![CDATA[Endpoint endpoint = context.getEndpoint(&quot;file:inbox?pollingConsumerQueueSize=50&quot;);
 PollingConsumer consumer = endpoint.createPollingConsumer();
 Exchange exchange = consumer.receive(5000);]]></script>
-</div></div><h3 id="BookPatternAppendix-ConsumerTemplate">ConsumerTemplate</h3><p>The <code>ConsumerTemplate</code> is a template much like Spring's JmsTemplate or JdbcTemplate supporting the <a shape="rect" href="polling-consumer.html">Polling Consumer</a> EIP. With the template you can consume <a shape="rect" href="exchange.html">Exchange</a>s from an <a shape="rect" href="endpoint.html">Endpoint</a>.</p><p>The template supports the 3 operations above, but also including convenient methods for returning the body, etc <code>consumeBody</code>.<br clear="none"> The example from above using ConsumerTemplate is:</p><div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl">
+</div></div><h3 id="BookPatternAppendix-ConsumerTemplate">ConsumerTemplate</h3><p>The <strong><code>ConsumerTemplate</code></strong> is a template much like Spring's&#160;<strong><code>JmsTemplate</code></strong> or&#160;<strong><code>JdbcTemplate</code></strong> supporting the <a shape="rect" href="polling-consumer.html">Polling Consumer</a> EIP. With the template you can consume <a shape="rect" href="exchange.html">Exchange</a>s from an <a shape="rect" href="endpoint.html">Endpoint</a>. The template supports the three operations listed above. However, it also includes convenient methods for returning the body, etc <strong><code>consumeBody</code></strong>.</p><p>Example:</p><div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl">
 <script class="brush: java; gutter: false; theme: Default" type="syntaxhighlighter"><![CDATA[Exchange exchange = consumerTemplate.receive(&quot;activemq:my.queue&quot;);
 ]]></script>
 </div></div><p>Or to extract and get the body you can do:</p><div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl">
@@ -3795,10 +3795,10 @@ Exchange exchange = consumer.receive(500
 </div></div><p>And you can provide the body type as a parameter and have it returned as the type:</p><div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl">
 <script class="brush: java; gutter: false; theme: Default" type="syntaxhighlighter"><![CDATA[String body = consumerTemplate.receiveBody(&quot;activemq:my.queue&quot;, String.class);
 ]]></script>
-</div></div><p>You get hold of a <code>ConsumerTemplate</code> from the <code>CamelContext</code> with the <code>createConsumerTemplate</code> operation:</p><div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl">
+</div></div><p>You get hold of a <strong><code>ConsumerTemplate</code></strong> from the <strong><code>CamelContext</code></strong> with the <strong><code>createConsumerTemplate</code></strong> operation:</p><div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl">
 <script class="brush: java; gutter: false; theme: Default" type="syntaxhighlighter"><![CDATA[ConsumerTemplate consumer = context.createConsumerTemplate();
 ]]></script>
-</div></div><h4 id="BookPatternAppendix-UsingConsumerTemplatewithSpringDSL">Using ConsumerTemplate with Spring DSL</h4><p>With the Spring DSL we can declare the consumer in the CamelContext with the <strong>consumerTemplate</strong> tag, just like the ProducerTemplate. The example below illustrates this:</p><div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl">
+</div></div><h4 id="BookPatternAppendix-UsingConsumerTemplatewithSpringDSL">Using ConsumerTemplate with Spring DSL</h4><p>With the Spring DSL we can declare the consumer in the&#160;<strong><code>CamelContext</code></strong> with the <strong><code>consumerTemplate</code></strong> tag, just like the <strong><code>ProducerTemplate</code></strong>. The example below illustrates this:</p><div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl">
 <script class="brush: xml; gutter: false; theme: Default" type="syntaxhighlighter"><![CDATA[
 &lt;camelContext xmlns=&quot;http://camel.apache.org/schema/spring&quot;&gt;
     &lt;!-- define a producer template --&gt;
@@ -3812,7 +3812,7 @@ Exchange exchange = consumer.receive(500
     &lt;/route&gt;
 &lt;/camelContext&gt;
 ]]></script>
-</div></div>Then we can get leverage Spring to inject the <code>ConsumerTemplate</code> in our java class. The code below is part of an unit test but it shows how the consumer and producer can work together.<div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl">
+</div></div>Then we can get leverage Spring to inject the <strong><code>ConsumerTemplate</code></strong> in our java class. The code below is part of an unit test but it shows how the consumer and producer can work together.<div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl">
 <script class="brush: java; gutter: false; theme: Default" type="syntaxhighlighter"><![CDATA[
 @ContextConfiguration
 public class SpringConsumerTemplateTest extends SpringRunWithTestSupport {
@@ -3848,7 +3848,7 @@ public class SpringConsumerTemplateTest
 
 }
 ]]></script>
-</div></div><h4 id="BookPatternAppendix-Timerbasedpollingconsumer">Timer based polling consumer</h4><p>In this sample we use a <a shape="rect" href="timer.html">Timer</a> to schedule a route to be started every 5th second and invoke our bean <strong>MyCoolBean</strong> where we implement the business logic for the <a shape="rect" href="polling-consumer.html">Polling Consumer</a>. Here we want to consume all messages from a JMS queue, process the message and send them to the next queue.</p><p>First we setup our route as:</p><div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl">
+</div></div><h4 id="BookPatternAppendix-TimerBasedPollingConsumer">Timer Based Polling Consumer</h4><p>In this sample we use a <a shape="rect" href="timer.html">Timer</a> to schedule a route to be started every 5th second and invoke our bean&#160;<strong><code>MyCoolBean</code></strong> where we implement the business logic for the <a shape="rect" href="polling-consumer.html">Polling Consumer</a>. Here we want to consume all messages from a JMS queue, process the message and send them to the next queue.</p><p>First we setup our route as:</p><div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl">
 <script class="brush: java; gutter: false; theme: Default" type="syntaxhighlighter"><![CDATA[
 MyCoolBean cool = new MyCoolBean();
 cool.setProducer(template);
@@ -3893,27 +3893,28 @@ public static class MyCoolBean {
     }
 }
 ]]></script>
-</div></div><h3 id="BookPatternAppendix-ScheduledPollComponents">Scheduled Poll Components</h3><p>Quite a few inbound Camel endpoints use a scheduled poll pattern to receive messages and push them through the Camel processing routes. That is to say externally from the client the endpoint appears to use an <a shape="rect" href="event-driven-consumer.html">Event Driven Consumer</a> but internally a scheduled poll is used to monitor some kind of state or resource and then fire message exchanges.</p><p>Since this a such a common pattern, polling components can extend the <a shape="rect" class="external-link" href="http://camel.apache.org/maven/current/camel-core/apidocs/org/apache/camel/impl/ScheduledPollConsumer.html">ScheduledPollConsumer</a> base class which makes it simpler to implement this pattern.</p><p>There is also the <a shape="rect" href="quartz.html">Quartz Component</a> which provides scheduled delivery of messages using the Quartz enterprise scheduler.</p><p>For more detai
 ls see:</p><ul><li><a shape="rect" class="external-link" href="http://camel.apache.org/maven/current/camel-core/apidocs/org/apache/camel/PollingConsumer.html">PollingConsumer</a></li><li>Scheduled Polling Components<ul><li><a shape="rect" class="external-link" href="http://camel.apache.org/maven/current/camel-core/apidocs/org/apache/camel/impl/ScheduledPollConsumer.html">ScheduledPollConsumer</a></li><li><a shape="rect" href="scheduler.html">Scheduler</a></li><li><a shape="rect" href="atom.html">Atom</a></li><li><a shape="rect" href="beanstalk.html">Beanstalk</a></li><li><a shape="rect" href="file2.html">File</a></li><li><a shape="rect" href="ftp2.html">FTP</a></li><li><a shape="rect" href="hbase.html">hbase</a></li><li><a shape="rect" href="ibatis.html">iBATIS</a></li><li><a shape="rect" href="jpa.html">JPA</a></li><li><a shape="rect" href="mail.html">Mail</a></li><li><a shape="rect" href="mybatis.html">MyBatis</a></li><li><a shape="rect" href="quartz.html">Quartz</a></li><li><a sh
 ape="rect" href="snmp.html">SNMP</a></li><li><a shape="rect" href="aws-s3.html">AWS-S3</a></li><li><a shape="rect" href="aws-sqs.html">AWS-SQS</a></li></ul></li></ul><h3 id="BookPatternAppendix-ScheduledPollConsumerOptions">ScheduledPollConsumer Options</h3><p>The ScheduledPollConsumer supports the following options:</p><div class="confluenceTableSmall"><div class="table-wrap"><table class="confluenceTable"><tbody><tr><th colspan="1" rowspan="1" class="confluenceTh"><p>Option</p></th><th colspan="1" rowspan="1" class="confluenceTh"><p>Default</p></th><th colspan="1" rowspan="1" class="confluenceTh"><p>Description</p></th></tr><tr><td colspan="1" rowspan="1" class="confluenceTd"><p><code>pollStrategy</code></p></td><td colspan="1" rowspan="1" class="confluenceTd">&#160;</td><td colspan="1" rowspan="1" class="confluenceTd"><p>A pluggable <code>org.apache.camel.PollingConsumerPollingStrategy</code> allowing you to provide your custom implementation to control error handling usually occ
 urred during the <code>poll</code> operation <strong>before</strong> an <a shape="rect" href="exchange.html">Exchange</a> have been created and being routed in Camel. In other words the error occurred while the polling was gathering information, for instance access to a file network failed so Camel cannot access it to scan for files. The default implementation will log the caused exception at <code>WARN</code> level and ignore it.</p></td></tr><tr><td colspan="1" rowspan="1" class="confluenceTd"><p><code>sendEmptyMessageWhenIdle</code></p></td><td colspan="1" rowspan="1" class="confluenceTd"><p><code>false</code></p></td><td colspan="1" rowspan="1" class="confluenceTd"><p><strong>Camel 2.9:</strong> If the polling consumer did not poll any files, you can enable this option to send an empty message (no body) instead.</p></td></tr><tr><td colspan="1" rowspan="1" class="confluenceTd"><p><code>startScheduler</code></p></td><td colspan="1" rowspan="1" class="confluenceTd"><p><code>true</
 code></p></td><td colspan="1" rowspan="1" class="confluenceTd"><p>Whether the scheduler should be auto started.</p></td></tr><tr><td colspan="1" rowspan="1" class="confluenceTd"><p><code>initialDelay</code></p></td><td colspan="1" rowspan="1" class="confluenceTd"><p><code>1000</code></p></td><td colspan="1" rowspan="1" class="confluenceTd"><p>Milliseconds before the first poll starts.</p></td></tr><tr><td colspan="1" rowspan="1" class="confluenceTd"><p><code>delay</code></p></td><td colspan="1" rowspan="1" class="confluenceTd"><p><code>500</code></p></td><td colspan="1" rowspan="1" class="confluenceTd"><p>Milliseconds before the next poll.</p></td></tr><tr><td colspan="1" rowspan="1" class="confluenceTd"><p><code>useFixedDelay</code></p></td><td colspan="1" rowspan="1" class="confluenceTd"><p>&#160;</p></td><td colspan="1" rowspan="1" class="confluenceTd"><p>Controls if fixed delay or fixed rate is used. See <a shape="rect" class="external-link" href="http://java.sun.com/j2se/1.5.0/
 docs/api/java/util/concurrent/ScheduledExecutorService.html" rel="nofollow">ScheduledExecutorService</a> in JDK for details. In <strong>Camel 2.7.x</strong> or older the default value is <code>false</code>. From <strong>Camel 2.8</strong> onwards the default value is <code>true</code>.</p></td></tr><tr><td colspan="1" rowspan="1" class="confluenceTd"><p><code>timeUnit</code></p></td><td colspan="1" rowspan="1" class="confluenceTd"><p><code>TimeUnit.MILLISECONDS</code></p></td><td colspan="1" rowspan="1" class="confluenceTd"><p>time unit for <code>initialDelay</code> and <code>delay</code> options.</p></td></tr><tr><td colspan="1" rowspan="1" class="confluenceTd"><p><code>runLoggingLevel</code></p></td><td colspan="1" rowspan="1" class="confluenceTd"><p><code>TRACE</code></p></td><td colspan="1" rowspan="1" class="confluenceTd"><p><strong>Camel 2.8:</strong> The consumer logs a start/complete log line when it polls. This option allows you to configure the logging level for that.</p><
 /td></tr><tr><td colspan="1" rowspan="1" class="confluenceTd"><p><code>scheduledExecutorService</code></p></td><td colspan="1" rowspan="1" class="confluenceTd"><p><code>null</code></p></td><td colspan="1" rowspan="1" class="confluenceTd"><p><strong>Camel 2.10:</strong> Allows for configuring a custom/shared thread pool to use for the consumer. By default each consumer has its own single threaded thread pool. This option allows you to share a thread pool among multiple consumers.</p></td></tr><tr><td colspan="1" rowspan="1" class="confluenceTd"><p><code>greedy</code></p></td><td colspan="1" rowspan="1" class="confluenceTd"><p><code>false</code></p></td><td colspan="1" rowspan="1" class="confluenceTd"><p><strong>Camel 2.10.6/2.11.1:</strong> If greedy is enabled, then the ScheduledPollConsumer will run immediately again, if the previous run polled 1 or more messages.</p></td></tr><tr><td colspan="1" rowspan="1" class="confluenceTd"><p><code>scheduler</code></p></td><td colspan="1" row
 span="1" class="confluenceTd"><p><code>null</code></p></td><td colspan="1" rowspan="1" class="confluenceTd"><p><strong>Camel 2.12:</strong> Allow to plugin a custom <code>org.apache.camel.spi.ScheduledPollConsumerScheduler</code> to use as the scheduler for firing when the polling consumer runs. The default implementation uses the <code>ScheduledExecutorService</code> and there is a <a shape="rect" href="quartz2.html">Quartz2</a>, and <a shape="rect" href="spring.html">Spring</a> based which supports CRON expressions. <strong>Notice:</strong> If using a custom scheduler then the options for <code>initialDelay</code>, <code>useFixedDelay</code>, <code>timeUnit</code>, and <code>scheduledExecutorService</code> may not be in use. Use the text <code>quartz2</code> to refer to use the <a shape="rect" href="quartz2.html">Quartz2</a> scheduler; and use the text <code>spring</code> to use the <a shape="rect" href="spring.html">Spring</a> based; and use the text <code>#myScheduler</code> to 
 refer to a custom scheduler by its id in the <a shape="rect" href="registry.html">Registry</a>. See <a shape="rect" href="quartz2.html">Quartz2</a> page for an example.</p></td></tr><tr><td colspan="1" rowspan="1" class="confluenceTd"><p><code>scheduler.xxx</code></p></td><td colspan="1" rowspan="1" class="confluenceTd"><p><code>null</code></p></td><td colspan="1" rowspan="1" class="confluenceTd"><p><strong>Camel 2.12:</strong> To configure additional properties when using a custom <code>scheduler</code> or any of the <a shape="rect" href="quartz2.html">Quartz2</a>, <a shape="rect" href="spring.html">Spring</a> based scheduler.</p></td></tr><tr><td colspan="1" rowspan="1" class="confluenceTd"><p><code>backoffMultiplier</code></p></td><td colspan="1" rowspan="1" class="confluenceTd"><p><code>0</code></p></td><td colspan="1" rowspan="1" class="confluenceTd"><p><strong>Camel 2.12:</strong> To let the scheduled polling consumer backoff if there has been a number of subsequent idles/erro
 rs in a row. The multiplier is then the number of polls that will be skipped before the next actual attempt is happening again. When this option is in use then <code>backoffIdleThreshold</code> and/or <code>backoffErrorThreshold</code> must also be configured.</p></td></tr><tr><td colspan="1" rowspan="1" class="confluenceTd"><p><code>backoffIdleThreshold</code></p></td><td colspan="1" rowspan="1" class="confluenceTd"><p><code>0</code></p></td><td colspan="1" rowspan="1" class="confluenceTd"><p><strong>Camel 2.12:</strong> The number of subsequent idle polls that should happen before the <code>backoffMultipler</code> should kick-in.</p></td></tr><tr><td colspan="1" rowspan="1" class="confluenceTd"><p><code>backoffErrorThreshold</code></p></td><td colspan="1" rowspan="1" class="confluenceTd"><p><code>0</code></p></td><td colspan="1" rowspan="1" class="confluenceTd"><p><strong>Camel 2.12:</strong> The number of subsequent error polls (failed due some error) that should happen before th
 e <code>backoffMultipler</code> should kick-in.</p></td></tr></tbody></table></div></div><h3 id="BookPatternAppendix-Usingbackofftolettheschedulerbelessaggressive">Using backoff to let the scheduler be less aggressive</h3><p><strong>Available as of Camel 2.12</strong></p><p>The scheduled <a shape="rect" href="polling-consumer.html">Polling Consumer</a> is by default static by using the same poll frequency whether or not there is messages to pickup or not. From Camel 2.12 onwards you can configure the scheduled <a shape="rect" href="polling-consumer.html">Polling Consumer</a> to be more dynamic by using backoff. This allows the scheduler to skip N number of polls when it becomes idle, or there has been X number of errors in a row. See more details in the table above for the <code>backoffXXX</code> options.</p><p>For example to let a FTP consumer backoff if its becoming idle for a while you can do:</p><div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panel
 Content pdl">
-<script class="brush: java; gutter: false; theme: Default" type="syntaxhighlighter"><![CDATA[    from(&quot;ftp://myserver?username=foo&amp;passowrd=secret?delete=true&amp;delay=5s&amp;backoffMultiplier=6&amp;backoffIdleThreshold=5&quot;)
-      .to(&quot;bean:processFile&quot;);
-]]></script>
-</div></div><p>In this example, the FTP consumer will poll for new FTP files evert 5th second. But if it has been idle for 5 attempts in a row, then it will<br clear="none"> backoff using a multiplier of 6, which means it will now poll every 5 x 6 = 30th second instead. When the consumer eventually pickup a file, then the backoff will reset, and the consumer will go back and poll every 5th second again.</p><p>Camel will log at <code>DEBUG</code> level using <code>org.apache.camel.impl.ScheduledPollConsumer</code> when backoff is kicking-in.</p><h3 id="BookPatternAppendix-Abouterrorhandlingandscheduledpollingconsumers">About error handling and scheduled polling consumers</h3><p><a shape="rect" class="external-link" href="http://camel.apache.org/maven/current/camel-core/apidocs/org/apache/camel/impl/ScheduledPollConsumer.html">ScheduledPollConsumer</a> is scheduled based and its <code>run</code> method is invoked periodically based on schedule settings. But errors can also occur when 
 a poll is being executed. For instance if Camel should poll a file network, and this network resource is not available then a <code>java.io.IOException</code> could occur. As this error happens <strong>before</strong> any <a shape="rect" href="exchange.html">Exchange</a> has been created and prepared for routing, then the regular <a shape="rect" href="error-handling-in-camel.html">Error handling in Camel</a> does not apply. So what does the consumer do then? Well the exception is propagated back to the <code>run</code> method where its handled. Camel will by default log the exception at <code>WARN</code> level and then ignore it. At next schedule the error could have been resolved and thus being able to poll the endpoint successfully.</p><h3 id="BookPatternAppendix-Usingacustomscheduler">Using a custom scheduler</h3><p><strong>Available as of Camel 2.12:</strong></p><p>The SPI interface <code>org.apache.camel.spi.ScheduledPollConsumerScheduler</code> allows to implement a custom sch
 eduler to control when the <a shape="rect" href="polling-consumer.html">Polling Consumer</a> runs. The default implementation is based on the JDKs <code>ScheduledExecutorService</code> with a single thread in the thread pool. There is a CRON based implementation in the <a shape="rect" href="quartz2.html">Quartz2</a>, and <a shape="rect" href="spring.html">Spring</a> components.</p><p>For an example of developing and using a custom scheduler, see the unit test <code>org.apache.camel.component.file.FileConsumerCustomSchedulerTest</code> from the source code in <code>camel-core</code>.</p><h4 id="BookPatternAppendix-ControllingtheerrorhandlingusingPollingConsumerPollStrategy">Controlling the error handling using PollingConsumerPollStrategy</h4><p><code>org.apache.camel.PollingConsumerPollStrategy</code> is a pluggable strategy that you can configure on the <code>ScheduledPollConsumer</code>. The default implementation <code>org.apache.camel.impl.DefaultPollingConsumerPollStrategy</code
 > will log the caused exception at <code>WARN</code> level and then ignore this issue.</p><p>The strategy interface provides the following 3 methods</p><ul class="alternate"><li>begin<ul class="alternate"><li><code>void begin(Consumer consumer, Endpoint endpoint)</code></li></ul></li><li>begin (<strong>Camel 2.3</strong>)<ul class="alternate"><li><code>boolean begin(Consumer consumer, Endpoint endpoint)</code></li></ul></li><li>commit<ul class="alternate"><li><code>void commit(Consumer consumer, Endpoint endpoint)</code></li></ul></li><li>commit (<strong>Camel 2.6</strong>)<ul class="alternate"><li><code>void commit(Consumer consumer, Endpoint endpoint, int polledMessages)</code></li></ul></li><li>rollback<ul class="alternate"><li><code>boolean rollback(Consumer consumer, Endpoint endpoint, int retryCounter, Exception e) throws Exception</code></li></ul></li></ul><p>In <strong>Camel 2.3</strong> onwards the begin method returns a boolean which indicates whether or not to skipping po
 lling. So you can implement your custom logic and return <code>false</code> if you do not want to poll this time.</p><p>In <strong>Camel 2.6</strong> onwards the commit method has an additional parameter containing the number of message that was actually polled. For example if there was no messages polled, the value would be zero, and you can react accordingly.</p><p>The most interesting is the <code>rollback</code> as it allows you do handle the caused exception and decide what to do.</p><p>For instance if we want to provide a retry feature to a scheduled consumer we can implement the <code>PollingConsumerPollStrategy</code> method and put the retry logic in the <code>rollback</code> method. Lets just retry up till 3 times:</p><div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl">
-<script class="brush: java; gutter: false; theme: Default" type="syntaxhighlighter"><![CDATA[    public boolean rollback(Consumer consumer, Endpoint endpoint, int retryCounter, Exception e) throws Exception {
-        if (retryCounter &lt; 3) {
-            // return true to tell Camel that it should retry the poll immediately
-            return true;
-        }
-        // okay we give up do not retry anymore
-        return false;
-    }
-]]></script>
-</div></div><p>Notice that we are given the <code>Consumer</code> as a parameter. We could use this to <em>restart</em> the consumer as we can invoke stop and start:</p><div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl">
-<script class="brush: java; gutter: false; theme: Default" type="syntaxhighlighter"><![CDATA[    // error occurred lets restart the consumer, that could maybe resolve the issue
-    consumer.stop();
-    consumer.start();
-]]></script>
-</div></div><p><strong>Notice:</strong> If you implement the <code>begin</code> operation make sure to avoid throwing exceptions as in such a case the <code>poll</code> operation is not invoked and Camel will invoke the <code>rollback</code> directly.</p><h4 id="BookPatternAppendix-ConfiguringantousePollingConsumerPollStrategy">Configuring an <a shape="rect" href="endpoint.html">Endpoint</a> to use <code>PollingConsumerPollStrategy</code></h4><p>To configure an <a shape="rect" href="endpoint.html">Endpoint</a> to use a custom <code>PollingConsumerPollStrategy</code> you use the option <code>pollStrategy</code>. For example in the file consumer below we want to use our custom strategy defined in the <a shape="rect" href="registry.html">Registry</a> with the bean id <code>myPoll</code>:</p><div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl">
-<script class="brush: java; gutter: false; theme: Default" type="syntaxhighlighter"><![CDATA[    from(&quot;file://inbox/?pollStrategy=#myPoll&quot;).to(&quot;activemq:queue:inbox&quot;)
+</div></div><h3 id="BookPatternAppendix-ScheduledPollComponents">Scheduled Poll Components</h3><p>Quite a few inbound Camel endpoints use a scheduled poll pattern to receive messages and push them through the Camel processing routes. That is to say externally from the client the endpoint appears to use an <a shape="rect" href="event-driven-consumer.html">Event Driven Consumer</a> but internally a scheduled poll is used to monitor some kind of state or resource and then fire message exchanges.</p><p>Since this a such a common pattern, polling components can extend the <a shape="rect" class="external-link" href="http://camel.apache.org/maven/current/camel-core/apidocs/org/apache/camel/impl/ScheduledPollConsumer.html">ScheduledPollConsumer</a> base class which makes it simpler to implement this pattern. There is also the <a shape="rect" href="quartz.html">Quartz Component</a> which provides scheduled delivery of messages using the Quartz enterprise scheduler.</p><p>For more details see
 :</p><ul><li><a shape="rect" class="external-link" href="http://camel.apache.org/maven/current/camel-core/apidocs/org/apache/camel/PollingConsumer.html">PollingConsumer</a></li><li>Scheduled Polling Components<ul><li><a shape="rect" class="external-link" href="http://camel.apache.org/maven/current/camel-core/apidocs/org/apache/camel/impl/ScheduledPollConsumer.html">ScheduledPollConsumer</a></li><li><a shape="rect" href="scheduler.html">Scheduler</a></li><li><a shape="rect" href="atom.html">Atom</a></li><li><a shape="rect" href="beanstalk.html">Beanstalk</a></li><li><a shape="rect" href="file2.html">File</a></li><li><a shape="rect" href="ftp2.html">FTP</a></li><li><a shape="rect" href="hbase.html">hbase</a></li><li><a shape="rect" href="ibatis.html">iBATIS</a></li><li><a shape="rect" href="jpa.html">JPA</a></li><li><a shape="rect" href="mail.html">Mail</a></li><li><a shape="rect" href="mybatis.html">MyBatis</a></li><li><a shape="rect" href="quartz.html">Quartz</a></li><li><a shape="r
 ect" href="snmp.html">SNMP</a></li><li><a shape="rect" href="aws-s3.html">AWS-S3</a></li><li><a shape="rect" href="aws-sqs.html">AWS-SQS</a></li></ul></li></ul><h3 id="BookPatternAppendix-ScheduledPollConsumerOptions">ScheduledPollConsumer Options</h3><p>The&#160;<strong><code>ScheduledPollConsumer</code></strong> supports the following options:</p><div class="confluenceTableSmall"><div class="table-wrap"><table class="confluenceTable"><tbody><tr><th colspan="1" rowspan="1" class="confluenceTh"><p>Option</p></th><th colspan="1" rowspan="1" class="confluenceTh"><p>Default</p></th><th colspan="1" rowspan="1" class="confluenceTh"><p>Description</p></th></tr><tr><td colspan="1" rowspan="1" class="confluenceTd"><p><code>backoffErrorThreshold</code></p></td><td colspan="1" rowspan="1" class="confluenceTd"><p><code>0</code></p></td><td colspan="1" rowspan="1" class="confluenceTd"><p><strong>Camel 2.12:</strong> The number of subsequent error polls (failed due some error) that should happen
  before the <strong><code>backoffMultipler</code></strong> should kick-in.</p></td></tr><tr><td colspan="1" rowspan="1" class="confluenceTd"><p><code>backoffIdleThreshold</code></p></td><td colspan="1" rowspan="1" class="confluenceTd"><p><code>0</code></p></td><td colspan="1" rowspan="1" class="confluenceTd"><p><strong>Camel 2.12:</strong> The number of subsequent idle polls that should happen before the <strong><code>backoffMultipler</code></strong> should kick-in.</p></td></tr><tr><td colspan="1" rowspan="1" class="confluenceTd"><p><code>backoffMultiplier</code></p></td><td colspan="1" rowspan="1" class="confluenceTd"><p><code>0</code></p></td><td colspan="1" rowspan="1" class="confluenceTd"><p><strong>Camel 2.12:</strong> To let the scheduled polling consumer back-off if there has been a number of subsequent idles/errors in a row. The multiplier is then the number of polls that will be skipped before the next actual attempt is happening again. When this option is in use then <str
 ong><code>backoffIdleThreshold</code></strong> and/or <strong><code>backoffErrorThreshold</code></strong> must also be configured.</p></td></tr><tr><td colspan="1" rowspan="1" class="confluenceTd"><p><code>delay</code></p></td><td colspan="1" rowspan="1" class="confluenceTd"><p><code>500</code></p></td><td colspan="1" rowspan="1" class="confluenceTd"><p>Milliseconds before the next poll.</p></td></tr><tr><td colspan="1" rowspan="1" class="confluenceTd"><p><code>greedy</code></p></td><td colspan="1" rowspan="1" class="confluenceTd"><p><code>false</code></p></td><td colspan="1" rowspan="1" class="confluenceTd"><p><strong>Camel 2.10.6/2.11.1:</strong> If greedy is enabled, then the&#160;<strong><code>ScheduledPollConsumer</code></strong> will run immediately again, if the previous run polled 1 or more messages.</p></td></tr><tr><td colspan="1" rowspan="1" class="confluenceTd"><p><code>initialDelay</code></p></td><td colspan="1" rowspan="1" class="confluenceTd"><p><code>1000</code></p><
 /td><td colspan="1" rowspan="1" class="confluenceTd"><p>Milliseconds before the first poll starts.</p></td></tr><tr><td colspan="1" rowspan="1" class="confluenceTd"><p><code>pollStrategy</code></p></td><td colspan="1" rowspan="1" class="confluenceTd">&#160;</td><td colspan="1" rowspan="1" class="confluenceTd"><p>A pluggable <strong><code>org.apache.camel.PollingConsumerPollingStrategy</code></strong> allowing you to provide your custom implementation to control error handling usually occurred during the <strong><code>poll</code></strong> operation <em><strong>before</strong></em> an <a shape="rect" href="exchange.html">Exchange</a> has been created and routed in Camel. In other words the error occurred while the polling was gathering information, for instance access to a file network failed so Camel cannot access it to scan for files.</p><p>The default implementation will log the caused exception at <strong><code>WARN</code></strong> level and ignore it.</p></td></tr><tr><td colspan
 ="1" rowspan="1" class="confluenceTd"><p><code>runLoggingLevel</code></p></td><td colspan="1" rowspan="1" class="confluenceTd"><p><code>TRACE</code></p></td><td colspan="1" rowspan="1" class="confluenceTd"><p><strong>Camel 2.8:</strong> The consumer logs a start/complete log line when it polls. This option allows you to configure the logging level for that.</p></td></tr><tr><td colspan="1" rowspan="1" class="confluenceTd"><p><code>scheduledExecutorService</code></p></td><td colspan="1" rowspan="1" class="confluenceTd"><p><code>null</code></p></td><td colspan="1" rowspan="1" class="confluenceTd"><p><strong>Camel 2.10:</strong> Allows for configuring a custom/shared thread pool to use for the consumer. By default each consumer has its own single threaded thread pool. This option allows you to share a thread pool among multiple consumers.</p></td></tr><tr><td colspan="1" rowspan="1" class="confluenceTd"><p><code>scheduler</code></p></td><td colspan="1" rowspan="1" class="confluenceTd">
 <p><code>null</code></p></td><td colspan="1" rowspan="1" class="confluenceTd"><p><strong>Camel 2.12:</strong> Allow to plugin a custom <strong><code>org.apache.camel.spi.ScheduledPollConsumerScheduler</code></strong> to use as the scheduler for firing when the polling consumer runs. The default implementation uses the <strong><code>ScheduledExecutorService</code></strong> and there is a <a shape="rect" href="quartz2.html">Quartz2</a>, and <a shape="rect" href="spring.html">Spring</a> based which supports CRON expressions. <strong>Notice:</strong> If using a custom scheduler then the options for <strong><code>initialDelay</code>, <code>useFixedDelay</code></strong>, <strong><code>timeUnit</code></strong> and <strong><code>scheduledExecutorService</code></strong> may not be in use. Use the text <strong><code>quartz2</code></strong> to refer to use the <a shape="rect" href="quartz2.html">Quartz2</a> scheduler; and use the text <code>spring</code> to use the <a shape="rect" href="spring
 .html">Spring</a> based; and use the text <strong><code>#myScheduler</code></strong> to refer to a custom scheduler by its id in the <a shape="rect" href="registry.html">Registry</a>.</p><p>See <a shape="rect" href="quartz2.html">Quartz2</a> page for an example.</p></td></tr><tr><td colspan="1" rowspan="1" class="confluenceTd"><p><code>scheduler.xxx</code></p></td><td colspan="1" rowspan="1" class="confluenceTd"><p><code>null</code></p></td><td colspan="1" rowspan="1" class="confluenceTd"><p><strong>Camel 2.12:</strong> To configure additional properties when using a custom <strong><code>scheduler</code></strong> or any of the <a shape="rect" href="quartz2.html">Quartz2</a>, <a shape="rect" href="spring.html">Spring</a> based scheduler.</p></td></tr><tr><td colspan="1" rowspan="1" class="confluenceTd"><p><code>sendEmptyMessageWhenIdle</code></p></td><td colspan="1" rowspan="1" class="confluenceTd"><p><code>false</code></p></td><td colspan="1" rowspan="1" class="confluenceTd"><p><str
 ong>Camel 2.9:</strong> If the polling consumer did not poll any files, you can enable this option to send an empty message (no body) instead.</p></td></tr><tr><td colspan="1" rowspan="1" class="confluenceTd"><p><code>startScheduler</code></p></td><td colspan="1" rowspan="1" class="confluenceTd"><p><code>true</code></p></td><td colspan="1" rowspan="1" class="confluenceTd"><p>Whether the scheduler should be auto started.</p></td></tr><tr><td colspan="1" rowspan="1" class="confluenceTd"><p><code>timeUnit</code></p></td><td colspan="1" rowspan="1" class="confluenceTd"><p><code>TimeUnit.MILLISECONDS</code></p></td><td colspan="1" rowspan="1" class="confluenceTd"><p>Time unit for <strong><code>initialDelay</code></strong> and <strong><code>delay</code></strong> options.</p></td></tr><tr><td colspan="1" rowspan="1" class="confluenceTd"><p><code>useFixedDelay</code></p></td><td colspan="1" rowspan="1" class="confluenceTd"><p>&#160;</p></td><td colspan="1" rowspan="1" class="confluenceTd"><
 p>Controls if fixed delay or fixed rate is used. See <a shape="rect" class="external-link" href="http://java.sun.com/j2se/1.5.0/docs/api/java/util/concurrent/ScheduledExecutorService.html" rel="nofollow">ScheduledExecutorService</a> in JDK for details. In <strong>Camel 2.7.x</strong> or older the default value is <strong><code>false</code></strong>.</p><p>From <strong>Camel 2.8</strong>: the default value is <strong><code>true</code></strong>.</p></td></tr></tbody></table></div></div><h3 id="BookPatternAppendix-UsingbackofftoLettheSchedulerbeLessAggressive">Using&#160;<code>backoff</code> to Let the Scheduler be Less Aggressive</h3><p><strong>Available as of Camel 2.12</strong></p><p>The scheduled <a shape="rect" href="polling-consumer.html">Polling Consumer</a> is by default static by using the same poll frequency whether or not there is messages to pickup or not.</p><p>From <strong>Camel 2.12</strong>: you can configure the scheduled <a shape="rect" href="polling-consumer.html">Po
 lling Consumer</a> to be more dynamic by using <strong><code>backoff</code></strong>. This allows the scheduler to skip N number of polls when it becomes idle, or there has been X number of errors in a row. See more details in the table above for the <strong><code>backoffXXX</code></strong> options.</p><p>For example to let a FTP consumer back-off if its becoming idle for a while you can do:</p><div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl">
+<script class="brush: java; gutter: false; theme: Default" type="syntaxhighlighter"><![CDATA[from(&quot;ftp://myserver?username=foo&amp;passowrd=secret?delete=true&amp;delay=5s&amp;backoffMultiplier=6&amp;backoffIdleThreshold=5&quot;)
+  .to(&quot;bean:processFile&quot;);
+]]></script>
+</div></div><p>In this example, the FTP consumer will poll for new FTP files every 5th second. But if it has been idle for 5 attempts in a row, then it will back-off using a multiplier of 6, which means it will now poll every 5 x 6 = 30th second instead. When the consumer eventually pickup a file, then the back-off will reset, and the consumer will go back and poll every 5th second again.</p><p>Camel will log at <strong><code>DEBUG</code></strong> level using <strong><code>org.apache.camel.impl.ScheduledPollConsumer</code></strong> when back-off is kicking-in.</p><h3 id="BookPatternAppendix-AboutErrorHandlingandScheduledPollingConsumers">About Error Handling and Scheduled Polling Consumers</h3><p><a shape="rect" class="external-link" href="http://camel.apache.org/maven/current/camel-core/apidocs/org/apache/camel/impl/ScheduledPollConsumer.html">ScheduledPollConsumer</a> is scheduled based and its <strong><code>run</code></strong> method is invoked periodically based on schedule sett
 ings. But errors can also occur when a poll is being executed. For instance if Camel should poll a file network, and this network resource is not available then a <strong><code>java.io.IOException</code></strong> could occur. As this error happens <strong>before</strong> any <a shape="rect" href="exchange.html">Exchange</a> has been created and prepared for routing, then the regular <a shape="rect" href="error-handling-in-camel.html">Error handling in Camel</a> does not apply. So what does the consumer do then? Well the exception is propagated back to the <strong><code>run</code></strong> method where its handled. Camel will by default log the exception at <strong><code>WARN</code></strong> level and then ignore it. At next schedule the error could have been resolved and thus being able to poll the endpoint successfully.</p><h3 id="BookPatternAppendix-UsingaCustomScheduler">Using a Custom Scheduler</h3><p><strong>Available as of Camel 2.12:</strong></p><p>The SPI interface <strong><
 code>org.apache.camel.spi.ScheduledPollConsumerScheduler</code></strong> allows to implement a custom scheduler to control when the <a shape="rect" href="polling-consumer.html">Polling Consumer</a> runs. The default implementation is based on the JDKs <strong><code>ScheduledExecutorService</code></strong> with a single thread in the thread pool. There is a CRON based implementation in the <a shape="rect" href="quartz2.html">Quartz2</a>, and <a shape="rect" href="spring.html">Spring</a> components.</p><p>For an example of developing and using a custom scheduler, see the unit test <strong><code>org.apache.camel.component.file.FileConsumerCustomSchedulerTest</code></strong> from the source code in <strong><code>camel-core</code></strong>.</p><h4 id="BookPatternAppendix-ErrorHandlingWhenUsingPollingConsumerPollStrategy">Error Handling When Using&#160;<code>PollingConsumerPollStrategy</code></h4><p><strong><code>org.apache.camel.PollingConsumerPollStrategy</code></strong> is a pluggable 
 strategy that you can configure on the <strong><code>ScheduledPollConsumer</code></strong>. The default implementation <strong><code>org.apache.camel.impl.DefaultPollingConsumerPollStrategy</code></strong> will log the caused exception at <strong><code>WARN</code></strong> level and then ignore this issue.</p><p>The strategy interface provides the following three methods:</p><ul class="alternate"><li><strong><code>begin</code></strong><br clear="none"><ul class="alternate"><li><code>void begin(Consumer consumer, Endpoint endpoint)</code></li></ul></li><li><strong><code>begin</code></strong>&#160;(<strong>Camel 2.3</strong>)<ul class="alternate"><li><code>boolean begin(Consumer consumer, Endpoint endpoint)</code></li></ul></li><li><strong><code>commit</code></strong><br clear="none"><ul class="alternate"><li><code>void commit(Consumer consumer, Endpoint endpoint)</code></li></ul></li><li><strong><code>commit</code></strong>&#160;(<strong>Camel 2.6</strong>)<ul class="alternate"><li><
 code>void commit(Consumer consumer, Endpoint endpoint, int polledMessages)</code></li></ul></li><li><strong><code>rollback</code></strong><br clear="none"><ul class="alternate"><li><code>boolean rollback(Consumer consumer, Endpoint endpoint, int retryCounter, Exception e) throws Exception</code></li></ul></li></ul><p>In <strong>Camel 2.3</strong>: the begin method returns a&#160;<strong><code>boolean</code></strong> which indicates whether or not to skipping polling. So you can implement your custom logic and return <strong><code>false</code></strong> if you do not want to poll this time.</p><p>In <strong>Camel 2.6</strong>: the commit method has an additional parameter containing the number of message that was actually polled. For example if there was no messages polled, the value would be zero, and you can react accordingly.</p><p>The most interesting is the <strong><code>rollback</code></strong> as it allows you do handle the caused exception and decide what to do.</p><p>For inst
 ance if we want to provide a retry feature to a scheduled consumer we can implement the <strong><code>PollingConsumerPollStrategy</code></strong> method and put the retry logic in the <strong><code>rollback</code></strong> method. Lets just retry up till three times:</p><div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl">
+<script class="brush: java; gutter: false; theme: Default" type="syntaxhighlighter"><![CDATA[public boolean rollback(Consumer consumer, Endpoint endpoint, int retryCounter, Exception e) throws Exception {
+  if (retryCounter &lt; 3) {
+    // return true to tell Camel that it should retry the poll immediately
+    return true;
+  }
+
+  // okay we give up do not retry anymore
+  return false;
+}]]></script>
+</div></div><p>Notice that we are given the <strong><code>Consumer</code></strong> as a parameter. We could use this to <em>restart</em> the consumer as we can invoke stop and start:</p><div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl">
+<script class="brush: java; gutter: false; theme: Default" type="syntaxhighlighter"><![CDATA[// error occurred lets restart the consumer, that could maybe resolve the issue
+consumer.stop();
+consumer.start();
+]]></script>
+</div></div><p><strong>Note:</strong> if you implement the <strong><code>begin</code></strong> operation make sure to avoid throwing exceptions as in such a case the <strong><code>poll</code></strong> operation is not invoked and Camel will invoke the <strong><code>rollback</code></strong> directly.</p><h4 id="BookPatternAppendix-ConfiguringantoUsePollingConsumerPollStrategy">Configuring an <a shape="rect" href="endpoint.html">Endpoint</a> to Use <code>PollingConsumerPollStrategy</code></h4><p>To configure an <a shape="rect" href="endpoint.html">Endpoint</a> to use a custom <strong><code>PollingConsumerPollStrategy</code></strong> you use the option <strong><code>pollStrategy</code></strong>. For example in the file consumer below we want to use our custom strategy defined in the <a shape="rect" href="registry.html">Registry</a> with the bean id <strong><code>myPoll</code></strong>:</p><div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl">
+<script class="brush: java; gutter: false; theme: Default" type="syntaxhighlighter"><![CDATA[from(&quot;file://inbox/?pollStrategy=#myPoll&quot;)
+  .to(&quot;activemq:queue:inbox&quot;)
 ]]></script>
 </div></div><p></p><h4 id="BookPatternAppendix-UsingThisPattern.37">Using This Pattern</h4>
 

Modified: websites/production/camel/content/cache/main.pageCache
==============================================================================
Binary files - no diff available.



Mime
View raw message