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 > Polling Consumer
Date Tue, 25 Jun 2013 06:53:00 GMT
<html>
<head>
    <base href="https://cwiki.apache.org/confluence">
            <link rel="stylesheet" href="/confluence/s/en/2176/1/1/_/styles/combined.css?spaceKey=CAMEL&amp;forWysiwyg=true"
type="text/css">
    </head>
<body style="background: white;" bgcolor="white" class="email-body">
<div id="pageContent">
<div id="notificationFormat">
<div class="wiki-content">
<div class="email">
    <h2><a href="https://cwiki.apache.org/confluence/display/CAMEL/Polling+Consumer">Polling
Consumer</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" >| {{delay}} | {{500}} | Milliseconds
before the next poll. | <br>| {{useFixedDelay}} |  | Controls if fixed delay or fixed
rate is used. See [ScheduledExecutorService|http://java.sun.com/j2se/1.5.0/docs/api/java/util/concurrent/ScheduledExecutorService.html]
in JDK for details. In *Camel 2.7.x* or older the default value is {{false}}. From *Camel
2.8* onwards the default value is {{true}}. | <br></td></tr>
            <tr><td class="diff-changed-lines" >| <span class="diff-changed-words"><span
class="diff-added-chars"style="background-color: #dfd;">{{</span>timeUnit<span
class="diff-added-chars"style="background-color: #dfd;">}}</span></span> |
{{TimeUnit.MILLISECONDS}} | time unit for {{initialDelay}} and {{delay}} options. | <br></td></tr>
            <tr><td class="diff-unchanged" >| {{runLoggingLevel}} | {{TRACE}}
| *Camel 2.8:* The consumer logs a start/complete log line when it polls. This option allows
you to configure the logging level for that. | <br>| {{scheduledExecutorService}} |
{{null}} | *Camel 2.10:* 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. | <br></td></tr>
            <tr><td class="diff-added-lines" style="background-color: #dfd;">|
{{greedy}} | {{false}} | *Camel 2.11.1:* If greedy is enabled, then the ScheduledPollConsumer
will run immediately again, if the previous run polled 1 or more messages. | <br></td></tr>
            <tr><td class="diff-unchanged" >{div} <br> <br></td></tr>
            <tr><td class="diff-snipped" >...<br></td></tr>
    
            </table>
    </div>                            <h4>Full Content</h4>
                    <div class="notificationGreySide">
        <h3><a name="PollingConsumer-PollingConsumer"></a>Polling Consumer</h3>

<p>Camel supports implementing the <a href="http://www.enterpriseintegrationpatterns.com/PollingConsumer.html"
class="external-link" rel="nofollow">Polling Consumer</a> from the <a href="/confluence/display/CAMEL/Enterprise+Integration+Patterns"
title="Enterprise Integration Patterns">EIP patterns</a> using the <a href="http://camel.apache.org/maven/current/camel-core/apidocs/org/apache/camel/PollingConsumer.html"
class="external-link" rel="nofollow">PollingConsumer</a> interface which can be created
via the <a href="http://camel.apache.org/maven/current/camel-core/apidocs/org/apache/camel/Endpoint.html#createPollingConsumer()"
class="external-link" rel="nofollow">Endpoint.createPollingConsumer()</a> method.</p>

<p><span class="image-wrap" style=""><img src="http://www.enterpriseintegrationpatterns.com/img/PollingConsumerSolution.gif"
style="border: 0px solid black" /></span></p>

<p>So in your Java code you can do</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;">
Endpoint endpoint = context.getEndpoint("activemq:my.queue");
PollingConsumer consumer = endpoint.createPollingConsumer();
Exchange exchange = consumer.receive();
</pre>
</div></div>

<p>The <tt>ConsumerTemplate</tt> (discussed below) is also available.</p>

<p>There are 3 main polling methods on <a href="http://camel.apache.org/maven/current/camel-core/apidocs/org/apache/camel/PollingConsumer.html"
class="external-link" rel="nofollow">PollingConsumer</a></p>

<div class='table-wrap'>
<table class='confluenceTable'><tbody>
<tr>
<th class='confluenceTh'> Method name </th>
<th class='confluenceTh'> Description </th>
</tr>
<tr>
<td class='confluenceTd'> <a href="http://camel.apache.org/maven/current/camel-core/apidocs/org/apache/camel/PollingConsumer.html#receive()"
class="external-link" rel="nofollow">receive()</a> </td>
<td class='confluenceTd'> Waits until a message is available and then returns it; potentially
blocking forever </td>
</tr>
<tr>
<td class='confluenceTd'> <a href="http://camel.apache.org/maven/current/camel-core/apidocs/org/apache/camel/PollingConsumer.html#receive(long)"
class="external-link" rel="nofollow">receive(long)</a> </td>
<td class='confluenceTd'> 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 </td>
</tr>
<tr>
<td class='confluenceTd'> <a href="http://camel.apache.org/maven/current/camel-core/apidocs/org/apache/camel/PollingConsumer.html#receiveNoWait()"
class="external-link" rel="nofollow">receiveNoWait()</a> </td>
<td class='confluenceTd'> Attempts to receive a message exchange immediately without
waiting and returning null if a message exchange is not available yet </td>
</tr>
</tbody></table>
</div>


<h3><a name="PollingConsumer-ConsumerTemplate"></a>ConsumerTemplate</h3>

<p>The <tt>ConsumerTemplate</tt> is a template much like Spring's JmsTemplate
or JdbcTemplate supporting the <a href="/confluence/display/CAMEL/Polling+Consumer" title="Polling
Consumer">Polling Consumer</a> EIP. With the template you can consume <a href="/confluence/display/CAMEL/Exchange"
title="Exchange">Exchange</a>s from an <a href="/confluence/display/CAMEL/Endpoint"
title="Endpoint">Endpoint</a>.</p>

<p>The template supports the 3 operations above, but also including convenient methods
for returning the body, etc <tt>consumeBody</tt>.<br/>
The example from above using ConsumerTemplate is:</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;">
Exchange exchange = consumerTemplate.receive("activemq:my.queue");
</pre>
</div></div>
<p>Or to extract and get the body you can do:</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;">
Object body = consumerTemplate.receiveBody("activemq:my.queue");
</pre>
</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" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="theme: Default; brush: java; gutter: false" style="font-size:12px; font-family:
ConfluenceInstalledFont,monospace;">
String body = consumerTemplate.receiveBody("activemq:my.queue", String.class);
</pre>
</div></div>
<p>You get hold of a <tt>ConsumerTemplate</tt> from the <tt>CamelContext</tt>
with the <tt>createConsumerTemplate</tt> operation:</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;">
ConsumerTemplate consumer = context.createConsumerTemplate();
</pre>
</div></div>

<h4><a name="PollingConsumer-UsingConsumerTemplatewithSpringDSL"></a>Using
ConsumerTemplate with Spring DSL</h4>
<p>With the Spring DSL we can declare the consumer in the CamelContext with the <b>consumerTemplate</b>
tag, just like the ProducerTemplate. The example below illustrates this:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<script type="syntaxhighlighter" class="theme: Default; brush: xml; gutter: false"><![CDATA[
&lt;camelContext xmlns="http://camel.apache.org/schema/spring"&gt;
    &lt;!-- define a producer template --&gt;
    &lt;template id="producer"/&gt;
    &lt;!-- define a consumer template --&gt;
    &lt;consumerTemplate id="consumer"/&gt;
    
    &lt;route&gt;
        &lt;from uri="seda:foo"/&gt;
        &lt;to id="result" uri="mock:result"/&gt;
    &lt;/route&gt;
&lt;/camelContext&gt;
]]></script>
</div></div>

<p>Then we can get leverage Spring to inject the <tt>ConsumerTemplate</tt>
in our java class. The code below is part of an unit test but it shows how the consumer and
producer can work together. </p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<script type="syntaxhighlighter" class="theme: Default; brush: java; gutter: false"><![CDATA[
@ContextConfiguration
public class SpringConsumerTemplateTest extends SpringRunWithTestSupport {

    @Autowired
    private ProducerTemplate producer;

    @Autowired
    private ConsumerTemplate consumer;

    @EndpointInject(ref = "result")
    private MockEndpoint mock;

    @Test
    public void testConsumeTemplate() throws Exception {
        // we expect Hello World received in our mock endpoint
        mock.expectedBodiesReceived("Hello World");

        // we use the producer template to send a message to the seda:start endpoint
        producer.sendBody("seda:start", "Hello World");

        // we consume the body from seda:start
        String body = consumer.receiveBody("seda:start", String.class);
        assertEquals("Hello World", body);

        // and then we send the body again to seda:foo so it will be routed to the mock
        // endpoint so our unit test can complete
        producer.sendBody("seda:foo", body);

        // assert mock received the body
        mock.assertIsSatisfied();
    }

}
]]></script>
</div></div>

<h4><a name="PollingConsumer-Timerbasedpollingconsumer"></a>Timer based
polling consumer</h4>
<p>In this sample we use a <a href="/confluence/display/CAMEL/Timer" title="Timer">Timer</a>
to schedule a route to be started every 5th second and invoke our bean <b>MyCoolBean</b>
where we implement the business logic for the <a href="/confluence/display/CAMEL/Polling+Consumer"
title="Polling Consumer">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" style="border-width: 1px;"><div class="codeContent panelContent">
<script type="syntaxhighlighter" class="theme: Default; brush: java; gutter: false"><![CDATA[
MyCoolBean cool = new MyCoolBean();
cool.setProducer(template);
cool.setConsumer(consumer);

from("timer://foo?period=5000").bean(cool, "someBusinessLogic");

from("activemq:queue.foo").to("mock:result");
]]></script>
</div></div>

<p>And then we have out logic in our bean:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<script type="syntaxhighlighter" class="theme: Default; brush: java; gutter: false"><![CDATA[
public static class MyCoolBean {

    private int count;
    private ConsumerTemplate consumer;
    private ProducerTemplate producer;

    public void setConsumer(ConsumerTemplate consumer) {
        this.consumer = consumer;
    }

    public void setProducer(ProducerTemplate producer) {
        this.producer = producer;
    }

    public void someBusinessLogic() {
        // loop to empty queue
        while (true) {
            // receive the message from the queue, wait at most 3 sec
            String msg = consumer.receiveBody("activemq:queue.inbox", 3000, String.class);
            if (msg == null) {
                // no more messages in queue
                break;
            }

            // do something with body
            msg = "Hello " + msg;

            // send it to the next queue
            producer.sendBodyAndHeader("activemq:queue.foo", msg, "number", count++);
        }
    }
}
]]></script>
</div></div>


<h3><a name="PollingConsumer-ScheduledPollComponents"></a>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 href="/confluence/display/CAMEL/Event+Driven+Consumer"
title="Event Driven Consumer">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 href="http://camel.apache.org/maven/current/camel-core/apidocs/org/apache/camel/impl/ScheduledPollConsumer.html"
class="external-link" rel="nofollow">ScheduledPollConsumer</a> base class which makes
it simpler to implement this pattern.</p>

<p>There is also the <a href="/confluence/display/CAMEL/Quartz" title="Quartz">Quartz
Component</a> which provides scheduled delivery of messages using the Quartz enterprise
scheduler.</p>

<p>For more details see:</p>

<ul>
	<li><a href="http://camel.apache.org/maven/current/camel-core/apidocs/org/apache/camel/PollingConsumer.html"
class="external-link" rel="nofollow">PollingConsumer</a></li>
	<li>Scheduled Polling Components
	<ul>
		<li><a href="http://camel.apache.org/maven/current/camel-core/apidocs/org/apache/camel/impl/ScheduledPollConsumer.html"
class="external-link" rel="nofollow">ScheduledPollConsumer</a></li>
		<li><a href="/confluence/display/CAMEL/Atom" title="Atom">Atom</a></li>
		<li><a href="/confluence/display/CAMEL/File2" title="File2">File</a></li>
		<li><a href="/confluence/display/CAMEL/FTP2" title="FTP2">FTP</a></li>
		<li><a href="/confluence/display/CAMEL/hbase" title="hbase">hbase</a></li>
		<li><a href="/confluence/display/CAMEL/iBATIS" title="iBATIS">iBATIS</a></li>
		<li><a href="/confluence/display/CAMEL/JPA" title="JPA">JPA</a></li>
		<li><a href="/confluence/display/CAMEL/Mail" title="Mail">Mail</a></li>
		<li><a href="/confluence/display/CAMEL/MyBatis" title="MyBatis">MyBatis</a></li>
		<li><a href="/confluence/display/CAMEL/Quartz" title="Quartz">Quartz</a></li>
		<li><a href="/confluence/display/CAMEL/SNMP" title="SNMP">SNMP</a></li>
		<li><a href="/confluence/display/CAMEL/AWS-S3" title="AWS-S3">AWS-S3</a></li>
		<li><a href="/confluence/display/CAMEL/AWS-SQS" title="AWS-SQS">AWS-SQS</a></li>
	</ul>
	</li>
</ul>


<h3><a name="PollingConsumer-ScheduledPollConsumerOptions"></a>ScheduledPollConsumer
Options</h3>
<p>The ScheduledPollConsumer supports the following options:</p>

<div class="confluenceTableSmall"><div class='table-wrap'>
<table class='confluenceTable'><tbody>
<tr>
<th class='confluenceTh'> Option </th>
<th class='confluenceTh'> Default </th>
<th class='confluenceTh'> Description </th>
</tr>
<tr>
<td class='confluenceTd'> <tt>pollStrategy</tt> </td>
<td class='confluenceTd'><ul class="alternate" type="square">
	<li></li>
</ul>
</td>
<td class='confluenceTd'> A pluggable <tt>org.apache.camel.PollingConsumerPollingStrategy</tt>
allowing you to provide your custom implementation to control error handling usually occurred
during the <tt>poll</tt> operation <b>before</b> an <a href="/confluence/display/CAMEL/Exchange"
title="Exchange">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 <tt>WARN</tt> level and ignore it. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>sendEmptyMessageWhenIdle</tt> </td>
<td class='confluenceTd'> <tt>false</tt> </td>
<td class='confluenceTd'> <b>Camel 2.9:</b> If the polling consumer did
not poll any files, you can enable this option to send an empty message (no body) instead.
</td>
</tr>
<tr>
<td class='confluenceTd'> <tt>startScheduler</tt> </td>
<td class='confluenceTd'> <tt>true</tt> </td>
<td class='confluenceTd'> Whether the scheduler should be auto started. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>initialDelay</tt> </td>
<td class='confluenceTd'> <tt>1000</tt> </td>
<td class='confluenceTd'> Milliseconds before the first poll starts. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>delay</tt> </td>
<td class='confluenceTd'> <tt>500</tt> </td>
<td class='confluenceTd'> Milliseconds before the next poll. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>useFixedDelay</tt> </td>
<td class='confluenceTd'>&nbsp;</td>
<td class='confluenceTd'> Controls if fixed delay or fixed rate is used. See <a href="http://java.sun.com/j2se/1.5.0/docs/api/java/util/concurrent/ScheduledExecutorService.html"
class="external-link" rel="nofollow">ScheduledExecutorService</a> in JDK for details.
In <b>Camel 2.7.x</b> or older the default value is <tt>false</tt>.
From <b>Camel 2.8</b> onwards the default value is <tt>true</tt>.
</td>
</tr>
<tr>
<td class='confluenceTd'> <tt>timeUnit</tt> </td>
<td class='confluenceTd'> <tt>TimeUnit.MILLISECONDS</tt> </td>
<td class='confluenceTd'> time unit for <tt>initialDelay</tt> and <tt>delay</tt>
options. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>runLoggingLevel</tt> </td>
<td class='confluenceTd'> <tt>TRACE</tt> </td>
<td class='confluenceTd'> <b>Camel 2.8:</b> The consumer logs a start/complete
log line when it polls. This option allows you to configure the logging level for that. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>scheduledExecutorService</tt> </td>
<td class='confluenceTd'> <tt>null</tt> </td>
<td class='confluenceTd'> <b>Camel 2.10:</b> 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. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>greedy</tt> </td>
<td class='confluenceTd'> <tt>false</tt> </td>
<td class='confluenceTd'> <b>Camel 2.11.1:</b> If greedy is enabled, then
the ScheduledPollConsumer will run immediately again, if the previous run polled 1 or more
messages. </td>
</tr>
</tbody></table>
</div>
</div>

<h3><a name="PollingConsumer-Abouterrorhandlingandscheduledpollingconsumers"></a>About
error handling and scheduled polling consumers</h3>
<p><a href="http://camel.apache.org/maven/current/camel-core/apidocs/org/apache/camel/impl/ScheduledPollConsumer.html"
class="external-link" rel="nofollow">ScheduledPollConsumer</a> is scheduled based
and its <tt>run</tt> 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 <tt>java.io.IOException</tt>
could occur. As this error happens <b>before</b> any <a href="/confluence/display/CAMEL/Exchange"
title="Exchange">Exchange</a> has been created and prepared for routing, then the
regular <a href="/confluence/display/CAMEL/Error+handling+in+Camel" title="Error handling
in Camel">Error handling in Camel</a> does not apply. So what does the consumer do
then? Well the exception is propagated back to the <tt>run</tt> method where its
handled. Camel will by default log the exception at <tt>WARN</tt> level and then
ignore it. At next schedule the error could have been resolved and thus being able to poll
the endpoint successfully.</p>

<h4><a name="PollingConsumer-ControllingtheerrorhandlingusingPollingConsumerPollStrategy"></a>Controlling
the error handling using PollingConsumerPollStrategy</h4>

<p><tt>org.apache.camel.PollingConsumerPollStrategy</tt> is a pluggable
strategy that you can configure on the <tt>ScheduledPollConsumer</tt>. The default
implementation <tt>org.apache.camel.impl.DefaultPollingConsumerPollStrategy</tt>
will log the caused exception at <tt>WARN</tt> level and then ignore this issue.</p>

<p>The strategy interface provides the following 3 methods</p>
<ul class="alternate" type="square">
	<li>begin
	<ul class="alternate" type="square">
		<li><tt>void begin(Consumer consumer, Endpoint endpoint)</tt></li>
	</ul>
	</li>
	<li>begin (<b>Camel 2.3</b>)
	<ul class="alternate" type="square">
		<li><tt>boolean begin(Consumer consumer, Endpoint endpoint)</tt></li>
	</ul>
	</li>
	<li>commit
	<ul class="alternate" type="square">
		<li><tt>void commit(Consumer consumer, Endpoint endpoint)</tt></li>
	</ul>
	</li>
	<li>commit (<b>Camel 2.6</b>)
	<ul class="alternate" type="square">
		<li><tt>void commit(Consumer consumer, Endpoint endpoint, int polledMessages)</tt></li>
	</ul>
	</li>
	<li>rollback
	<ul class="alternate" type="square">
		<li><tt>boolean rollback(Consumer consumer, Endpoint endpoint, int retryCounter,
Exception e) throws Exception</tt></li>
	</ul>
	</li>
</ul>


<p>In <b>Camel 2.3</b> onwards the begin method returns a boolean which
indicates whether or not to skipping polling. So you can implement your custom logic and return
<tt>false</tt> if you do not want to poll this time.</p>

<p>In <b>Camel 2.6</b> 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 <tt>rollback</tt> 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 <tt>PollingConsumerPollStrategy</tt> method and put the retry logic
in the <tt>rollback</tt> method. Lets just retry up till 3 times:</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;">
    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;
    }
