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 Thu Sep 14 19:25:46 2017 @@ -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"> -<script class="brush: text; gutter: false; theme: Confluence" type="syntaxhighlighter"><![CDATA[jms:queue:foo]]></script> +<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"> -<script class="brush: java; gutter: false; theme: Confluence" type="syntaxhighlighter"><![CDATA[to("jms:queue:foo")]]></script> +<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"> -<script class="brush: xml; gutter: false; theme: Confluence" type="syntaxhighlighter"><![CDATA[<to uri="jms:queue:foo"/>]]></script> +<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,7 +113,7 @@ <p><strong>Requestor Code</strong></p> <div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl"> -<script class="brush: bash; gutter: false; theme: Confluence" type="syntaxhighlighter"><![CDATA[ +<script class="brush: java; gutter: false; theme: Default" type="syntaxhighlighter"><![CDATA[ //InOnly getContext().createProducerTemplate().sendBody("direct:startInOnly", "Hello World"); @@ -125,7 +125,7 @@ String result = (String) getContext().cr <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"> -<script class="brush: bash; gutter: false; theme: Confluence" type="syntaxhighlighter"><![CDATA[ +<script class="brush: java; gutter: false; theme: Default" type="syntaxhighlighter"><![CDATA[ from("direct:startInOnly").inOnly("bean:process"); from("direct:startInOut").inOut("bean:process"); @@ -135,7 +135,7 @@ from("direct:startInOut").inOu <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"> -<script class="brush: bash; gutter: false; theme: Confluence" type="syntaxhighlighter"><![CDATA[ +<script class="brush: java; gutter: false; theme: Default" type="syntaxhighlighter"><![CDATA[ <route> <from uri="direct:startInOnly"/> <inOnly uri="bean:process"/> @@ -190,7 +190,7 @@ from("direct:startInOut").inOu <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"> -<script class="brush: java; gutter: false; theme: Confluence" type="syntaxhighlighter"><![CDATA[ +<script class="brush: java; gutter: false; theme: Default" type="syntaxhighlighter"><![CDATA[ RouteBuilder builder = new RouteBuilder() { public void configure() { errorHandler(deadLetterChannel("mock:error")); @@ -210,7 +210,7 @@ RouteBuilder builder = new RouteBuilder( <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: Confluence" type="syntaxhighlighter"><![CDATA[ +<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"/> @@ -296,44 +296,44 @@ from("activemq:My.Queue"). <parameter ac:name=""><a shape="rect" href="using-this-pattern.html">Using This Pattern</a></parameter> <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/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: Confluence" type="syntaxhighlighter"><![CDATA[from("file://local/router/messages/foo") +<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"> -<script class="brush: xml; gutter: false; theme: Confluence" type="syntaxhighlighter"><![CDATA[<route> +<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><h3 id="BookPatternAppendix-DynamicTo">Dynamic To</h3><p><strong>Available as of Camel 2.16</strong></p><p>There is a new <toD> that allows to send a message to a dynamic computed <a shape="rect" href="endpoint.html">Endpoint</a> using one or more <a shape="rect" href="expression.html">Expression</a> that are concat together. By default the <a shape="rect" href="simple.html">Simple</a> language is used to compute the endpoint. For example to send a message to a endpoint defined by a header you can do</p><div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl"> -<script class="brush: bash; gutter: false; theme: Confluence" type="syntaxhighlighter"><![CDATA[<route> +<script class="brush: java; gutter: false; theme: Default" type="syntaxhighlighter"><![CDATA[<route> <from uri="direct:start"/> <toD uri="${header.foo}"/> </route>]]></script> </div></div><p>And in Java DSL</p><div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl"> -<script class="brush: bash; gutter: false; theme: Confluence" type="syntaxhighlighter"><![CDATA[from("direct:start") +<script class="brush: java; gutter: false; theme: Default" type="syntaxhighlighter"><![CDATA[from("direct:start") .toD("${header.foo}");]]></script> </div></div><p> </p><p>You can also prefix the uri with a value because by default the uri is evaluated using the <a shape="rect" href="simple.html">Simple</a> language</p><div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl"> -<script class="brush: bash; gutter: false; theme: Confluence" type="syntaxhighlighter"><![CDATA[<route> +<script class="brush: java; gutter: false; theme: Default" type="syntaxhighlighter"><![CDATA[<route> <from uri="direct:start"/> <toD uri="mock:${header.foo}"/> </route>]]></script> </div></div><p>And in Java DSL</p><div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl"> -<script class="brush: bash; gutter: false; theme: Confluence" type="syntaxhighlighter"><![CDATA[from("direct:start") +<script class="brush: java; gutter: false; theme: Default" type="syntaxhighlighter"><![CDATA[from("direct:start") .toD("mock:${header.foo}");]]></script> </div></div><p>In the example above we compute an endpoint that has prefix "mock:" and then the header foo is appended. So for example if the header foo has value order, then the endpoint is computed as "mock:order".</p><p>You can also use other languages than <a shape="rect" href="simple.html">Simple</a> such as <a shape="rect" href="xpath.html">XPath</a> - this requires to prefix with language: as shown below (simple language is the default language). If you do not specify language: then the endpoint is a component name. And in some cases there is both a component and language with the same name such as xquery.</p><div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl"> -<script class="brush: bash; gutter: false; theme: Confluence" type="syntaxhighlighter"><![CDATA[<route> +<script class="brush: java; gutter: false; theme: Default" type="syntaxhighlighter"><![CDATA[<route> <from uri="direct:start"/> <toD uri="language:xpath:/order/@uri"/> </route>]]></script> </div></div><p>This is done by specifying the name of the language followed by a colon.</p><div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl"> -<script class="brush: bash; gutter: false; theme: Confluence" type="syntaxhighlighter"><![CDATA[from("direct:start") +<script class="brush: java; gutter: false; theme: Default" type="syntaxhighlighter"><![CDATA[from("direct:start") .toD("language:xpath:/order/@uri");]]></script> </div></div><p>You can also concat multiple <a shape="rect" href="language.html">Language</a>(s) together using the plus sign <code>+</code> such as shown below:</p><div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl"> -<script class="brush: bash; gutter: false; theme: Confluence" type="syntaxhighlighter"><![CDATA[<route> +<script class="brush: java; gutter: false; theme: Default" type="syntaxhighlighter"><![CDATA[<route> <from uri="direct:start"/> <toD uri="jms:${header.base}+language:xpath:/order/@id"/> </route>]]></script> </div></div><p>In the example above the uri is a combination of <a shape="rect" href="simple.html">Simple</a> language and <a shape="rect" href="xpath.html">XPath</a> where the first part is simple (simple is default language). And then the plus sign separate to another language, where we specify the language name followed by a colon</p><div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl"> -<script class="brush: bash; gutter: false; theme: Confluence" type="syntaxhighlighter"><![CDATA[from("direct:start") +<script class="brush: java; gutter: false; theme: Default" type="syntaxhighlighter"><![CDATA[from("direct:start") .toD("jms:${header.base}+language:xpath:/order/@id");]]></script> </div></div><p>You can concat as many languages as you want, just separate them with the plus sign</p><p>The Dynamic To has a few options you can configure</p><div class="table-wrap"><table class="confluenceTable"><tbody><tr><th colspan="1" rowspan="1" class="confluenceTh">Name</th><th colspan="1" rowspan="1" class="confluenceTh">Default Value</th><th colspan="1" rowspan="1" class="confluenceTh">Description</th></tr><tr><td colspan="1" rowspan="1" class="confluenceTd">uri</td><td colspan="1" rowspan="1" class="confluenceTd"> </td><td colspan="1" rowspan="1" class="confluenceTd"><strong>Mandatory:</strong> The uri to use. See above</td></tr><tr><td colspan="1" rowspan="1" class="confluenceTd">pattern</td><td colspan="1" rowspan="1" class="confluenceTd"> </td><td colspan="1" rowspan="1" class="confluenceTd">To set a specific <a shape="rect" href="exchange-pattern.html">Exchange Pattern</a> to use when sending to the endpoint. The original MEP is restored afterwards.</td></tr ><tr><td colspan="1" rowspan="1" class="confluenceTd">cacheSize</td><td >colspan="1" rowspan="1" class="confluenceTd"> </td><td colspan="1" >rowspan="1" class="confluenceTd"><span style="color: rgb(0,0,0);">Allows to >configure the cache size for the </span><code>ProducerCache</code><span >style="color: rgb(0,0,0);"> which caches producers for reuse. Will by >default use the default cache size which is 1000. Setting the value to -1 >allows to turn off the cache all together.</span></td></tr><tr><td >colspan="1" rowspan="1" class="confluenceTd">ignoreInvalidEndpoint</td><td >colspan="1" rowspan="1" class="confluenceTd"><code>false</code></td><td >colspan="1" rowspan="1" class="confluenceTd"><span style="color: >rgb(0,0,0);">Whether to ignore an endpoint URI that could not be resolved. If >disabled, Camel will throw an exception identifying the invalid endpoint >URI.</span></td></tr></tbody></table></div><p> </p><p>For more details >see</p><ul><li><a shape="rect" href="recipien t-list.html">Recipient List</a></li><li><a shape="rect" href="message.html">Message</a></li><li><a shape="rect" href="wire-tap.html">Wire Tap</a><br clear="none"><br clear="none"></li></ul><p></p><h4 id="BookPatternAppendix-UsingThisPattern.3">Using This Pattern</h4> @@ -341,10 +341,10 @@ from("activemq:My.Queue"). <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"> -<script class="brush: java; gutter: false; theme: Confluence" type="syntaxhighlighter"><![CDATA[from("direct:start") +<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"> -<script class="brush: xml; gutter: false; theme: Confluence" type="syntaxhighlighter"><![CDATA[<route> +<script class="brush: xml; gutter: false; theme: Default" type="syntaxhighlighter"><![CDATA[<route> <from uri="direct:start"/> <to uri="jms:queue:foo"/> </route>]]></script> @@ -366,7 +366,7 @@ from("activemq:My.Queue"). <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"> -<script class="brush: java; gutter: false; theme: Confluence" type="syntaxhighlighter"><![CDATA[ +<script class="brush: java; gutter: false; theme: Default" type="syntaxhighlighter"><![CDATA[ RouteBuilder builder = new RouteBuilder() { public void configure() { errorHandler(deadLetterChannel("mock:error")); @@ -380,7 +380,7 @@ RouteBuilder builder = new RouteBuilder( <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: Confluence" type="syntaxhighlighter"><![CDATA[ +<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"/> @@ -437,10 +437,10 @@ errorHandler(deadLetterChannel("jms:queu <errorHandler id="dlc" type="DeadLetterChannel" deadLetterUri="jms:dead" onPrepareFailureRef="myPrepare"/></plain-text-body><p> </p><p>The <strong><code>onPrepare</code></strong> 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 <strong><code>handled=true</code></strong>, then Camel will decorate the <a shape="rect" href="exchange.html">Exchange</a> with the route id where the error occurred.</p><p>Example:</p><parameter ac:name="language">java</parameter><plain-text-body>String failedRouteId = exchange.getProperty(Exchange.FAILURE_ROUTE_ID, String.class); </plain-text-body><p>The <strong><code>Exchange.FAILURE_ROUTE_ID</code></strong> have the constant value <strong><code>CamelFailureRouteId</code></strong>. 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>Before <strong>Camel 2.10</strong>, Camel would perform redelivery while stopping a route, or shutting down Camel. This has improved a bit in <strong>Camel 2.10</strong>: Camel will no longer perform redelivery attempts when shutting down aggressively, e.g., during <a shape="rect" href="graceful-shutdown.html">Graceful Shutdown</a> and timeout hit.</p><p>From <strong>Camel 2.11</strong>: there is a new option <strong><code>allowRedeliveryWhileStopping</code></strong> 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 disallow any redelivery to be executed <em><strong>after</strong></em> the stopping of a route/shutdown of Camel has been triggered. If a redelivery is disallowed then a <strong><code>RejectedExcutionException</code></strong> 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 <strong><code>RejectedExcutionException</code></strong>. The default value is <strong><code>true</code></strong> for backward compatibility.</p><p>For example, the following snippet shows how to do this with Java DSL and XML DSL:<plain-text-body>{snippet:id=e1|lang=java|url=camel/trunk/camel-core/src/test/java/org/apache/camel/processor/RedeliveryErrorHandlerNoRedeliveryOnShutdownTest.java}</plain-text-body>And the sample sam ple with XML DSL<plain-text-body>{snippet:id=e1|lang=xml|url=camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/SpringRedeliveryErrorHandlerNoRedeliveryOnShutdownTest.xml}</plain-text-body></p><h3 id="BookPatternAppendix-Samples">Samples</h3><p>The following example shows how to configure the Dead Letter Channel configuration using the <a shape="rect" href="dsl.html">DSL</a><plain-text-body>{snippet:id=e3|lang=java|url=camel/trunk/camel-core/src/test/java/org/apache/camel/builder/ErrorHandlerTest.java}</plain-text-body>You can also configure 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> as this example shows<plain-text-body>{snippet:id=e4|lang=java|url=camel/trunk/camel-core/src/test/java/org/apache/camel/builder/ErrorHandlerTest.java}</plain-text-body></p><h3 id="BookPatternAppendix-HowCanIModifytheExchangeBeforeRede livery?">How Can I Modify the Exchange Before Redelivery?</h3><p>We support directly in <a shape="rect" href="dead-letter-channel.html">Dead Letter Channel</a> to set a <a shape="rect" href="processor.html">Processor</a> that is executed <strong>before</strong> each redelivery attempt. 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. Here we configure the <a shape="rect" href="dead-letter-channel.html">Dead Letter Channel</a> to use our processor <strong><code>MyRedeliveryProcessor</code></strong> to be executed before each redelivery.<plain-text-body>{snippet:id=e1|lang=java|url=camel/trunk/camel-core/src/test/java/org/apache/camel/processor/DeadLetterChannelOnRedeliveryTest.java}</plain-text -body>And this is the processor <strong><code>MyRedeliveryProcessor</code></strong> where we alter the message.<plain-text-body>{snippet:id=e2|lang=java|url=camel/trunk/camel-core/src/test/java/org/apache/camel/processor/DeadLetterChannelOnRedeliveryTest.java}</plain-text-body></p><h3 id="BookPatternAppendix-HowCanILogWhatCausedtheDeadLetterChanneltobeInvoked?">How Can I Log What Caused the Dead Letter Channel to be Invoked?</h3><p>You often need to know what went wrong that caused the Dead Letter Channel to be used and it does not offer logging for this purpose. So the Dead Letter Channel's endpoint can be set to a endpoint of our own (such as <strong><code>direct:deadLetterChannel</code></strong>). We write a route to accept this Exchange and log the Exception, then forward on to where we want the failed Exchange moved to (which might be a DLQ queue for instance). See also <a shape="rect" class="external-link" href="http://stackoverflow.com/questions/13711462/logging-cam el-exceptions-and-sending-to-the-dead-letter-channel" rel="nofollow">http://stackoverflow.com/questions/13711462/logging-camel-exceptions-and-sending-to-the-dead-letter-channel</a></p><p><parameter ac:name=""><a shape="rect" href="using-this-pattern.html">Using This Pattern</a></parameter></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"> -<script class="brush: java; gutter: false; theme: Confluence" type="syntaxhighlighter"><![CDATA[from("direct:start") +<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"> -<script class="brush: xml; gutter: false; theme: Confluence" type="syntaxhighlighter"><![CDATA[<route> +<script class="brush: xml; gutter: false; theme: Default" type="syntaxhighlighter"><![CDATA[<route> <from uri="direct:start"/> <to uri="jms:queue:foo"/> </route>]]></script> @@ -448,11 +448,11 @@ errorHandler(deadLetterChannel("jms:queu <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"> -<script class="brush: java; gutter: false; theme: Confluence" type="syntaxhighlighter"><![CDATA[from("direct:start") +<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"> -<script class="brush: xml; gutter: false; theme: Confluence" type="syntaxhighlighter"><![CDATA[<route> +<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"/> @@ -463,25 +463,25 @@ errorHandler(deadLetterChannel("jms:queu <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"> -<script class="brush: bash; gutter: false; theme: Confluence" type="syntaxhighlighter"><![CDATA[foo:bar?exchangePattern=InOnly +<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"> -<script class="brush: bash; gutter: false; theme: Confluence" type="syntaxhighlighter"><![CDATA[from("mq:someQueue"). +<script class="brush: java; gutter: false; theme: Default" type="syntaxhighlighter"><![CDATA[from("mq:someQueue"). setExchangePattern(ExchangePattern.InOnly). bean(Foo.class); ]]></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"> -<script class="brush: bash; gutter: false; theme: Confluence" type="syntaxhighlighter"><![CDATA[from("mq:someQueue"). +<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"> -<script class="brush: bash; gutter: false; theme: Confluence" type="syntaxhighlighter"><![CDATA[<route> +<script class="brush: java; gutter: false; theme: Default" type="syntaxhighlighter"><![CDATA[<route> <from uri="mq:someQueue"/> <inOnly uri="bean:foo"/> </route> ]]></script> </div></div><div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl"> -<script class="brush: bash; gutter: false; theme: Confluence" type="syntaxhighlighter"><![CDATA[<route> +<script class="brush: java; gutter: false; theme: Default" type="syntaxhighlighter"><![CDATA[<route> <from uri="mq:someQueue"/> <inOnly uri="mq:anotherQueue"/> </route> @@ -510,7 +510,7 @@ errorHandler(deadLetterChannel("jms:queu <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"> -<script class="brush: bash; gutter: false; theme: Confluence" type="syntaxhighlighter"><![CDATA[ +<script class="brush: java; gutter: false; theme: Default" type="syntaxhighlighter"><![CDATA[ jms:MyQueue?exchangePattern=InOut ]]></script> </div></div> @@ -518,7 +518,7 @@ jms:MyQueue?exchangePattern=InOut <p>You can specify the exchange pattern in DSL rule or Spring configuration.</p> <div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl"> -<script class="brush: java; gutter: false; theme: Confluence" type="syntaxhighlighter"><![CDATA[ +<script class="brush: java; gutter: false; theme: Default" type="syntaxhighlighter"><![CDATA[ // Send to an endpoint using InOut from("direct:testInOut").inOut("mock:result"); @@ -545,7 +545,7 @@ from("direct:testSetExchangePattern </div></div> <div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl"> -<script class="brush: xml; gutter: false; theme: Confluence" type="syntaxhighlighter"><![CDATA[ +<script class="brush: xml; gutter: false; theme: Default" type="syntaxhighlighter"><![CDATA[ <camelContext xmlns="http://camel.apache.org/schema/spring"> <!-- Send the exchange as InOnly --> <route> @@ -599,11 +599,11 @@ 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"> -<script class="brush: java; gutter: false; theme: Confluence" type="syntaxhighlighter"><![CDATA[from("direct:start") +<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"> -<script class="brush: xml; gutter: false; theme: Confluence" type="syntaxhighlighter"><![CDATA[<route> +<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"/> @@ -619,7 +619,7 @@ from("direct:testSetExchangePattern <p><strong>Requestor Code</strong></p> <div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl"> -<script class="brush: bash; gutter: false; theme: Confluence" type="syntaxhighlighter"><![CDATA[ +<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> @@ -627,7 +627,7 @@ template.sendBodyAndHeader("direct: <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"> -<script class="brush: bash; gutter: false; theme: Confluence" type="syntaxhighlighter"><![CDATA[ +<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"); @@ -637,7 +637,7 @@ from("activemq:queue:bar?disableRep <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"> -<script class="brush: bash; gutter: false; theme: Confluence" type="syntaxhighlighter"><![CDATA[ +<script class="brush: java; gutter: false; theme: Default" type="syntaxhighlighter"><![CDATA[ <route> <from uri="direct:start"/> <to uri="activemq:queue:foo?preserveMessageQos=true"/> @@ -665,7 +665,7 @@ from("activemq:queue:bar?disableRep <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"> -<script class="brush: java; gutter: false; theme: Confluence" type="syntaxhighlighter"><![CDATA[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")); @@ -680,7 +680,7 @@ from("activemq:queue:bar?disableRep } };]]></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"> -<script class="brush: xml; gutter: false; theme: Confluence" type="syntaxhighlighter"><![CDATA[<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"/> <choice> @@ -1002,7 +1002,7 @@ Whereas using the <a shape="rect" href=" <p>In this example we want to check that a multipart order can be filled. Each part of the order requires a check at a different inventory.</p> <div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl"> -<script class="brush: java; gutter: false; theme: Confluence" type="syntaxhighlighter"><![CDATA[ +<script class="brush: java; gutter: false; theme: Default" type="syntaxhighlighter"><![CDATA[ // split up the order so individual OrderItems can be validated by the appropriate bean from("direct:start") .split().body() @@ -1024,7 +1024,7 @@ from("seda:aggregate") <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: bash; gutter: false; theme: Confluence" type="syntaxhighlighter"><![CDATA[ +<script class="brush: java; gutter: false; theme: Default" type="syntaxhighlighter"><![CDATA[ <route> <from uri="direct:start"/> <split> @@ -1066,7 +1066,7 @@ from("seda:aggregate") <p>In this example we want to split an incoming order using the <a shape="rect" href="splitter.html">Splitter</a> eip, transform each order line, and then combine the order lines into a new order message.</p> <div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl"> -<script class="brush: java; gutter: false; theme: Confluence" type="syntaxhighlighter"><![CDATA[ +<script class="brush: java; gutter: false; theme: Default" type="syntaxhighlighter"><![CDATA[ // this routes starts from the direct:start endpoint // the body is then splitted based on @ separator // the splitter in Camel supports InOut as well and for that we need @@ -1091,7 +1091,7 @@ from("direct:start") <p>The bean with the methods to transform the order line and process the order as well:</p> <div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl"> -<script class="brush: java; gutter: false; theme: Confluence" type="syntaxhighlighter"><![CDATA[ +<script class="brush: java; gutter: false; theme: Default" type="syntaxhighlighter"><![CDATA[ public static class MyOrderService { private static int counter; @@ -1118,7 +1118,7 @@ public static class MyOrderService { <p>And the <code>AggregationStrategy</code> we use with the <a shape="rect" href="splitter.html">Splitter</a> eip to combine the orders back again (eg fork/join):</p> <div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl"> -<script class="brush: java; gutter: false; theme: Confluence" type="syntaxhighlighter"><![CDATA[ +<script class="brush: java; gutter: false; theme: Default" type="syntaxhighlighter"><![CDATA[ /** * This is our own order aggregation strategy where we can control * how each splitted message should be combined. As we do not want to @@ -1169,7 +1169,7 @@ public static class MyOrderStrategy impl <p>In this example we want to get the best quote for beer from several different vendors. We use a dynamic <a shape="rect" href="recipient-list.html">Recipient List</a> to get the request for a quote to all vendors and an <a shape="rect" href="aggregator.html">Aggregator</a> to pick the best quote out of all the responses. The routes for this are defined as:</p> <div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl"> -<script class="brush: xml; gutter: false; theme: Confluence" type="syntaxhighlighter"><![CDATA[ +<script class="brush: xml; gutter: false; theme: Default" type="syntaxhighlighter"><![CDATA[ <camelContext xmlns="http://camel.apache.org/schema/spring"> <route> <from uri="direct:start"/> @@ -1193,7 +1193,7 @@ public static class MyOrderStrategy impl <p>So in the first route you see that the <a shape="rect" href="recipient-list.html">Recipient List</a> is looking at the <code>listOfVendors</code> header for the list of recipients. So, we need to send a message like</p> <div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl"> -<script class="brush: java; gutter: false; theme: Confluence" type="syntaxhighlighter"><![CDATA[ +<script class="brush: java; gutter: false; theme: Default" type="syntaxhighlighter"><![CDATA[ Map<String, Object> headers = new HashMap<String, Object>(); headers.put("listOfVendors", "bean:vendor1, bean:vendor2, bean:vendor3"); headers.put("quoteRequestId", "quoteRequest-1"); @@ -1204,7 +1204,7 @@ template.sendBodyAndHeaders("direct <p>This message will be distributed to the following <a shape="rect" href="endpoint.html">Endpoint</a>s: <code>bean:vendor1</code>, <code>bean:vendor2</code>, and <code>bean:vendor3</code>. These are all beans which look like</p> <div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl"> -<script class="brush: java; gutter: false; theme: Confluence" type="syntaxhighlighter"><![CDATA[ +<script class="brush: java; gutter: false; theme: Default" type="syntaxhighlighter"><![CDATA[ public class MyVendor { private int beerPrice; @@ -1230,7 +1230,7 @@ public class MyVendor { <p>and are loaded up in Spring like</p> <div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl"> -<script class="brush: xml; gutter: false; theme: Confluence" type="syntaxhighlighter"><![CDATA[ +<script class="brush: xml; gutter: false; theme: Default" type="syntaxhighlighter"><![CDATA[ <bean id="aggregatorStrategy" class="org.apache.camel.spring.processor.scattergather.LowestQuoteAggregationStrategy"/> <bean id="vendor1" class="org.apache.camel.spring.processor.scattergather.MyVendor"> @@ -1258,7 +1258,7 @@ public class MyVendor { <p>At the next step we want to take the beer quotes from all vendors and find out which one was the best (i.e. the lowest!). To do this we use an <a shape="rect" href="aggregator.html">Aggregator</a> with a custom aggregation strategy. The <a shape="rect" href="aggregator.html">Aggregator</a> needs to be able to compare only the messages from this particular quote; this is easily done by specifying a correlationExpression equal to the value of the quoteRequestId header. As shown above in the message sending snippet, we set this header to <code>quoteRequest-1</code>. This correlation value should be unique or you may include responses that are not part of this quote. To pick the lowest quote out of the set, we use a custom aggregation strategy like </p> <div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl"> -<script class="brush: java; gutter: false; theme: Confluence" type="syntaxhighlighter"><![CDATA[ +<script class="brush: java; gutter: false; theme: Default" type="syntaxhighlighter"><![CDATA[ public class LowestQuoteAggregationStrategy implements AggregationStrategy { public Exchange aggregate(Exchange oldExchange, Exchange newExchange) { // the first time we only have the new exchange @@ -1279,7 +1279,7 @@ public class LowestQuoteAggregationStrat <p>Finally, we expect to get the lowest quote of $1 out of $1, $2, and $3.</p> <div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl"> -<script class="brush: java; gutter: false; theme: Confluence" type="syntaxhighlighter"><![CDATA[ +<script class="brush: java; gutter: false; theme: Default" type="syntaxhighlighter"><![CDATA[ result.expectedBodiesReceived(1); // expect the lowest quote ]]></script> </div></div> @@ -1294,7 +1294,7 @@ result.expectedBodiesReceived(1); // exp <p>You can lock down which recipients are used in the Scatter-Gather by using a static <a shape="rect" href="recipient-list.html">Recipient List</a>. It looks something like this</p> <div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl"> -<script class="brush: java; gutter: false; theme: Confluence" type="syntaxhighlighter"><![CDATA[ +<script class="brush: java; gutter: false; theme: Default" type="syntaxhighlighter"><![CDATA[ from("direct:start").multicast().to("seda:vendor1", "seda:vendor2", "seda:vendor3"); from("seda:vendor1").to("bean:vendor1").to("seda:quoteAggregator"); @@ -1711,14 +1711,14 @@ from("direct:resource") <p>Here is a simple example using the <a shape="rect" href="dsl.html">DSL</a> directly</p> <div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl"> -<script class="brush: java; gutter: false; theme: Confluence" type="syntaxhighlighter"><![CDATA[ +<script class="brush: java; gutter: false; theme: Default" type="syntaxhighlighter"><![CDATA[ from("direct:start").setBody(body().append(" World!")).to("mock:result"); ]]></script> </div></div> <p>In this example we add our own <a shape="rect" href="processor.html">Processor</a></p> <div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl"> -<script class="brush: java; gutter: false; theme: Confluence" type="syntaxhighlighter"><![CDATA[ +<script class="brush: java; gutter: false; theme: Default" type="syntaxhighlighter"><![CDATA[ from("direct:start").process(new Processor() { public void process(Exchange exchange) { Message in = exchange.getIn(); @@ -1736,7 +1736,7 @@ from("direct:start").process(n <p><strong>Using Spring XML</strong></p> <div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl"> -<script class="brush: bash; gutter: false; theme: Confluence" type="syntaxhighlighter"><![CDATA[ +<script class="brush: java; gutter: false; theme: Default" type="syntaxhighlighter"><![CDATA[ <route> <from uri="activemq:Input"/> <bean ref="myBeanName" method="doTransform"/> @@ -1748,7 +1748,7 @@ from("direct:start").process(n <p>You can also use XPath to filter out part of the message you are interested in:</p> <div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl"> -<script class="brush: bash; gutter: false; theme: Confluence" type="syntaxhighlighter"><![CDATA[ +<script class="brush: java; gutter: false; theme: Default" type="syntaxhighlighter"><![CDATA[ <route> <from uri="activemq:Input"/> <setBody><xpath resultType="org.w3c.dom.Document">//foo:bar</xpath></setBody> @@ -1861,14 +1861,14 @@ from("direct:start").process(n <h3 id="BookPatternAppendix-UsingfromJavaDSL">Using from Java DSL</h3> <p>In the route below it will read the file content and tokenize by line breaks so each line can be sorted. </p> <div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl"> -<script class="brush: bash; gutter: false; theme: Confluence" type="syntaxhighlighter"><![CDATA[ +<script class="brush: java; gutter: false; theme: Default" type="syntaxhighlighter"><![CDATA[ from("file://inbox").sort(body().tokenize("\n")).to("bean:MyServiceBean.processLine"); ]]></script> </div></div> <p>You can pass in your own comparator as a 2nd argument:</p> <div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl"> -<script class="brush: bash; gutter: false; theme: Confluence" type="syntaxhighlighter"><![CDATA[ +<script class="brush: java; gutter: false; theme: Default" type="syntaxhighlighter"><![CDATA[ from("file://inbox").sort(body().tokenize("\n"), new MyReverseComparator()).to("bean:MyServiceBean.processLine"); ]]></script> </div></div> @@ -1878,7 +1878,7 @@ from("file://inbox").sort(body <p>In the route below it will read the file content and tokenize by line breaks so each line can be sorted. </p> <div class="code panel pdl" style="border-width: 1px;"><div class="codeHeader panelHeader pdl" style="border-bottom-width: 1px;"><b>Camel 2.7 or better</b></div><div class="codeContent panelContent pdl"> -<script class="brush: bash; gutter: false; theme: Confluence" type="syntaxhighlighter"><![CDATA[ +<script class="brush: java; gutter: false; theme: Default" type="syntaxhighlighter"><![CDATA[ <route> <from uri="file://inbox"/> <sort> @@ -1890,7 +1890,7 @@ from("file://inbox").sort(body </div></div> <div class="code panel pdl" style="border-width: 1px;"><div class="codeHeader panelHeader pdl" style="border-bottom-width: 1px;"><b>Camel 2.6 or older</b></div><div class="codeContent panelContent pdl"> -<script class="brush: bash; gutter: false; theme: Confluence" type="syntaxhighlighter"><![CDATA[ +<script class="brush: java; gutter: false; theme: Default" type="syntaxhighlighter"><![CDATA[ <route> <from uri="file://inbox"/> <sort> @@ -1905,7 +1905,7 @@ from("file://inbox").sort(body <p>And to use our own comparator we can refer to it as a spring bean:</p> <div class="code panel pdl" style="border-width: 1px;"><div class="codeHeader panelHeader pdl" style="border-bottom-width: 1px;"><b>Camel 2.7 or better</b></div><div class="codeContent panelContent pdl"> -<script class="brush: bash; gutter: false; theme: Confluence" type="syntaxhighlighter"><![CDATA[ +<script class="brush: java; gutter: false; theme: Default" type="syntaxhighlighter"><![CDATA[ <route> <from uri="file://inbox"/> <sort comparatorRef="myReverseComparator"> @@ -1919,7 +1919,7 @@ from("file://inbox").sort(body </div></div> <div class="code panel pdl" style="border-width: 1px;"><div class="codeHeader panelHeader pdl" style="border-bottom-width: 1px;"><b>Camel 2.6 or older</b></div><div class="codeContent panelContent pdl"> -<script class="brush: bash; gutter: false; theme: Confluence" type="syntaxhighlighter"><![CDATA[ +<script class="brush: java; gutter: false; theme: Default" type="syntaxhighlighter"><![CDATA[ <route> <from uri="file://inbox"/> <sort comparatorRef="myReverseComparator"> @@ -1942,11 +1942,11 @@ from("file://inbox").sort(body <h2 id="BookPatternAppendix-MessagingEndpoints">Messaging Endpoints</h2> <h3 id="BookPatternAppendix-MessagingMapper">Messaging Mapper</h3><p>Camel supports the <a shape="rect" class="external-link" href="http://www.enterpriseintegrationpatterns.com/MessagingMapper.html" rel="nofollow">Messaging Mapper</a> from the <a shape="rect" href="enterprise-integration-patterns.html">EIP patterns</a> by using either <a shape="rect" href="message-translator.html">Message Translator</a> pattern or the <a shape="rect" href="type-converter.html">Type Converter</a> module.</p><p><span class="confluence-embedded-file-wrapper"><img class="confluence-embedded-image confluence-external-resource" src="http://www.enterpriseintegrationpatterns.com/img/MessagingMapperClassDiagram.gif" data-image-src="http://www.enterpriseintegrationpatterns.com/img/MessagingMapperClassDiagram.gif"></span></p><h4 id="BookPatternAppendix-Example.8">Example</h4><p>The following example demonstrates the use of a <a shape="rect" href="bean.html">Bean</a> component to map between two messaging system</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"> -<script class="brush: java; gutter: false; theme: Confluence" type="syntaxhighlighter"><![CDATA[from("activemq:foo") +<script class="brush: java; gutter: false; theme: Default" type="syntaxhighlighter"><![CDATA[from("activemq:foo") .beanRef("transformerBean", "transform") .to("jms:bar");]]></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"> -<script class="brush: xml; gutter: false; theme: Confluence" type="syntaxhighlighter"><![CDATA[<route> +<script class="brush: xml; gutter: false; theme: Default" type="syntaxhighlighter"><![CDATA[<route> <from uri="activemq:foo"/> <bean ref="transformerBean" method="transform" /> <to uri="jms:bar"/> @@ -1955,10 +1955,10 @@ from("file://inbox").sort(body <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-EventDrivenConsumer">Event Driven Consumer</h3><p>Camel supports the <a shape="rect" class="external-link" href="http://www.enterpriseintegrationpatterns.com/EventDrivenConsumer.html" rel="nofollow">Event Driven Consumer</a> from the <a shape="rect" href="enterprise-integration-patterns.html">EIP patterns</a>. The default consumer model is event based (i.e. asynchronous) as this means that the Camel container can then manage pooling, threading and concurrency for you in a declarative manner.</p><p><span class="confluence-embedded-file-wrapper"><img class="confluence-embedded-image confluence-external-resource" src="http://www.enterpriseintegrationpatterns.com/img/EventDrivenConsumerSolution.gif" data-image-src="http://www.enterpriseintegrationpatterns.com/img/EventDrivenConsumerSolution.gif"></span></p><p>The Event Driven Consumer is implemented by consumers implementing the <a shape="rect" class="external-link" href="http://camel.apache.org/maven/current /camel-core/apidocs/org/apache/camel/Processor.html">Processor</a> interface which is invoked by the <a shape="rect" href="message-endpoint.html">Message Endpoint</a> when a <a shape="rect" href="message.html">Message</a> is available for processing.</p><h4 id="BookPatternAppendix-Example.9">Example</h4><p>The following demonstrates a <a shape="rect" class="external-link" href="http://camel.apache.org/maven/current/camel-core/apidocs/org/apache/camel/Processor.html">Processor</a> defined in the Camel  <a shape="rect" href="registry.html">Registry</a> which is invoked when an event occurs from a <a shape="rect" href="jms.html">JMS</a> queue</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"> -<script class="brush: java; gutter: false; theme: Confluence" type="syntaxhighlighter"><![CDATA[from("jms:queue:foo") +<script class="brush: java; gutter: false; theme: Default" type="syntaxhighlighter"><![CDATA[from("jms:queue:foo") .processRef("processor");]]></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"> -<script class="brush: xml; gutter: false; theme: Confluence" type="syntaxhighlighter"><![CDATA[<route> +<script class="brush: xml; gutter: false; theme: Default" type="syntaxhighlighter"><![CDATA[<route> <from uri="jms:queue:foo"/> <to uri="processor"/> </route>]]></script> @@ -2008,7 +2008,7 @@ consumer.start(); <p>For example</p> <div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl"> -<script class="brush: bash; gutter: false; theme: Confluence" type="syntaxhighlighter"><![CDATA[ +<script class="brush: java; gutter: false; theme: Default" type="syntaxhighlighter"><![CDATA[ from("jms:MyQueue?concurrentConsumers=5").bean(SomeBean.class); ]]></script> </div></div> @@ -2016,7 +2016,7 @@ from("jms:MyQueue?concurrentConsume <p>or in Spring DSL</p> <div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl"> -<script class="brush: bash; gutter: false; theme: Confluence" type="syntaxhighlighter"><![CDATA[ +<script class="brush: java; gutter: false; theme: Default" type="syntaxhighlighter"><![CDATA[ <route> <from uri="jms:MyQueue?concurrentConsumers=5"/> <to uri="bean:someBean"/> @@ -2030,7 +2030,7 @@ from("jms:MyQueue?concurrentConsume <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-MessageDispatcher">Message Dispatcher</h3><p>Camel supports the <a shape="rect" class="external-link" href="http://www.enterpriseintegrationpatterns.com/MessageDispatcher.html" rel="nofollow">Message Dispatcher</a> from the <a shape="rect" href="enterprise-integration-patterns.html">EIP patterns</a> using various approaches.</p><p><span class="confluence-embedded-file-wrapper"><img class="confluence-embedded-image confluence-external-resource" src="http://www.enterpriseintegrationpatterns.com/img/MessageDispatcher.gif" data-image-src="http://www.enterpriseintegrationpatterns.com/img/MessageDispatcher.gif"></span></p><p>You can use a component like <a shape="rect" href="jms.html">JMS</a> with selectors to implement a <a shape="rect" href="selective-consumer.html">Selective Consumer</a> as the Message Dispatcher implementation. Or you can use an <a shape="rect" href="endpoint.html">Endpoint</a> as the Message Dispatcher itself and then use a <a shape="rect" href="content-based-router.html">Content Based Router</a> as the Message Dispatcher.</p><p> </p><h4 id="BookPatternAppendix-Example.10">Example</h4><p>The following example demonstrates <a shape="rect" class="external-link" href="http://www.enterpriseintegrationpatterns.com/MessageDispatcher.html" rel="nofollow">Message Dispatcher</a> pattern using the <a shape="rect" href="competing-consumers.html">Competing Consumers</a> functionality of the <a shape="rect" href="jms.html">JMS</a> component to offload messages to a <a shape="rect" href="content-based-router.html">Content Based Router</a> and custom <a shape="rect" href="processor.html">Processors</a> registered in the Camel <a shape="rect" href="registry.html">Registry</a> running in separate threads from originating consumer.</p><p> </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"> -<script class="brush: java; gutter: false; theme: Confluence" type="syntaxhighlighter"><![CDATA[from("jms:queue:foo?concurrentConsumers=5") +<script class="brush: java; gutter: false; theme: Default" type="syntaxhighlighter"><![CDATA[from("jms:queue:foo?concurrentConsumers=5") .threads(5) .choice() .when(header("type").isEqualTo("A")) @@ -2042,7 +2042,7 @@ from("jms:MyQueue?concurrentConsume .otherwise() .to("jms:queue:invalidMessageType");]]></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"> -<script class="brush: xml; gutter: false; theme: Confluence" type="syntaxhighlighter"><![CDATA[<route> +<script class="brush: xml; gutter: false; theme: Default" type="syntaxhighlighter"><![CDATA[<route> <from uri="jms:queue:foo?concurrentConsumers=5"/> <threads poolSize="5"> <choice> @@ -2078,7 +2078,7 @@ from("jms:MyQueue?concurrentConsume <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"> -<script class="brush: java; gutter: false; theme: Confluence" type="syntaxhighlighter"><![CDATA[ +<script class="brush: java; gutter: false; theme: Default" type="syntaxhighlighter"><![CDATA[ RouteBuilder builder = new RouteBuilder() { public void configure() { errorHandler(deadLetterChannel("mock:error")); @@ -2093,7 +2093,7 @@ RouteBuilder builder = new RouteBuilder( <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: Confluence" type="syntaxhighlighter"><![CDATA[ +<script class="brush: xml; gutter: false; theme: Default" type="syntaxhighlighter"><![CDATA[ <bean id="myProcessor" class="org.apache.camel.builder.MyProcessor"/> <camelContext errorHandlerRef="errorHandler" xmlns="http://camel.apache.org/schema/spring"> @@ -2124,7 +2124,7 @@ RouteBuilder builder = new RouteBuilder( <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"> -<script class="brush: bash; gutter: false; theme: Confluence" type="syntaxhighlighter"><![CDATA[ +<script class="brush: java; gutter: false; theme: Default" type="syntaxhighlighter"><![CDATA[ from("direct:start").to("activemq:topic:foo"); from("activemq:topic:foo?clientId=1&durableSubscriptionName=bar1").to("mock:result1"); @@ -2136,7 +2136,7 @@ from("activemq:topic:foo?clientId=2 <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: bash; gutter: false; theme: Confluence" type="syntaxhighlighter"><![CDATA[ +<script class="brush: java; gutter: false; theme: Default" type="syntaxhighlighter"><![CDATA[ <route> <from uri="direct:start"/> <to uri="activemq:topic:foo"/> @@ -2159,7 +2159,7 @@ from("activemq:topic:foo?clientId=2 <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"> -<script class="brush: bash; gutter: false; theme: Confluence" type="syntaxhighlighter"><![CDATA[ +<script class="brush: java; gutter: false; theme: Default" type="syntaxhighlighter"><![CDATA[ from("direct:start").to("activemq:topic:VirtualTopic.foo"); from("activemq:queue:Consumer.1.VirtualTopic.foo").to("mock:result1"); @@ -2171,7 +2171,7 @@ from("activemq:queue:Consumer.2.Vir <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: bash; gutter: false; theme: Confluence" type="syntaxhighlighter"><![CDATA[ +<script class="brush: java; gutter: false; theme: Default" type="syntaxhighlighter"><![CDATA[ <route> <from uri="direct:start"/> <to uri="activemq:topic:VirtualTopic.foo"/> @@ -2244,10 +2244,10 @@ from("activemq:queue:Consumer.2.Vir </route> </plain-text-body><h3 id="BookPatternAppendix-DatabaseSample">Database Sample</h3><p>In this sample we want to ensure that two endpoints is under transaction control. These two endpoints inserts data into a database.<br clear="none"> The sample is in its full as a <a shape="rect" class="external-link" href="http://svn.apache.org/viewvc/camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/interceptor/TransactionalClientDataSourceMinimalConfigurationTest.java?view=log">unit test</a>.</p><p>First of all we setup the usual spring stuff in its configuration file. Here we have defined a DataSource to the HSQLDB and a most importantly the Spring DataSource TransactionManager that is doing the heavy lifting of ensuring our transactional policies. You are of course free to use any of the Spring based TransactionManager, eg. if you are in a full blown J2EE container you could use JTA or the WebLogic or WebSphere specific managers.</p><p>As we use the new convent ion over configuration we do <strong>not</strong> need to configure a transaction policy bean, so we do not have any <code>PROPAGATION_REQUIRED</code> beans. All the beans needed to be configured is <strong>standard</strong> Spring beans only, eg. there are no Camel specific configuration at all.<plain-text-body>{snippet:id=e1|lang=xml|url=camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/interceptor/springTransactionalClientDataSourceMinimalConfiguration.xml}</plain-text-body>Then we are ready to define our Camel routes. We have two routes: 1 for success conditions, and 1 for a forced rollback condition.<br clear="none"> This is after all based on a unit test. Notice that we mark each route as transacted using the <strong>transacted</strong> tag.<plain-text-body>{snippet:id=e2|lang=xml|url=camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/interceptor/springTransactionalClientDataSourceMinimalConfiguration.xml}</plain-te xt-body>That is all that is needed to configure a Camel route as being transacted. Just remember to use the <strong>transacted</strong> DSL. The rest is standard Spring XML to setup the transaction manager.</p><h3 id="BookPatternAppendix-JMSSample">JMS Sample</h3><p>In this sample we want to listen for messages on a queue and process the messages with our business logic java code and send them along. Since its based on a <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/tx/TransactionMinimalConfigurationTest.java?view=log">unit test</a> the destination is a mock endpoint.</p><p>First we configure the standard Spring XML to declare a JMS connection factory, a JMS transaction manager and our ActiveMQ component that we use in our routing.<plain-text-body>{snippet:id=e1|lang=xml|url=camel/trunk/components/camel-jms/src/test/resources/org/apache/camel/component/jms/tx/TransactionMinimalCo nfigurationTest.xml}</plain-text-body>And then we configure our routes. Notice that all we have to do is mark the route as transacted using the <strong>transacted</strong> tag.<plain-text-body>{snippet:id=e2|lang=xml|url=camel/trunk/components/camel-jms/src/test/resources/org/apache/camel/component/jms/tx/TransactionMinimalConfigurationTest.xml}</plain-text-body></p><parameter ac:name="title">Transaction error handler</parameter><rich-text-body><p>When a route is marked as transacted using <strong>transacted</strong> Camel will automatic use the <a shape="rect" href="transactionerrorhandler.html">TransactionErrorHandler</a> as <a shape="rect" href="error-handler.html">Error Handler</a>. It supports basically the same feature set as the <a shape="rect" href="defaulterrorhandler.html">DefaultErrorHandler</a>, so you can for instance use <a shape="rect" href="exception-clause.html">Exception Clause</a> as well.</p></rich-text-body><h3 id="BookPatternAppendix-IntegrationTestingwithSprin g">Integration Testing with Spring</h3><rich-text-body><p>An Integration Test here means a test runner class annotated <code>@RunWith(SpringJUnit4ClassRunner.class).</code></p></rich-text-body><p><span style="line-height: 1.4285715;">When following the Spring Transactions documentation it is tempting to annotate your integration test with </span><code style="line-height: 1.4285715;">@Transactional</code><span style="line-height: 1.4285715;"> then seed your database before firing up the route to be tested and sending a message in. This is incorrect as Spring will have an in-progress transaction, and Camel will wait on this before proceeding, leading to the route timing out.</span></p><p>Instead, remove the <code>@Transactional</code> annotation from the test method and seed the test data within a <code>TransactionTemplate</code> execution which will ensure the data is committed to the database before Camel attempts to pick up and use the transaction manager. A simple exampl e <a shape="rect" class="external-link" href="https://github.com/rajivj2/example2/blob/master/src/test/java/com/example/NotificationRouterIT.java" rel="nofollow">can be found on GitHub</a>.</p><p>Spring's transactional model ensures each transaction is bound to one thread. A Camel route may invoke additional threads which is where the blockage may occur. This is not a fault of Camel but as the programmer you must be aware of the consequences of beginning a transaction in a test thread and expecting a separate thread created by your Camel route to be participate, which it cannot. You can, in your test, mock the parts that cause separate threads to avoid this issue.</p><h2 id="BookPatternAppendix-Usingmultiplerouteswithdifferentpropagationbehaviors">Using multiple routes with different propagation behaviors</h2><p><strong>Available as of Camel 2.2</strong><br clear="none"> Suppose you want to route a message through two routes and by which the 2nd route should run in its own tran saction. How do you do that? You use propagation behaviors for that where you configure it as follows:</p><ul class="alternate"><li>The first route use <code>PROPAGATION_REQUIRED</code></li><li>The second route use <code>PROPAGATION_REQUIRES_NEW</code></li></ul><p>This is configured in the Spring XML file:<plain-text-body>{snippet:id=e1|lang=xml|url=camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/interceptor/MixedTransactionPropagationTest.xml}</plain-text-body>Then in the routes you use transacted DSL to indicate which of these two propagations it uses.<plain-text-body>{snippet:id=e1|lang=java|url=camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/interceptor/MixedTransactionPropagationTest.java}</plain-text-body>Notice how we have configured the <code>onException</code> in the 2nd route to indicate in case of any exceptions we should handle it and just rollback this transaction. This is done using the <code>markRollbackOnlyLast </code> which tells Camel to only do it for the current transaction and not globally.</p><h4 id="BookPatternAppendix-SeeAlso.7">See Also</h4><ul><li><a shape="rect" href="error-handling-in-camel.html">Error handling in Camel</a></li><li><a shape="rect" href="transactionerrorhandler.html">TransactionErrorHandler</a></li><li><a shape="rect" href="error-handler.html">Error Handler</a></li><li><a shape="rect" href="jms.html">JMS</a></li></ul><p><parameter ac:name=""><a shape="rect" href="using-this-pattern.html">Using This Pattern</a></parameter></p> <h3 id="BookPatternAppendix-MessagingGateway">Messaging Gateway</h3><p>Camel has several endpoint components that support the <a shape="rect" class="external-link" href="http://www.enterpriseintegrationpatterns.com/MessagingGateway.html" rel="nofollow">Messaging Gateway</a> from the <a shape="rect" href="enterprise-integration-patterns.html">EIP patterns</a>.</p><p><span class="confluence-embedded-file-wrapper"><img class="confluence-embedded-image confluence-external-resource" src="http://www.enterpriseintegrationpatterns.com/img/MessagingGatewaySolution.gif" data-image-src="http://www.enterpriseintegrationpatterns.com/img/MessagingGatewaySolution.gif"></span></p><p>Components like <a shape="rect" href="bean.html">Bean</a> and <a shape="rect" href="cxf.html">CXF</a> provide a a way to bind a Java interface to the message exchange.</p><p>However you may want to read the <a shape="rect" href="using-camelproxy.html">Using CamelProxy</a> documentation as a true <a shape="rect" href="me ssaging-gateway.html">Messaging Gateway</a> EIP solution.<br clear="none"> Another approach is to use <code>@Produce</code> which you can read about in <a shape="rect" href="pojo-producing.html">POJO Producing</a> which also can be used as a <a shape="rect" href="messaging-gateway.html">Messaging Gateway</a> EIP solution.</p><p> </p><h4 id="BookPatternAppendix-Example.11">Example</h4><p>The following example how the <a shape="rect" href="cxf.html">CXF</a> and <a shape="rect" href="bean.html">Bean</a> components can be used to abstract the developer from the underlying messaging system API</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"> -<script class="brush: java; gutter: false; theme: Confluence" type="syntaxhighlighter"><![CDATA[from("cxf:bean:soapMessageEndpoint") +<script class="brush: java; gutter: false; theme: Default" type="syntaxhighlighter"><![CDATA[from("cxf:bean:soapMessageEndpoint") .to("bean:testBean?method=processSOAP");]]></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"> -<script class="brush: xml; gutter: false; theme: Confluence" type="syntaxhighlighter"><![CDATA[<route> +<script class="brush: xml; gutter: false; theme: Default" type="syntaxhighlighter"><![CDATA[<route> <from uri="cxf:bean:soapMessageEndpoint"/> <to uri="bean:testBean?method=processSOAP"/> </route>]]></script> @@ -2269,7 +2269,7 @@ from("activemq:queue:Consumer.2.Vir <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"> -<script class="brush: bash; gutter: false; theme: Confluence" type="syntaxhighlighter"><![CDATA[ +<script class="brush: java; gutter: false; theme: Default" type="syntaxhighlighter"><![CDATA[ from("direct:invokeMyService").to("bean:myService"); ]]></script> </div></div> @@ -2277,7 +2277,7 @@ from("direct:invokeMyService") <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">
[... 87 lines stripped ...]
