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 Sun Jul 12 09:19:43 2015 @@ -93,11 +93,11 @@ <h2 id="BookPatternAppendix-MessagingSystems">Messaging Systems</h2> <h3 id="BookPatternAppendix-MessageChannel">Message Channel</h3><p>Camel supports the <a shape="rect" class="external-link" href="http://www.enterpriseintegrationpatterns.com/MessageChannel.html" rel="nofollow">Message Channel</a> from the <a shape="rect" href="enterprise-integration-patterns.html">EIP patterns</a>. The Message Channel is an internal implementation detail of the <a shape="rect" class="external-link" href="http://camel.apache.org/maven/current/camel-core/apidocs/org/apache/camel/Endpoint.html">Endpoint</a> interface and all interactions with the Message Channel are via the Endpoint interfaces.</p><p><span class="confluence-embedded-file-wrapper"><img class="confluence-embedded-image confluence-external-resource" src="http://www.enterpriseintegrationpatterns.com/img/MessageChannelSolution.gif" data-image-src="http://www.enterpriseintegrationpatterns.com/img/MessageChannelSolution.gif"></span></p><p><strong style="font-size: 16.0px;line-height: 1.5625;"><br clear="none "></strong></p><p><strong style="font-size: 16.0px;line-height: 1.5625;">Example</strong></p><p>In JMS, Message Channels are represented by topics and queues such as the following</p><div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl"> -<pre class="brush: text; gutter: false; theme: Default" style="font-size:12px;">jms:queue:foo</pre> +<script class="brush: text; gutter: false; theme: Default" type="syntaxhighlighter"><![CDATA[jms:queue:foo]]></script> </div></div><p> </p><p>This message channel can be then used within the <a shape="rect" href="jms.html">JMS</a> component</p><p><strong style="line-height: 1.4285715;">Using the <a shape="rect" href="fluent-builders.html">Fluent Builders</a></strong></p><div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl"> -<pre class="brush: java; gutter: false; theme: Default" style="font-size:12px;">to("jms:queue:foo")</pre> +<script class="brush: java; gutter: false; theme: Default" type="syntaxhighlighter"><![CDATA[to("jms:queue:foo")]]></script> </div></div><p><strong><br clear="none"></strong></p><p><strong>Using the <a shape="rect" href="spring-xml-extensions.html">Spring XML Extensions</a></strong></p><div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl"> -<pre class="brush: xml; gutter: false; theme: Default" style="font-size:12px;"><to uri="jms:queue:foo"/></pre> +<script class="brush: xml; gutter: false; theme: Default" type="syntaxhighlighter"><![CDATA[<to uri="jms:queue:foo"/>]]></script> </div></div><p> </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">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> @@ -113,39 +113,39 @@ <p><strong>Requestor Code</strong></p> <div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl"> -<pre class="brush: java; gutter: false; theme: Default" style="font-size:12px;"> +<script class="brush: java; gutter: false; theme: Default" type="syntaxhighlighter"><![CDATA[ //InOnly -getContext().createProducerTemplate().sendBody("direct:startInOnly", "Hello World"); +getContext().createProducerTemplate().sendBody("direct:startInOnly", "Hello World"); //InOut -String result = (String) getContext().createProducerTemplate().requestBody("direct:startInOut", "Hello World"); +String result = (String) getContext().createProducerTemplate().requestBody("direct:startInOut", "Hello World"); -</pre> +]]></script> </div></div> <p><strong>Route Using the <a shape="rect" href="fluent-builders.html">Fluent Builders</a></strong></p> <div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl"> -<pre class="brush: java; gutter: false; theme: Default" style="font-size:12px;"> -from("direct:startInOnly").inOnly("bean:process"); +<script class="brush: java; gutter: false; theme: Default" type="syntaxhighlighter"><![CDATA[ +from("direct:startInOnly").inOnly("bean:process"); -from("direct:startInOut").inOut("bean:process"); -</pre> +from("direct:startInOut").inOut("bean:process"); +]]></script> </div></div> <p><strong>Route Using the <a shape="rect" href="spring-xml-extensions.html">Spring XML Extensions</a></strong></p> <div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl"> -<pre class="brush: java; gutter: false; theme: Default" style="font-size:12px;"> +<script class="brush: java; gutter: false; theme: Default" type="syntaxhighlighter"><![CDATA[ <route> - <from uri="direct:startInOnly"/> - <inOnly uri="bean:process"/> + <from uri="direct:startInOnly"/> + <inOnly uri="bean:process"/> </route> <route> - <from uri="direct:startInOut"/> - <inOut uri="bean:process"/> + <from uri="direct:startInOut"/> + <inOut uri="bean:process"/> </route> -</pre> +]]></script> </div></div> <h4 id="BookPatternAppendix-UsingThisPattern.1">Using This Pattern</h4> @@ -174,50 +174,50 @@ from("direct:a").pipeline(&quo <p>In Spring XML you can use the <pipeline/> element</p> <div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl"> -<pre class="brush: java; gutter: false; theme: Default" style="font-size:12px;"> +<script class="brush: java; gutter: false; theme: Default" type="syntaxhighlighter"><![CDATA[ <route> - <from uri="activemq:SomeQueue"/> + <from uri="activemq:SomeQueue"/> <pipeline> - <bean ref="foo"/> - <bean ref="bar"/> - <to uri="activemq:OutputQueue"/> + <bean ref="foo"/> + <bean ref="bar"/> + <to uri="activemq:OutputQueue"/> </pipeline> </route> -</pre> +]]></script> </div></div> <p>In the above the pipeline element is actually unnecessary, you could use this...</p> <div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl"> -<pre class="brush: java; gutter: false; theme: Default" style="font-size:12px;"> +<script class="brush: java; gutter: false; theme: Default" type="syntaxhighlighter"><![CDATA[ <route> - <from uri="activemq:SomeQueue"/> - <bean ref="foo"/> - <bean ref="bar"/> - <to uri="activemq:OutputQueue"/> + <from uri="activemq:SomeQueue"/> + <bean ref="foo"/> + <bean ref="bar"/> + <to uri="activemq:OutputQueue"/> </route> -</pre> +]]></script> </div></div> <p>Its just a bit more explicit. However if you wish to use <multicast/> to avoid a pipeline - to send the same message into multiple pipelines - then the <pipeline/> element comes into its own.</p> <div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl"> -<pre class="brush: java; gutter: false; theme: Default" style="font-size:12px;"> +<script class="brush: java; gutter: false; theme: Default" type="syntaxhighlighter"><![CDATA[ <route> - <from uri="activemq:SomeQueue"/> + <from uri="activemq:SomeQueue"/> <multicast> <pipeline> - <bean ref="something"/> - <to uri="log:Something"/> + <bean ref="something"/> + <to uri="log:Something"/> </pipeline> <pipeline> - <bean ref="foo"/> - <bean ref="bar"/> - <to uri="activemq:OutputQueue"/> + <bean ref="foo"/> + <bean ref="bar"/> + <to uri="activemq:OutputQueue"/> </pipeline> </multicast> </route> -</pre> +]]></script> </div></div> @@ -297,11 +297,11 @@ RouteBuilder builder = new RouteBuilder( <p>You can transform a message using Camel's <a shape="rect" href="bean-integration.html">Bean Integration</a> to call any method on a bean in your <a shape="rect" href="registry.html">Registry</a> such as your <a shape="rect" href="spring.html">Spring</a> XML configuration file as follows</p> <div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl"> -<pre class="brush: java; gutter: false; theme: Default" style="font-size:12px;"> -from("activemq:SomeQueue"). - beanRef("myTransformerBean", "myMethodName"). - to("mqseries:AnotherQueue"); -</pre> +<script class="brush: java; gutter: false; theme: Default" type="syntaxhighlighter"><![CDATA[ +from("activemq:SomeQueue"). + beanRef("myTransformerBean", "myMethodName"). + to("mqseries:AnotherQueue"); +]]></script> </div></div> <p>Where the "myTransformerBean" would be defined in a Spring XML file or defined in JNDI etc. You can omit the method name parameter from beanRef() and the <a shape="rect" href="bean-integration.html">Bean Integration</a> will try to deduce the method to invoke from the message exchange.</p> @@ -345,32 +345,32 @@ from("direct:start").transform <p>Or you can use the <a shape="rect" href="bean-integration.html">Bean Integration</a> to invoke a bean</p> <div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl"> -<pre class="brush: java; gutter: false; theme: Default" style="font-size:12px;"> +<script class="brush: java; gutter: false; theme: Default" type="syntaxhighlighter"><![CDATA[ <route> - <from uri="activemq:Input"/> - <bean ref="myBeanName" method="doTransform"/> - <to uri="activemq:Output"/> + <from uri="activemq:Input"/> + <bean ref="myBeanName" method="doTransform"/> + <to uri="activemq:Output"/> </route> -</pre> +]]></script> </div></div> <p>You can also use <a shape="rect" href="templating.html">Templating</a> to consume a message from one destination, transform it with something like <a shape="rect" href="velocity.html">Velocity</a> or <a shape="rect" href="xquery.html">XQuery</a> and then send it on to another destination. For example using InOnly (one way messaging)</p> <div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl"> -<pre class="brush: java; gutter: false; theme: Default" style="font-size:12px;"> -from("activemq:My.Queue"). - to("velocity:com/acme/MyResponse.vm"). - to("activemq:Another.Queue"); -</pre> +<script class="brush: java; gutter: false; theme: Default" type="syntaxhighlighter"><![CDATA[ +from("activemq:My.Queue"). + to("velocity:com/acme/MyResponse.vm"). + to("activemq:Another.Queue"); +]]></script> </div></div> <p>If you want to use InOut (request-reply) semantics to process requests on the <strong>My.Queue</strong> queue on <a shape="rect" href="activemq.html">ActiveMQ</a> with a template generated response, then sending responses back to the JMSReplyTo Destination you could use this.</p> <div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl"> -<pre class="brush: java; gutter: false; theme: Default" style="font-size:12px;"> -from("activemq:My.Queue"). - to("velocity:com/acme/MyResponse.vm"); -</pre> +<script class="brush: java; gutter: false; theme: Default" type="syntaxhighlighter"><![CDATA[ +from("activemq:My.Queue"). + to("velocity:com/acme/MyResponse.vm"); +]]></script> </div></div> @@ -378,27 +378,27 @@ from("activemq:My.Queue"). <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> <ul class="alternate"><li><a shape="rect" href="content-enricher.html">Content Enricher</a></li><li><a shape="rect" href="using-getin-or-getout-methods-on-exchange.html">Using getIn or getOut methods on Exchange</a></li></ul> -<h3 id="BookPatternAppendix-MessageEndpoint">Message Endpoint</h3><p>Camel supports the <a shape="rect" class="external-link" href="http://www.enterpriseintegrationpatterns.com/MessageEndpoint.html" rel="nofollow">Message Endpoint</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/Endpoint.html">Endpoint</a> interface.</p><p><span class="confluence-embedded-file-wrapper"><img class="confluence-embedded-image confluence-external-resource" src="http://www.enterpriseintegrationpatterns.com/img/MessageEndpointSolution.gif" data-image-src="http://www.enterpriseintegrationpatterns.com/img/MessageEndpointSolution.gif"></span></p><p>When using the <a shape="rect" href="dsl.html">DSL</a> to create <a shape="rect" href="routes.html">Routes</a> you typically refer to Message Endpoints by their <a shape="rect" href="uris.html">URI s</a> rather than directly using the <a shape="rect" class="external-link" href="http://camel.apache.org/maven/current/camel-core/apidocs/org/apache/camel/Endpoint.html">Endpoint</a> interface. Its then a responsibility of the <a shape="rect" class="external-link" href="http://camel.apache.org/maven/current/camel-core/apidocs/org/apache/camel/CamelContext.html">CamelContext</a> to create and activate the necessary Endpoint instances using the available <a shape="rect" class="external-link" href="http://camel.apache.org/maven/current/camel-core/apidocs/org/apache/camel/Component.html">Component</a> implementations.</p><h4 id="BookPatternAppendix-Example">Example</h4><p>The following example route demonstrates the use of a <a shape="rect" href="https://cwiki.apache.org/confluence/pages/viewpage.action?pageId=38922">File</a> Consumer Endpoint and <a shape="rect" href="jms.html">JMS</a> Producer Endpoint</p><p><strong><br clear="none"></strong></p><p><strong>Using the <a shape="rec t" href="fluent-builders.html">Fluent Builders</a></strong></p><div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl"> -<pre class="brush: java; gutter: false; theme: Default" style="font-size:12px;">from("file://local/router/messages/foo") - .to("jms:queue:foo");</pre> +<h3 id="BookPatternAppendix-MessageEndpoint">Message Endpoint</h3><p>Camel supports the <a shape="rect" class="external-link" href="http://www.enterpriseintegrationpatterns.com/MessageEndpoint.html" rel="nofollow">Message Endpoint</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/Endpoint.html">Endpoint</a> interface.</p><p><span class="confluence-embedded-file-wrapper"><img class="confluence-embedded-image confluence-external-resource" src="http://www.enterpriseintegrationpatterns.com/img/MessageEndpointSolution.gif" data-image-src="http://www.enterpriseintegrationpatterns.com/img/MessageEndpointSolution.gif"></span></p><p>When using the <a shape="rect" href="dsl.html">DSL</a> to create <a shape="rect" href="routes.html">Routes</a> you typically refer to Message Endpoints by their <a shape="rect" href="uris.html">URI s</a> rather than directly using the <a shape="rect" class="external-link" href="http://camel.apache.org/maven/current/camel-core/apidocs/org/apache/camel/Endpoint.html">Endpoint</a> interface. Its then a responsibility of the <a shape="rect" class="external-link" href="http://camel.apache.org/maven/current/camel-core/apidocs/org/apache/camel/CamelContext.html">CamelContext</a> to create and activate the necessary Endpoint instances using the available <a shape="rect" class="external-link" href="http://camel.apache.org/maven/current/camel-core/apidocs/org/apache/camel/Component.html">Component</a> implementations.</p><h4 id="BookPatternAppendix-Example">Example</h4><p>The following example route demonstrates the use of a <a shape="rect" href="https://cwiki.apache.org/confluence/display/SM/File">File</a> Consumer Endpoint and <a shape="rect" href="jms.html">JMS</a> Producer Endpoint</p><p><strong><br clear="none"></strong></p><p><strong>Using the <a shape="rect" href="fluent-bui lders.html">Fluent Builders</a></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("file://local/router/messages/foo") + .to("jms:queue:foo");]]></script> </div></div><p> </p><p><strong><strong>Using the <a shape="rect" href="spring-xml-extensions.html">Spring XML Extensions</a></strong></strong></p><div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl"> -<pre class="brush: xml; gutter: false; theme: Default" style="font-size:12px;"><route> - <from uri="file://local/router/messages/foo"/> - <to uri="jms:queue:foo"/> -</route></pre> +<script class="brush: xml; gutter: false; theme: Default" type="syntaxhighlighter"><![CDATA[<route> + <from uri="file://local/router/messages/foo"/> + <to uri="jms:queue:foo"/> +</route>]]></script> </div></div><p> </p><p>For more details see</p><ul><li><a shape="rect" href="message.html">Message</a><br clear="none"><br clear="none"></li></ul><p></p><h4 id="BookPatternAppendix-UsingThisPattern.5">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> <h2 id="BookPatternAppendix-MessagingChannels">Messaging Channels</h2> <h3 id="BookPatternAppendix-PointtoPointChannel">Point to Point Channel</h3><p>Camel supports the <a shape="rect" class="external-link" href="http://www.enterpriseintegrationpatterns.com/PointToPointChannel.html" rel="nofollow">Point to Point Channel</a> from the <a shape="rect" href="enterprise-integration-patterns.html">EIP patterns</a> using the following components</p><ul><li><a shape="rect" href="seda.html">SEDA</a> for in-VM seda based messaging</li><li><a shape="rect" href="jms.html">JMS</a> for working with JMS Queues for high performance, clustering and load balancing</li><li><a shape="rect" href="jpa.html">JPA</a> for using a database as a simple message queue</li><li><a shape="rect" href="xmpp.html">XMPP</a> for point-to-point communication over XMPP (Jabber)</li><li>and others</li></ul><p><span class="confluence-embedded-file-wrapper"><img class="confluence-embedded-image confluence-external-resource" src="http://www.enterpriseintegrationpatterns.com/img/PointToPointSolu tion.gif" data-image-src="http://www.enterpriseintegrationpatterns.com/img/PointToPointSolution.gif"></span></p><p>The following example demonstrates point to point messaging using the <a shape="rect" href="jms.html">JMS</a> component </p><p><strong>Using the <a shape="rect" href="fluent-builders.html">Fluent Builders</a></strong></p><div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl"> -<pre class="brush: java; gutter: false; theme: Default" style="font-size:12px;">from("direct:start") - .to("jms:queue:foo");</pre> +<script class="brush: java; gutter: false; theme: Default" type="syntaxhighlighter"><![CDATA[from("direct:start") + .to("jms:queue:foo");]]></script> </div></div><p> </p><p><strong><strong>Using the <a shape="rect" href="spring-xml-extensions.html">Spring XML Extensions</a></strong></strong></p><div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl"> -<pre class="brush: xml; gutter: false; theme: Default" style="font-size:12px;"><route> - <from uri="direct:start"/> - <to uri="jms:queue:foo"/> -</route></pre> +<script class="brush: xml; gutter: false; theme: Default" type="syntaxhighlighter"><![CDATA[<route> + <from uri="direct:start"/> + <to uri="jms:queue:foo"/> +</route>]]></script> </div></div><p> </p><p> </p><p></p><h4 id="BookPatternAppendix-UsingThisPattern.6">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> @@ -449,66 +449,66 @@ RouteBuilder builder = new RouteBuilder( <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> <h2 id="BookPatternAppendix-DeadLetterChannel">Dead Letter Channel</h2><p>Camel supports the <a shape="rect" class="external-link" href="http://www.enterpriseintegrationpatterns.com/DeadLetterChannel.html" rel="nofollow">Dead Letter Channel</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/processor/DeadLetterChannel.html">DeadLetterChannel</a> processor which is an <a shape="rect" href="error-handler.html">Error Handler</a>.</p><p><span class="confluence-embedded-file-wrapper"><img class="confluence-embedded-image confluence-external-resource" src="http://www.enterpriseintegrationpatterns.com/img/DeadLetterChannelSolution.gif" data-image-src="http://www.enterpriseintegrationpatterns.com/img/DeadLetterChannelSolution.gif"></span></p><div class="confluence-information-macro confluence-information-macro-tip"><p class="t itle">Difference between Dead Letter Channel and Default Error Handler</p><span class="aui-icon aui-icon-small aui-iconfont-approve confluence-information-macro-icon"></span><div class="confluence-information-macro-body"><p>The Default Error Handler does very little: it ends the Exchange immediately and propagates the thrown Exception back to the caller.</p><p>The Dead Letter Channel lets you control behaviors including redelivery, whether to propagate the thrown Exception to the caller (the <strong>handled</strong> option), and where the (failed) Exchange should now be routed to.</p><p>The Dead Letter Channel is also by default configured to not be verbose in the logs, so when a message is handled and moved to the dead letter endpoint, then there is nothing logged. If you want some level of logging you can use the various options on the redelivery policy / dead letter channel to configure this. For example if you want the message history then set logExhaustedMessageHistory=true (an d logHandled=true for Camel 2.15.x or older).</p><p>When the DeadLetterChannel moves a message to the dead letter endpoint, any new Exception thrown is by default handled by the dead letter channel as well. This ensures that the DeadLetterChannel will always succeed. From <strong>Camel 2.15</strong> onwards this behavior can be changed by setting the option deadLetterHandleNewException=false. Then if a new Exception is thrown, then the dead letter channel will fail and propagate back that new Exception (which is the behavior of the default error handler). When a new Exception occurs then the dead letter channel logs this at WARN level. This can be turned off by setting logNewException=false.</p></div></div><h3 id="BookPatternAppendix-Redelivery">Redelivery</h3><p>It is common for a temporary outage or database deadlock to cause a message to fail to process; but the chances are if its tried a few more times with some time delay then it will complete fine. So we typically wish to use some kind of redelivery policy to decide how many times to try redeliver a message and how long to wait before redelivery attempts.</p><p>The <a shape="rect" class="external-link" href="http://camel.apache.org/maven/current/camel-core/apidocs/org/apache/camel/processor/RedeliveryPolicy.html">RedeliveryPolicy</a> defines how the message is to be redelivered. You can customize things like</p><ul><li>how many times a message is attempted to be redelivered before it is considered a failure and sent to the dead letter channel</li><li>the initial redelivery timeout</li><li>whether or not exponential backoff is used (i.e. the time between retries increases using a backoff multiplier)</li><li>whether to use collision avoidance to add some randomness to the timings</li><li>delay pattern (see below for details)</li><li><strong>Camel 2.11:</strong> whether to allow redelivery during stopping/shutdown</li></ul><p>Once all attempts at redelivering the message fails then the message is forwarded to the dead letter queue.</p><h3 id="BookPatternAppendix-AboutmovingExchangetodeadletterqueueandusinghandled">About moving Exchange to dead letter queue and using handled</h3><p><strong>Handled</strong> on <a shape="rect" href="dead-letter-channel.html">Dead Letter Channel</a></p><p>When all attempts of redelivery have failed the <a shape="rect" href="exchange.html">Exchange</a> is moved to the dead letter queue (the dead letter endpoint). The exchange is then complete and from the client point of view it was processed. As such the <a shape="rect" href="dead-letter-channel.html">Dead Letter Channel</a> have handled the <a shape="rect" href="exchange.html">Exchange</a>.</p><p>For instance configuring the dead letter channel as:</p><p><strong>Using the <a shape="rect" href="fluent-builders.html">Fluent Builders</a></strong></p><div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl"> -<pre class="brush: java; gutter: false; theme: Default" style="font-size:12px;">errorHandler(deadLetterChannel("jms:queue:dead") +<script class="brush: java; gutter: false; theme: Default" type="syntaxhighlighter"><![CDATA[errorHandler(deadLetterChannel("jms:queue:dead") .maximumRedeliveries(3).redeliveryDelay(5000)); -</pre> +]]></script> </div></div><p><strong>Using the <a shape="rect" href="spring-xml-extensions.html">Spring XML Extensions</a></strong></p><div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl"> -<pre class="brush: xml; gutter: false; theme: Default" style="font-size:12px;"><route errorHandlerRef="myDeadLetterErrorHandler"> +<script class="brush: xml; gutter: false; theme: Default" type="syntaxhighlighter"><![CDATA[<route errorHandlerRef="myDeadLetterErrorHandler"> ... </route> -<bean id="myDeadLetterErrorHandler" class="org.apache.camel.builder.DeadLetterChannelBuilder"> - <property name="deadLetterUri" value="jms:queue:dead"/> - <property name="redeliveryPolicy" ref="myRedeliveryPolicyConfig"/> +<bean id="myDeadLetterErrorHandler" class="org.apache.camel.builder.DeadLetterChannelBuilder"> + <property name="deadLetterUri" value="jms:queue:dead"/> + <property name="redeliveryPolicy" ref="myRedeliveryPolicyConfig"/> </bean> -<bean id="myRedeliveryPolicyConfig" class="org.apache.camel.processor.RedeliveryPolicy"> - <property name="maximumRedeliveries" value="3"/> - <property name="redeliveryDelay" value="5000"/> +<bean id="myRedeliveryPolicyConfig" class="org.apache.camel.processor.RedeliveryPolicy"> + <property name="maximumRedeliveries" value="3"/> + <property name="redeliveryDelay" value="5000"/> </bean> -</pre> +]]></script> </div></div><p>The <a shape="rect" href="dead-letter-channel.html">Dead Letter Channel</a> above will clear the caused exception (<code>setException(null)</code>), by moving the caused exception to a property on the <a shape="rect" href="exchange.html">Exchange</a>, with the key <code>Exchange.EXCEPTION_CAUGHT</code>. Then the <a shape="rect" href="exchange.html">Exchange</a> is moved to the <code>"jms:queue:dead"</code> destination and the client will not notice the failure.</p><h3 id="BookPatternAppendix-AboutmovingExchangetodeadletterqueueandusingtheoriginalmessage">About moving Exchange to dead letter queue and using the original message</h3><p>The option <strong>useOriginalMessage</strong> is used for routing the original input message instead of the current message that potentially is modified during routing.</p><p>For instance if you have this route:</p><div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl"> -<pre class="brush: java; gutter: false; theme: Default" style="font-size:12px;"> from("jms:queue:order:input") - .to("bean:validateOrder") - .to("bean:transformOrder") - .to("bean:handleOrder"); -</pre> +<script class="brush: java; gutter: false; theme: Default" type="syntaxhighlighter"><![CDATA[ from("jms:queue:order:input") + .to("bean:validateOrder") + .to("bean:transformOrder") + .to("bean:handleOrder"); +]]></script> </div></div><p>The route listen for JMS messages and validates, transforms and handle it. During this the <a shape="rect" href="exchange.html">Exchange</a> payload is transformed/modified. So in case something goes wrong and we want to move the message to another JMS destination, then we can configure our <a shape="rect" href="dead-letter-channel.html">Dead Letter Channel</a> with the <strong>useOriginalMessage</strong> option. But when we move the <a shape="rect" href="exchange.html">Exchange</a> to this destination we do not know in which state the message is in. Did the error happen in before the transformOrder or after? So to be sure we want to move the original input message we received from <code>jms:queue:order:input</code>. So we can do this by enabling the <strong>useOriginalMessage</strong> option as shown below:</p><div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl"> -<pre class="brush: java; gutter: false; theme: Default" style="font-size:12px;"> // will use original body - errorHandler(deadLetterChannel("jms:queue:dead") +<script class="brush: java; gutter: false; theme: Default" type="syntaxhighlighter"><![CDATA[ // will use original body + errorHandler(deadLetterChannel("jms:queue:dead") .useOriginalMessage().maximumRedeliveries(5).redeliverDelay(5000); -</pre> +]]></script> </div></div><p>Then the messages routed to the <code>jms:queue:dead</code> is the original input. If we want to manually retry we can move the JMS message from the failed to the input queue, with no problem as the message is the same as the original we received.</p><h3 id="BookPatternAppendix-OnRedelivery">OnRedelivery</h3><p>When <a shape="rect" href="dead-letter-channel.html">Dead Letter Channel</a> is doing redeliver its possible to configure a <a shape="rect" href="processor.html">Processor</a> that is executed just <strong>before</strong> every redelivery attempt. This can be used for the situations where you need to alter the message before its redelivered. See below for sample.</p><div class="confluence-information-macro confluence-information-macro-tip"><p class="title">onException and onRedeliver</p><span class="aui-icon aui-icon-small aui-iconfont-approve confluence-information-macro-icon"></span><div class="confluence-information-macro-body"><p>We also support for per <a shape="rect" href="exception-clause.html"><strong>onException</strong></a> to set a <strong>onRedeliver</strong>. That means you can do special on redelivery for different exceptions, as opposed to onRedelivery set on <a shape="rect" href="dead-letter-channel.html">Dead Letter Channel</a> can be viewed as a global scope.</p></div></div><h3 id="BookPatternAppendix-Redeliverydefaultvalues">Redelivery default values</h3><p>Redelivery is disabled by default.</p><p>The default redeliver policy will use the following values:</p><ul><li>maximumRedeliveries=0</li><li>redeliverDelay=1000L (1 second)</li><li>maximumRedeliveryDelay = 60 * 1000L (60 seconds)</li><li>And the exponential backoff and collision avoidance is turned off.</li><li>The retriesExhaustedLogLevel are set to LoggingLevel.ERROR</li><li>The retryAttemptedLogLevel are set to LoggingLevel.DEBUG</li><li>Stack traces is logged for exhausted messages from Camel 2.2 onwards.</li><li>Handled exceptions is not logged from Camel 2.3 o nwards</li><li>logExhaustedMessageHistory is true for default error handler, and false for dead letter channel.</li></ul><p>The maximum redeliver delay ensures that a delay is never longer than the value, default 1 minute. This can happen if you turn on the exponential backoff.</p><p>The maximum redeliveries is the number of <strong>re</strong> delivery attempts. By default Camel will try to process the exchange 1 + 5 times. 1 time for the normal attempt and then 5 attempts as redeliveries.<br clear="none"> Setting the maximumRedeliveries to a negative value such as -1 will then always redelivery (unlimited).<br clear="none"> Setting the maximumRedeliveries to 0 will disable any re delivery attempt.</p><p>Camel will log delivery failures at the DEBUG logging level by default. You can change this by specifying retriesExhaustedLogLevel and/or retryAttemptedLogLevel. See <a shape="rect" class="external-link" href="http://svn.apache.org/repos/asf/camel/trunk/camel-core/src/test/java/org /apache/camel/builder/ExceptionBuilderWithRetryLoggingLevelSetTest.java">ExceptionBuilderWithRetryLoggingLevelSetTest</a> for an example.</p><p>You can turn logging of stack traces on/off. If turned off Camel will still log the redelivery attempt. Its just much less verbose.</p><h4 id="BookPatternAppendix-RedeliverDelayPattern">Redeliver Delay Pattern</h4><p>Delay pattern is used as a single option to set a range pattern for delays. If used then the following options does not apply: (delay, backOffMultiplier, useExponentialBackOff, useCollisionAvoidance, maximumRedeliveryDelay).</p><p>The idea is to set groups of ranges using the following syntax: <code>limit:delay;limit 2:delay 2;limit 3:delay 3;...;limit N:delay N</code></p><p>Each group has two values separated with colon</p><ul class="alternate"><li>limit = upper limit</li><li>delay = delay in millis<br clear="none"> And the groups is again separated with semi colon.<br clear="none"> The rule of thumb is that the next groups sho uld have a higher limit than the previous group.</li></ul><p>Lets clarify this with an example:<br clear="none"> <code>delayPattern=5:1000;10:5000;20:20000</code></p><p>That gives us 3 groups:</p><ul class="alternate"><li>5:1000</li><li>10:5000</li><li>20:20000</li></ul><p>Resulting in these delays for redelivery attempt:</p><ul class="alternate"><li>Redelivery attempt number 1..4 = 0 millis (as the first group start with 5)</li><li>Redelivery attempt number 5..9 = 1000 millis (the first group)</li><li>Redelivery attempt number 10..19 = 5000 millis (the second group)</li><li>Redelivery attempt number 20.. = 20000 millis (the last group)</li></ul><p>Note: The first redelivery attempt is 1, so the first group should start with 1 or higher.</p><p>You can start a group with limit 1 to eg have a starting delay: <code>delayPattern=1:1000;5:5000</code></p><ul class="alternate"><li>Redelivery attempt number 1..4 = 1000 millis (the first group)</li><li>Redelivery attempt number 5.. = 5000 mi llis (the last group)</li></ul><p>There is no requirement that the next delay should be higher than the previous. You can use any delay value you like. For example with <code>delayPattern=1:5000;3:1000</code> we start with 5 sec delay and then later reduce that to 1 second.</p><h3 id="BookPatternAppendix-Redeliveryheader">Redelivery header</h3><p>When a message is redelivered the <a shape="rect" class="external-link" href="http://camel.apache.org/maven/camel-core/apidocs/org/apache/camel/processor/DeadLetterChannel.html">DeadLetterChannel</a> will append a customizable header to the message to indicate how many times its been redelivered. <br clear="none"> Before Camel 2.6: The header is <strong>CamelRedeliveryCounter</strong>, which is also defined on the <code>Exchange.REDELIVERY_COUNTER</code>.<br clear="none"> Starting with 2.6: The header <strong>CamelRedeliveryMaxCounter</strong>, which is also defined on the <code>Exchange.REDELIVERY_MAX_COUNTER</code>, contains the maximum r edelivery setting. This header is absent if you use <code>retryWhile</code> or have unlimited maximum redelivery configured.</p><p>And a boolean flag whether it is being redelivered or not (first attempt)<br clear="none"> The header <strong>CamelRedelivered</strong> contains a boolean if the message is redelivered or not, which is also defined on the <code>Exchange.REDELIVERED</code>.</p><p>Dynamically calculated delay from the exchange<br clear="none"> In Camel 2.9 and 2.8.2: The header is <strong>CamelRedeliveryDelay</strong>, which is also defined on the <code>Exchange.REDELIVERY_DELAY</code>.<br clear="none"> Is this header is absent, normal redelivery rules apply.</p><h4 id="BookPatternAppendix-Whichendpointfailed">Which endpoint failed</h4><p><strong>Available as of Camel 2.1</strong></p><p>When Camel routes messages it will decorate the <a shape="rect" href="exchange.html">Exchange</a> with a property that contains the <strong>last</strong> endpoint Camel send the <a shape="r ect" href="exchange.html">Exchange</a> to:</p><div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl"> -<pre class="brush: java; gutter: false; theme: Default" style="font-size:12px;">String lastEndpointUri = exchange.getProperty(Exchange.TO_ENDPOINT, String.class); -</pre> +<script class="brush: java; gutter: false; theme: Default" type="syntaxhighlighter"><![CDATA[String lastEndpointUri = exchange.getProperty(Exchange.TO_ENDPOINT, String.class); +]]></script> </div></div><p>The <code>Exchange.TO_ENDPOINT</code> have the constant value <code>CamelToEndpoint</code>.</p><p>This information is updated when Camel sends a message to any endpoint. So if it exists its the <strong>last</strong> endpoint which Camel send the Exchange to.</p><p>When for example processing the <a shape="rect" href="exchange.html">Exchange</a> at a given <a shape="rect" href="endpoint.html">Endpoint</a> and the message is to be moved into the dead letter queue, then Camel also decorates the Exchange with another property that contains that <strong>last</strong> endpoint:</p><div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl"> -<pre class="brush: java; gutter: false; theme: Default" style="font-size:12px;">String failedEndpointUri = exchange.getProperty(Exchange.FAILURE_ENDPOINT, String.class); -</pre> +<script class="brush: java; gutter: false; theme: Default" type="syntaxhighlighter"><![CDATA[String failedEndpointUri = exchange.getProperty(Exchange.FAILURE_ENDPOINT, String.class); +]]></script> </div></div><p>The <code>Exchange.FAILURE_ENDPOINT</code> have the constant value <code>CamelFailureEndpoint</code>.</p><p>This allows for example you to fetch this information in your dead letter queue and use that for error reporting.<br clear="none"> This is useable if the Camel route is a bit dynamic such as the dynamic <a shape="rect" href="recipient-list.html">Recipient List</a> so you know which endpoints failed.</p><p><strong>Notice:</strong> These information is kept on the Exchange even if the message was successfully processed by a given endpoint, and then later fails for example in a local <a shape="rect" href="bean.html">Bean</a> processing instead. So beware that this is a hint that helps pinpoint errors.</p><div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl"> -<pre class="brush: java; gutter: false; theme: Default" style="font-size:12px;">from("activemq:queue:foo") - .to("http://someserver/somepath") - .beanRef("foo"); -</pre> +<script class="brush: java; gutter: false; theme: Default" type="syntaxhighlighter"><![CDATA[from("activemq:queue:foo") + .to("http://someserver/somepath") + .beanRef("foo"); +]]></script> </div></div><p>Now suppose the route above and a failure happens in the <code>foo</code> bean. Then the <code>Exchange.TO_ENDPOINT</code> and <code>Exchange.FAILURE_ENDPOINT</code> will still contain the value of <code><a shape="rect" class="external-link" href="http://someserver/somepath" rel="nofollow">http://someserver/somepath</a></code>.</p><h3 id="BookPatternAppendix-OnPrepareFailure">OnPrepareFailure</h3><p><strong>Available as of Camel 2.16</strong></p><p>Before the exchange is sent to the dead letter queue, you can use onPrepare to allow a custom <code>Processor</code> to prepare the exchange, such as adding information why the Exchange failed. For example the following processor adds a header with the exception message</p><div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl"> -<pre class="brush: java; gutter: false; theme: Default" style="font-size:12px;"> public static class MyPrepareProcessor implements Processor { +<script class="brush: java; gutter: false; theme: Default" type="syntaxhighlighter"><![CDATA[ public static class MyPrepareProcessor implements Processor { @Override public void process(Exchange exchange) throws Exception { Exception cause = exchange.getProperty(Exchange.EXCEPTION_CAUGHT, Exception.class); - exchange.getIn().setHeader("FailedBecause", cause.getMessage()); + exchange.getIn().setHeader("FailedBecause", cause.getMessage()); } - }</pre> + }]]></script> </div></div><p>Then configure the error handler to use the processor as follows:</p><div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl"> -<pre class="brush: java; gutter: false; theme: Default" style="font-size:12px;">errorHandler(deadLetterChannel("jms:dead").onPrepareFailure(new MyPrepareProcessor()));</pre> +<script class="brush: java; gutter: false; theme: Default" type="syntaxhighlighter"><![CDATA[errorHandler(deadLetterChannel("jms:dead").onPrepareFailure(new MyPrepareProcessor()));]]></script> </div></div><p> </p><p>Configuring this from XML DSL is as shown:</p><div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl"> -<pre class="brush: java; gutter: false; theme: Default" style="font-size:12px;"> <bean id="myPrepare" - class="org.apache.camel.processor.DeadLetterChannelOnPrepareTest.MyPrepareProcessor"/> +<script class="brush: java; gutter: false; theme: Default" type="syntaxhighlighter"><![CDATA[ <bean id="myPrepare" + class="org.apache.camel.processor.DeadLetterChannelOnPrepareTest.MyPrepareProcessor"/> - <errorHandler id="dlc" type="DeadLetterChannel" deadLetterUri="jms:dead" onPrepareFailureRef="myPrepare"/></pre> + <errorHandler id="dlc" type="DeadLetterChannel" deadLetterUri="jms:dead" onPrepareFailureRef="myPrepare"/>]]></script> </div></div><p> </p><p>The onPrepare is also available using the default error handler.</p><h3 id="BookPatternAppendix-Whichroutefailed">Which route failed</h3><p><strong>Available as of Camel 2.10.4/2.11</strong></p><p>When Camel error handler handles an error such as <a shape="rect" href="dead-letter-channel.html">Dead Letter Channel</a> or using <a shape="rect" href="exception-clause.html">Exception Clause</a> with handled=true, then Camel will decorate<br clear="none"> the <a shape="rect" href="exchange.html">Exchange</a> with the route id where the error occurred.</p><div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl"> -<pre class="brush: java; gutter: false; theme: Default" style="font-size:12px;">String failedRouteId = exchange.getProperty(Exchange.FAILURE_ROUTE_ID, String.class); -</pre> +<script class="brush: java; gutter: false; theme: Default" type="syntaxhighlighter"><![CDATA[String failedRouteId = exchange.getProperty(Exchange.FAILURE_ROUTE_ID, String.class); +]]></script> </div></div><p>The <code>Exchange.FAILURE_ROUTE_ID</code> have the constant value <code>CamelFailureRouteId</code>.</p><p>This allows for example you to fetch this information in your dead letter queue and use that for error reporting.</p><h3 id="BookPatternAppendix-Controlifredeliveryisallowedduringstopping/shutdown">Control if redelivery is allowed during stopping/shutdown</h3><p><strong>Available as of Camel 2.11</strong></p><p>Prior to Camel 2.10, Camel will perform redelivery while stopping a route, or shutting down Camel. This has improved a bit in Camel 2.10 onwards, as Camel will not perform redelivery attempts when shutting down aggressively (eg during <a shape="rect" href="graceful-shutdown.html">Graceful Shutdown</a> and timeout hit). From Camel 2.11 onwards there is a new option <code>allowRedeliveryWhileStopping</code> which you can use to control if redelivery is allowed or not; notice that any in progress redelivery will still be executed. This option can only disallo w any redelivery to be executed <strong>after</strong> the stopping of a route/shutdown of Camel has been triggered. If a redelivery is dissallowed then a <code>RejectedExcutionException</code> is set on the <a shape="rect" href="exchange.html">Exchange</a> and the processing of the <a shape="rect" href="exchange.html">Exchange</a> stops. This means any consumer will see the <a shape="rect" href="exchange.html">Exchange</a> as failed due the <code>RejectedExecutionException</code>.</p><p>The default value is <code>true</code> to be backwards compatible as before. For example the following sample shows how to do this with Java DSL and XML DSL</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[ @@ -602,55 +602,55 @@ public class MyRedeliverProcessor implem <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><ul class="alternate"><li><a shape="rect" href="error-handler.html">Error Handler</a></li><li><a shape="rect" href="exception-clause.html">Exception Clause</a></li></ul> <h3 id="BookPatternAppendix-GuaranteedDelivery">Guaranteed Delivery</h3><p>Camel supports the <a shape="rect" class="external-link" href="http://www.enterpriseintegrationpatterns.com/GuaranteedMessaging.html" rel="nofollow">Guaranteed Delivery</a> from the <a shape="rect" href="enterprise-integration-patterns.html">EIP patterns</a> using among others the following components:</p><ul><li><a shape="rect" href="file2.html">File</a> for using file systems as a persistent store of messages</li><li><a shape="rect" href="jms.html">JMS</a> when using persistent delivery (the default) for working with JMS Queues and Topics for high performance, clustering and load balancing</li><li><a shape="rect" href="jpa.html">JPA</a> for using a database as a persistence layer, or use any of the many other database component such as <a shape="rect" href="sql.html">SQL</a>, <a shape="rect" href="jdbc.html">JDBC</a>, <a shape="rect" href="ibatis.html">iBATIS</a>/<a shape="rect" href="mybatis.html">MyBatis< /a>, <a shape="rect" href="hibernate.html">Hibernate</a></li><li><a shape="rect" href="hawtdb.html">HawtDB</a> for a lightweight key-value persistent store</li></ul><p><span class="confluence-embedded-file-wrapper"><img class="confluence-embedded-image confluence-external-resource" src="http://www.enterpriseintegrationpatterns.com/img/GuaranteedMessagingSolution.gif" data-image-src="http://www.enterpriseintegrationpatterns.com/img/GuaranteedMessagingSolution.gif"></span></p><h4 id="BookPatternAppendix-Example.1">Example</h4><p>The following example demonstrates illustrates the use of <a shape="rect" class="external-link" href="http://www.enterpriseintegrationpatterns.com/GuaranteedMessaging.html" rel="nofollow">Guaranteed Delivery</a> within the <a shape="rect" href="jms.html">JMS</a> component. By default, a message is not considered successfully delivered until the recipient has persisted the message locally guaranteeing its receipt in the event the destination becomes unavailable.</p><p><strong>Using the <a shape="rect" href="fluent-builders.html">Fluent Builders</a></strong></p><div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl"> -<pre class="brush: java; gutter: false; theme: Default" style="font-size:12px;">from("direct:start") - .to("jms:queue:foo");</pre> +<script class="brush: java; gutter: false; theme: Default" type="syntaxhighlighter"><![CDATA[from("direct:start") + .to("jms:queue:foo");]]></script> </div></div><p> </p><p><strong><strong>Using the <a shape="rect" href="spring-xml-extensions.html">Spring XML Extensions</a></strong></strong></p><div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl"> -<pre class="brush: xml; gutter: false; theme: Default" style="font-size:12px;"><route> - <from uri="direct:start"/> - <to uri="jms:queue:foo"/> -</route></pre> +<script class="brush: xml; gutter: false; theme: Default" type="syntaxhighlighter"><![CDATA[<route> + <from uri="direct:start"/> + <to uri="jms:queue:foo"/> +</route>]]></script> </div></div><p></p><h4 id="BookPatternAppendix-UsingThisPattern.9">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-MessageBus">Message Bus</h3><p>Camel supports the <a shape="rect" class="external-link" href="http://www.enterpriseintegrationpatterns.com/PointToPointChannel.html" rel="nofollow">Message Bus</a> from the <a shape="rect" href="enterprise-integration-patterns.html">EIP patterns</a>. You could view Camel as a Message Bus itself as it allows producers and consumers to be decoupled.</p><p><span class="confluence-embedded-file-wrapper"><img class="confluence-embedded-image confluence-external-resource" src="http://www.enterpriseintegrationpatterns.com/img/MessageBusSolution.gif" data-image-src="http://www.enterpriseintegrationpatterns.com/img/MessageBusSolution.gif"></span></p><p>Folks often assume that a Message Bus is a JMS though so you may wish to refer to the <a shape="rect" href="jms.html">JMS</a> component for traditional MOM support.<br clear="none"> Also worthy of note is the <a shape="rect" href="xmpp.html">XMPP</a> component for supporting messaging over XMPP (Jabber)</p><p>Of course there are also ESB products such as <a shape="rect" class="external-link" href="http://servicemix.apache.org/home.html">Apache ServiceMix</a> which serve as full fledged message busses.<br clear="none"> You can interact with <a shape="rect" class="external-link" href="http://servicemix.apache.org/home.html">Apache ServiceMix</a> from Camel in many ways, but in particular you can use the <a shape="rect" href="nmr.html">NMR</a> or <a shape="rect" href="jbi.html">JBI</a> component to access the ServiceMix message bus directly.</p><p> </p><h4 id="BookPatternAppendix-Example.2">Example</h4><p>The following demonstrates how the Camel message bus can be used to communicate with consumers and producers</p><p><strong><br clear="none"></strong></p><p><strong>Using the <a shape="rect" href="fluent-builders.html">Fluent Builders</a></strong></p><div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl"> -<pre class="brush: java; gutter: false; theme: Default" style="font-size:12px;">from("direct:start") - .pollEnrich("file:inbox?fileName=data.txt") - .to("jms:queue:foo");</pre> +<script class="brush: java; gutter: false; theme: Default" type="syntaxhighlighter"><![CDATA[from("direct:start") + .pollEnrich("file:inbox?fileName=data.txt") + .to("jms:queue:foo");]]></script> </div></div><p> </p><p><strong><strong>Using the <a shape="rect" href="spring-xml-extensions.html">Spring XML Extensions</a></strong></strong></p><div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl"> -<pre class="brush: xml; gutter: false; theme: Default" style="font-size:12px;"><route> - <from uri="direct:start"/> - <pollEnrich uri="file:inbox?fileName=data.txt"/> - <to uri="jms:queue:foo"/> -</route></pre> +<script class="brush: xml; gutter: false; theme: Default" type="syntaxhighlighter"><![CDATA[<route> + <from uri="direct:start"/> + <pollEnrich uri="file:inbox?fileName=data.txt"/> + <to uri="jms:queue:foo"/> +</route>]]></script> </div></div><p></p><h4 id="BookPatternAppendix-UsingThisPattern.10">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-MessageConstruction">Message Construction</h3> <h2 id="BookPatternAppendix-EventMessage">Event Message</h2><p>Camel supports the <a shape="rect" class="external-link" href="http://www.enterpriseintegrationpatterns.com/EventMessage.html" rel="nofollow">Event Message</a> from the <a shape="rect" href="enterprise-integration-patterns.html">EIP patterns</a> by supporting the <a shape="rect" href="exchange-pattern.html">Exchange Pattern</a> on a <a shape="rect" href="message.html">Message</a> which can be set to <strong>InOnly</strong> to indicate a oneway event message. Camel <a shape="rect" href="components.html">Components</a> then implement this pattern using the underlying transport or protocols.</p><p><span class="confluence-embedded-file-wrapper"><img class="confluence-embedded-image confluence-external-resource" src="http://www.enterpriseintegrationpatterns.com/img/EventMessageSolution.gif" data-image-src="http://www.enterpriseintegrationpatterns.com/img/EventMessageSolution.gif"></span></p><p>The default behaviour of many <a shape="rect" href="components.html">Components</a> is InOnly such as for <a shape="rect" href="jms.html">JMS</a>, <a shape="rect" href="file2.html">File</a> or <a shape="rect" href="seda.html">SEDA</a></p><div class="confluence-information-macro confluence-information-macro-tip"><p class="title">Related</p><span class="aui-icon aui-icon-small aui-iconfont-approve confluence-information-macro-icon"></span><div class="confluence-information-macro-body"><p>See the related <a shape="rect" href="request-reply.html">Request Reply</a> message.</p></div></div><h3 id="BookPatternAppendix-ExplicitlyspecifyingInOnly">Explicitly specifying InOnly</h3><p>If you are using a component which defaults to InOut you can override the <a shape="rect" href="exchange-pattern.html">Exchange Pattern</a> for an endpoint using the pattern property.</p><div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl"> -<pre class="brush: java; gutter: false; theme: Default" style="font-size:12px;">foo:bar?exchangePattern=InOnly -</pre> +<script class="brush: java; gutter: false; theme: Default" type="syntaxhighlighter"><![CDATA[foo:bar?exchangePattern=InOnly +]]></script> </div></div><p>From 2.0 onwards on Camel you can specify the <a shape="rect" href="exchange-pattern.html">Exchange Pattern</a> using the DSL.</p><p><strong>Using the <a shape="rect" href="fluent-builders.html">Fluent Builders</a></strong></p><div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl"> -<pre class="brush: java; gutter: false; theme: Default" style="font-size:12px;">from("mq:someQueue"). +<script class="brush: java; gutter: false; theme: Default" type="syntaxhighlighter"><![CDATA[from("mq:someQueue"). setExchangePattern(ExchangePattern.InOnly). bean(Foo.class); -</pre> +]]></script> </div></div><p>or you can invoke an endpoint with an explicit pattern</p><div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl"> -<pre class="brush: java; gutter: false; theme: Default" style="font-size:12px;">from("mq:someQueue"). - inOnly("mq:anotherQueue"); -</pre> +<script class="brush: java; gutter: false; theme: Default" type="syntaxhighlighter"><![CDATA[from("mq:someQueue"). + inOnly("mq:anotherQueue"); +]]></script> </div></div><p><strong>Using the <a shape="rect" href="spring-xml-extensions.html">Spring XML Extensions</a></strong></p><div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl"> -<pre class="brush: java; gutter: false; theme: Default" style="font-size:12px;"><route> - <from uri="mq:someQueue"/> - <inOnly uri="bean:foo"/> +<script class="brush: java; gutter: false; theme: Default" type="syntaxhighlighter"><![CDATA[<route> + <from uri="mq:someQueue"/> + <inOnly uri="bean:foo"/> </route> -</pre> +]]></script> </div></div><div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl"> -<pre class="brush: java; gutter: false; theme: Default" style="font-size:12px;"><route> - <from uri="mq:someQueue"/> - <inOnly uri="mq:anotherQueue"/> +<script class="brush: java; gutter: false; theme: Default" type="syntaxhighlighter"><![CDATA[<route> + <from uri="mq:someQueue"/> + <inOnly uri="mq:anotherQueue"/> </route> -</pre> +]]></script> </div></div><p></p><h4 id="BookPatternAppendix-UsingThisPattern.11">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> @@ -675,9 +675,9 @@ public class MyRedeliverProcessor implem <p>You can explicitly force an endpoint to be in Request Reply mode by setting the exchange pattern on the URI. e.g.</p> <div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl"> -<pre class="brush: java; gutter: false; theme: Default" style="font-size:12px;"> +<script class="brush: java; gutter: false; theme: Default" type="syntaxhighlighter"><![CDATA[ jms:MyQueue?exchangePattern=InOut -</pre> +]]></script> </div></div> <p>You can specify the exchange pattern in DSL rule or Spring configuration.</p> @@ -764,15 +764,15 @@ from("direct:testSetExchangePattern <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-CorrelationIdentifier">Correlation Identifier</h3><p>Camel supports the <a shape="rect" class="external-link" href="http://www.enterpriseintegrationpatterns.com/CorrelationIdentifier.html" rel="nofollow">Correlation Identifier</a> from the <a shape="rect" href="enterprise-integration-patterns.html">EIP patterns</a> by getting or setting a header on a <a shape="rect" href="message.html">Message</a>.</p><p>When working with the <a shape="rect" href="activemq.html">ActiveMQ</a> or <a shape="rect" href="jms.html">JMS</a> components the correlation identifier header is called <strong>JMSCorrelationID</strong>. You can add your own correlation identifier to any message exchange to help correlate messages together to a single conversation (or business process).</p><p><span class="confluence-embedded-file-wrapper"><img class="confluence-embedded-image confluence-external-resource" src="http://www.enterpriseintegrationpatterns.com/img/CorrelationIdentifierSolution .gif" data-image-src="http://www.enterpriseintegrationpatterns.com/img/CorrelationIdentifierSolution.gif"></span></p><p>The use of a Correlation Identifier is key to working with the <a shape="rect" href="bam.html">Camel Business Activity Monitoring Framework</a> and can also be highly useful when testing with simulation or canned data such as with the <a shape="rect" href="mock.html">Mock testing framework</a></p><p>Some <a shape="rect" href="eip.html">EIP</a> patterns will spin off a sub message, and in those cases, Camel will add a correlation id on the <a shape="rect" href="exchange.html">Exchange</a> as a property with they key <code>Exchange.CORRELATION_ID</code>, which links back to the source <a shape="rect" href="exchange.html">Exchange</a>. For example the <a shape="rect" href="splitter.html">Splitter</a>, <a shape="rect" href="multicast.html">Multicast</a>, <a shape="rect" href="recipient-list.html">Recipient List</a>, and <a shape="rect" href="wire-tap.html">Wire Tap</a> EIP does this.</p><p>The following example demonstrates using the Camel JMSMessageID as the Correlation Identifier within a request/reply pattern in the <a shape="rect" href="jms.html">JMS</a> component</p><p><strong>Using the <a shape="rect" href="fluent-builders.html">Fluent Builders</a></strong></p><div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl"> -<pre class="brush: java; gutter: false; theme: Default" style="font-size:12px;">from("direct:start") - .to(ExchangePattern.InOut,"jms:queue:foo?useMessageIDAsCorrelationID=true") - .to("mock:result");</pre> +<script class="brush: java; gutter: false; theme: Default" type="syntaxhighlighter"><![CDATA[from("direct:start") + .to(ExchangePattern.InOut,"jms:queue:foo?useMessageIDAsCorrelationID=true") + .to("mock:result");]]></script> </div></div><p> </p><p><strong><strong>Using the <a shape="rect" href="spring-xml-extensions.html">Spring XML Extensions</a></strong></strong></p><div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl"> -<pre class="brush: xml; gutter: false; theme: Default" style="font-size:12px;"><route> - <from uri="direct:start"/> - <to uri="jms:queue:foo?useMessageIDAsCorrelationID=true" pattern="InOut"/> - <to uri="mock:result"/> -</route></pre> +<script class="brush: xml; gutter: false; theme: Default" type="syntaxhighlighter"><![CDATA[<route> + <from uri="direct:start"/> + <to uri="jms:queue:foo?useMessageIDAsCorrelationID=true" pattern="InOut"/> + <to uri="mock:result"/> +</route>]]></script> </div></div><h4 id="BookPatternAppendix-SeeAlso">See Also</h4><ul><li><a shape="rect" href="bam.html">BAM</a></li></ul> <h2 id="BookPatternAppendix-ReturnAddress">Return Address</h2> @@ -784,42 +784,42 @@ from("direct:testSetExchangePattern <p><strong>Requestor Code</strong></p> <div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl"> -<pre class="brush: java; gutter: false; theme: Default" style="font-size:12px;"> -getMockEndpoint("mock:bar").expectedBodiesReceived("Bye World"); -template.sendBodyAndHeader("direct:start", "World", "JMSReplyTo", "queue:bar"); -</pre> +<script class="brush: java; gutter: false; theme: Default" type="syntaxhighlighter"><![CDATA[ +getMockEndpoint("mock:bar").expectedBodiesReceived("Bye World"); +template.sendBodyAndHeader("direct:start", "World", "JMSReplyTo", "queue:bar"); +]]></script> </div></div> <p><strong>Route Using the <a shape="rect" href="fluent-builders.html">Fluent Builders</a></strong></p> <div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl"> -<pre class="brush: java; gutter: false; theme: Default" style="font-size:12px;"> -from("direct:start").to("activemq:queue:foo?preserveMessageQos=true"); -from("activemq:queue:foo").transform(body().prepend("Bye ")); -from("activemq:queue:bar?disableReplyTo=true").to("mock:bar"); -</pre> +<script class="brush: java; gutter: false; theme: Default" type="syntaxhighlighter"><![CDATA[ +from("direct:start").to("activemq:queue:foo?preserveMessageQos=true"); +from("activemq:queue:foo").transform(body().prepend("Bye ")); +from("activemq:queue:bar?disableReplyTo=true").to("mock:bar"); +]]></script> </div></div> <p><strong>Route Using the <a shape="rect" href="spring-xml-extensions.html">Spring XML Extensions</a></strong></p> <div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl"> -<pre class="brush: java; gutter: false; theme: Default" style="font-size:12px;"> +<script class="brush: java; gutter: false; theme: Default" type="syntaxhighlighter"><![CDATA[ <route> - <from uri="direct:start"/> - <to uri="activemq:queue:foo?preserveMessageQos=true"/> + <from uri="direct:start"/> + <to uri="activemq:queue:foo?preserveMessageQos=true"/> </route> <route> - <from uri="activemq:queue:foo"/> + <from uri="activemq:queue:foo"/> <transform> <simple>Bye ${in.body}</simple> </transform> </route> <route> - <from uri="activemq:queue:bar?disableReplyTo=true"/> - <to uri="mock:bar"/> + <from uri="activemq:queue:bar?disableReplyTo=true"/> + <to uri="mock:bar"/> </route> -</pre> +]]></script> </div></div> <p>For a complete example of this pattern, see this <a shape="rect" class="external-link" href="http://svn.apache.org/viewvc/camel/trunk/components/camel-jms/src/test/java/org/apache/camel/component/jms/JmsInOnlyWithReplyToAsHeaderTest.java?view=markup">junit test case</a></p> @@ -830,39 +830,39 @@ from("activemq:queue:bar?disableReplyTo= <h2 id="BookPatternAppendix-MessageRouting">Message Routing</h2> <h3 id="BookPatternAppendix-ContentBasedRouter">Content Based Router</h3><p>The <a shape="rect" class="external-link" href="http://www.enterpriseintegrationpatterns.com/ContentBasedRouter.html" rel="nofollow">Content Based Router</a> from the <a shape="rect" href="enterprise-integration-patterns.html">EIP patterns</a> allows you to route messages to the correct destination based on the contents of the message exchanges.</p><p><span class="confluence-embedded-file-wrapper"><img class="confluence-embedded-image confluence-external-resource" src="http://www.enterpriseintegrationpatterns.com/img/ContentBasedRouter.gif" data-image-src="http://www.enterpriseintegrationpatterns.com/img/ContentBasedRouter.gif"></span></p><p>The following example shows how to route a request from an input <strong>seda:a</strong> endpoint to either <strong>seda:b</strong>, <strong>seda:c</strong> or <strong>seda:d</strong> depending on the evaluation of various <a shape="rect" href="predicate.html">Predicate< /a> expressions</p><p><strong>Using the <a shape="rect" href="fluent-builders.html">Fluent Builders</a></strong></p><p> </p><p><strong><br clear="none"></strong></p><div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl"> -<pre class="brush: java; gutter: false; theme: Default" style="font-size:12px;">RouteBuilder builder = new RouteBuilder() { +<script class="brush: java; gutter: false; theme: Default" type="syntaxhighlighter"><![CDATA[RouteBuilder builder = new RouteBuilder() { public void configure() { - errorHandler(deadLetterChannel("mock:error")); + errorHandler(deadLetterChannel("mock:error")); - from("direct:a") + from("direct:a") .choice() - .when(header("foo").isEqualTo("bar")) - .to("direct:b") - .when(header("foo").isEqualTo("cheese")) - .to("direct:c") + .when(header("foo").isEqualTo("bar")) + .to("direct:b") + .when(header("foo").isEqualTo("cheese")) + .to("direct:c") .otherwise() - .to("direct:d"); + .to("direct:d"); } -};</pre> +};]]></script> </div></div><div class="confluence-information-macro confluence-information-macro-tip"><span class="aui-icon aui-icon-small aui-iconfont-approve confluence-information-macro-icon"></span><div class="confluence-information-macro-body"><p>See <a shape="rect" href="why-can-i-not-use-when-or-otherwise-in-a-java-camel-route.html">Why can I not use when or otherwise in a Java Camel route</a> if you have problems with the Java DSL, accepting using <code>when</code> or <code>otherwise</code>.</p></div></div><p><strong>Using the <a shape="rect" href="spring-xml-extensions.html">Spring XML Extensions</a></strong></p><div class="line number1 index0 alt2"><p> </p><div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl"> -<pre class="brush: xml; gutter: false; theme: Default" style="font-size:12px;"><camelContext errorHandlerRef="errorHandler" xmlns="http://camel.apache.org/schema/spring"> +<script class="brush: xml; gutter: false; theme: Default" type="syntaxhighlighter"><![CDATA[<camelContext errorHandlerRef="errorHandler" xmlns="http://camel.apache.org/schema/spring"> <route> - <from uri="direct:a"/> + <from uri="direct:a"/> <choice> <when> - <xpath>$foo = 'bar'</xpath> - <to uri="direct:b"/> + <xpath>$foo = 'bar'</xpath> + <to uri="direct:b"/> </when> <when> - <xpath>$foo = 'cheese'</xpath> - <to uri="direct:c"/> + <xpath>$foo = 'cheese'</xpath> + <to uri="direct:c"/> </when> <otherwise> - <to uri="direct:d"/> + <to uri="direct:d"/> </otherwise> </choice> </route> -</camelContext></pre> +</camelContext>]]></script> </div></div><p><span style="line-height: 1.4285715;">For further examples of this pattern in use you could look at the </span><a shape="rect" class="external-link" href="http://svn.apache.org/viewvc/camel/trunk/camel-core/src/test/java/org/apache/camel/processor/ChoiceTest.java?view=markup" style="line-height: 1.4285715;">junit test case</a></p></div><p></p><h4 id="BookPatternAppendix-UsingThisPattern.14">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> @@ -885,16 +885,16 @@ from("direct:start"). to("mock:result"); ]]></script> </div></div><p>Here is another example of using a bean to define the filter behavior</p><div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl"> -<pre class="brush: java; gutter: false; theme: Default" style="font-size:12px;">from("direct:start") - .filter().method(MyBean.class, "isGoldCustomer").to("mock:result").end() - .to("mock:end"); +<script class="brush: java; gutter: false; theme: Default" type="syntaxhighlighter"><![CDATA[from("direct:start") + .filter().method(MyBean.class, "isGoldCustomer").to("mock:result").end() + .to("mock:end"); public static class MyBean { - public boolean isGoldCustomer(@Header("level") String level) { - return level.equals("gold"); + public boolean isGoldCustomer(@Header("level") String level) { + return level.equals("gold"); } } -</pre> +]]></script> </div></div><p><strong>Using the <a shape="rect" href="spring-xml-extensions.html">Spring XML Extensions</a></strong></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[ <camelContext errorHandlerRef="errorHandler" xmlns="http://camel.apache.org/schema/spring"> @@ -1013,31 +1013,31 @@ public String slip(String body, @Propert </camelContext> ]]></script> </div></div><h4 id="BookPatternAppendix-@DynamicRouterannotation">@DynamicRouter annotation</h4><p>You can also use the <code>@DynamicRouter</code> annotation, for example the Camel 2.4 example below could be written as follows. The <code>route</code> method would then be invoked repeatedly as the message is processed dynamically. The idea is to return the next endpoint uri where to go. Return <code>null</code> to indicate the end. You can return multiple endpoints if you like, just as the <a shape="rect" href="routing-slip.html">Routing Slip</a>, where each endpoint is separated by a delimiter.</p><div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl"> -<pre class="brush: java; gutter: false; theme: Default" style="font-size:12px;">public class MyDynamicRouter { +<script class="brush: java; gutter: false; theme: Default" type="syntaxhighlighter"><![CDATA[public class MyDynamicRouter { - @Consume(uri = "activemq:foo") + @Consume(uri = "activemq:foo") @DynamicRouter - public String route(@XPath("/customer/id") String customerId, @Header("Location") String location, Document body) { + public String route(@XPath("/customer/id") String customerId, @Header("Location") String location, Document body) { // query a database to find the best match of the endpoint based on the input parameteres // return the next endpoint uri, where to go. Return null to indicate the end. } } -</pre> +]]></script> </div></div><h3 id="BookPatternAppendix-DynamicRouterinCamel2.4orolder">Dynamic Router in Camel 2.4 or older</h3><p>The simplest way to implement this is to use the <a shape="rect" href="recipientlist-annotation.html">RecipientList Annotation</a> on a Bean method to determine where to route the message.</p><div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl"> -<pre class="brush: java; gutter: false; theme: Default" style="font-size:12px;">public class MyDynamicRouter { +<script class="brush: java; gutter: false; theme: Default" type="syntaxhighlighter"><![CDATA[public class MyDynamicRouter { - @Consume(uri = "activemq:foo") + @Consume(uri = "activemq:foo") @RecipientList - public List<String> route(@XPath("/customer/id") String customerId, @Header("Location") String location, Document body) { + public List<String> route(@XPath("/customer/id") String customerId, @Header("Location") String location, Document body) { // query a database to find the best match of the endpoint based on the input parameteres ... } } -</pre> +]]></script> </div></div><p>In the above we can use the <a shape="rect" href="parameter-binding-annotations.html">Parameter Binding Annotations</a> to bind different parts of the <a shape="rect" href="message.html">Message</a> to method parameters or use an <a shape="rect" href="expression.html">Expression</a> such as using <a shape="rect" href="xpath.html">XPath</a> or <a shape="rect" href="xquery.html">XQuery</a>.</p><p>The method can be invoked in a number of ways as described in the <a shape="rect" href="bean-integration.html">Bean Integration</a> such as</p><ul><li><a shape="rect" href="pojo-producing.html">POJO Producing</a></li><li><a shape="rect" href="spring-remoting.html">Spring Remoting</a></li><li><a shape="rect" href="bean.html">Bean</a> component</li></ul><p></p><h4 id="BookPatternAppendix-UsingThisPattern.16">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>
[... 2373 lines stripped ...] Modified: websites/production/camel/content/cache/main.pageCache ============================================================================== Binary files - no diff available.