</pre>
</div></div>

<p>Notice that we are given the <tt>Consumer</tt> 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" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="theme: Default; brush: java; gutter: false" style="font-size:12px; font-family:
ConfluenceInstalledFont,monospace;">
    // error occurred lets restart the consumer, that could maybe resolve the issue
    consumer.stop();
    consumer.start();
</pre>
</div></div>

<p><b>Notice:</b> If you implement the <tt>begin</tt> operation
make sure to avoid throwing exceptions as in such a case the <tt>poll</tt> operation
is not invoked and Camel will invoke the <tt>rollback</tt> directly.</p>

<h4><a name="PollingConsumer-ConfiguringanEndpointtouse%7B%7BPollingConsumerPollStrategy%7D%7D"></a>Configuring
an <a href="/confluence/display/CAMEL/Endpoint" title="Endpoint">Endpoint</a>
to use <tt>PollingConsumerPollStrategy</tt></h4>
<p>To configure an <a href="/confluence/display/CAMEL/Endpoint" title="Endpoint">Endpoint</a>
to use a custom <tt>PollingConsumerPollStrategy</tt> you use the option <tt>pollStrategy</tt>.
For example in the file consumer below we want to use our custom strategy defined in the <a
href="/confluence/display/CAMEL/Registry" title="Registry">Registry</a> with the
bean id <tt>myPoll</tt>:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="theme: Default; brush: java; gutter: false" style="font-size:12px; font-family:
ConfluenceInstalledFont,monospace;">
    from("file://inbox/?pollStrategy=#myPoll").to("activemq:queue:inbox")
</pre>
</div></div>

<h4><a name="PollingConsumer-UsingThisPattern"></a>Using This Pattern</h4>

<p>If you would like to use this EIP Pattern then please read the <a href="/confluence/display/CAMEL/Getting+Started"
title="Getting Started">Getting Started</a>, you may also find the <a href="/confluence/display/CAMEL/Architecture"
title="Architecture">Architecture</a> useful particularly the description of <a
href="/confluence/display/CAMEL/Endpoint" title="Endpoint">Endpoint</a> and <a
href="/confluence/display/CAMEL/URIs" title="URIs">URIs</a>. Then you could try out
some of the <a href="/confluence/display/CAMEL/Examples" title="Examples">Examples</a>
first before trying this pattern out.</p>

<h3><a name="PollingConsumer-SeeAlso"></a>See Also</h3>
<ul class="alternate" type="square">
	<li><a href="/confluence/display/CAMEL/POJO+Consuming" title="POJO Consuming">POJO
Consuming</a></li>
	<li><a href="/confluence/display/CAMEL/Batch+Consumer" title="Batch Consumer">Batch
Consumer</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/Polling+Consumer">View
Online</a>
        |
        <a href="https://cwiki.apache.org/confluence/pages/diffpagesbyversion.action?pageId=52977&revisedVersion=35&originalVersion=34">View
Changes</a>
                |
        <a href="https://cwiki.apache.org/confluence/display/CAMEL/Polling+Consumer?showComments=true&amp;showCommentArea=true#addcomment">Add
Comment</a>
            </div>
</div>
</div>
</div>
</div>
</body>
</html>

Mime
View raw message