camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From conflue...@apache.org
Subject [CONF] Apache Camel > JMS
Date Tue, 28 Jul 2009 04:48:00 GMT
<html>
<head>
    <base href="http://cwiki.apache.org/confluence">
            <link rel="stylesheet" href="/confluence/s/1519/1/1/_/styles/combined.css?spaceKey=CAMEL&amp;forWysiwyg=true" type="text/css">
    </head>
<body style="background-color: white" bgcolor="white">
<div id="pageContent">
<div id="notificationFormat">
<div class="wiki-content">
<div class="email">
     <h2><a href="http://cwiki.apache.org/confluence/display/CAMEL/JMS">JMS</a></h2>
     <h4>Page <b>edited</b> by             <a href="http://cwiki.apache.org/confluence/display/~davsclaus">Claus Ibsen</a>
    </h4>
     
          <br/>
     <div class="notificationGreySide">
         <h2><a name="JMS-JMSComponent"></a>JMS Component</h2>

<p>The JMS component allows messages to be sent to a <a href="http://java.sun.com/products/jms/" rel="nofollow">JMS</a> Queue or Topic; or messages to be consumed from a JMS Queue or Topic. The implementation of the JMS Component uses Spring's JMS support for declarative transactions, using Spring's JmsTemplate for sending and a MessageListenerContainer for consuming.</p>

<div class='panelMacro'><table class='warningMacro'><colgroup><col width='24'><col></colgroup><tr><td valign='top'><img src="/confluence/images/icons/emoticons/forbidden.gif" width="16" height="16" align="absmiddle" alt="" border="0"></td><td><b>For users with Camel 1.6.1 or older</b><br /><p>The jms consumer have a bad default in Camel 1.6.1 or older. The maxMessagesPerTask is set to 1 where as it really should be -1.<br/>
This issue causes Spring to create a new thread after it have processed a message. Causing the thread to continue rising. You can see this in the log where a new thread name is used.</p>

<p>To remedy this change your routes from:</p>
<style type="text/css">
@import url(/confluence/download/resources/confluence.ext.code:code/shStyles.css);
</style>
<!--[if IE]>
<style type="text/css">
    .code textarea, .code input { padding: 0 !important; }
</style>
<![endif]-->
<script class="javascript" src="/confluence/download/resources/confluence.ext.code:code/shCore.js"></script>
<script class="javascript" src="/confluence/download/resources/confluence.ext.code:code/shBrushCSharp.js"></script>
<script class="javascript" src="/confluence/download/resources/confluence.ext.code:code/shBrushPhp.js"></script>
<script class="javascript" src="/confluence/download/resources/confluence.ext.code:code/shBrushJScript.js"></script>
<script class="javascript" src="/confluence/download/resources/confluence.ext.code:code/shBrushVb.js"></script>
<script class="javascript" src="/confluence/download/resources/confluence.ext.code:code/shBrushSql.js"></script>
<script class="javascript" src="/confluence/download/resources/confluence.ext.code:code/shBrushXml.js"></script>
<script class="javascript" src="/confluence/download/resources/confluence.ext.code:code/shBrushShell.js"></script>
<script class="javascript" src="/confluence/download/resources/confluence.ext.code:code/shBrushDelphi.js"></script>
<script class="javascript" src="/confluence/download/resources/confluence.ext.code:code/shBrushPython.js"></script>
<script class="javascript" src="/confluence/download/resources/confluence.ext.code:code/shBrushJava.js"></script>
<div class="code">
<textarea name="newcodemacro" class="xml:nocontrols:nogutter" rows="10" readonly="readonly">&lt;from uri="jms:queue:foo"/&gt;</textarea>
<script class="javascript">
    if(!window.newcodemacro_initialised)
    {
        window.newcodemacro_initialised = true;
        window.oldonloadmethod = window.onload;
        window.onload = function(){
            dp.SyntaxHighlighter.HighlightAll('newcodemacro');
            if(window.oldonloadmethod)
            {
                window.oldonloadmethod();
            }
        }
    }

</script>
</div>


<p>To adding the <tt>maxMessagesPerTask</tt> option and setting its value to -1.</p>
<div class="code">
<textarea name="newcodemacro" class="xml:nocontrols:nogutter" rows="10" readonly="readonly">&lt;from uri="jms:queue:foo&amp;amp;maxMessagesPerTask=-1"/&gt;</textarea>
<script class="javascript">
    if(!window.newcodemacro_initialised)
    {
        window.newcodemacro_initialised = true;
        window.oldonloadmethod = window.onload;
        window.onload = function(){
            dp.SyntaxHighlighter.HighlightAll('newcodemacro');
            if(window.oldonloadmethod)
            {
                window.oldonloadmethod();
            }
        }
    }

</script>
</div>


<p>This has been fixed in Camel 1.6.2/2.0.</p></td></tr></table></div>

<div class='panelMacro'><table class='tipMacro'><colgroup><col width='24'><col></colgroup><tr><td valign='top'><img src="/confluence/images/icons/emoticons/check.gif" width="16" height="16" align="absmiddle" alt="" border="0"></td><td><b>Using ActiveMQ</b><br /><p>If you are using <a href="http://activemq.apache.org/" rel="nofollow">Apache ActiveMQ</a> you should prefer to use the <a href="/confluence/display/CAMEL/ActiveMQ" title="ActiveMQ">ActiveMQ</a> component as it has been particularly optimized for <a href="/confluence/display/CAMEL/ActiveMQ" title="ActiveMQ">ActiveMQ</a>.<br/>
All the options and samples on this page applies as well for <a href="/confluence/display/CAMEL/ActiveMQ" title="ActiveMQ">ActiveMQ</a> component.</p></td></tr></table></div>


<h3><a name="JMS-URIformat"></a>URI format</h3>

<div class="code">
<textarea name="newcodemacro" class="java:nocontrols:nogutter" rows="10" readonly="readonly">jms:[topic:]destinationName?options</textarea>
<script class="javascript">
    if(!window.newcodemacro_initialised)
    {
        window.newcodemacro_initialised = true;
        window.oldonloadmethod = window.onload;
        window.onload = function(){
            dp.SyntaxHighlighter.HighlightAll('newcodemacro');
            if(window.oldonloadmethod)
            {
                window.oldonloadmethod();
            }
        }
    }

</script>
</div>


<p>So for example to send to queue FOO.BAR you would use</p>

<div class="code">
<textarea name="newcodemacro" class="java:nocontrols:nogutter" rows="10" readonly="readonly">jms:FOO.BAR</textarea>
<script class="javascript">
    if(!window.newcodemacro_initialised)
    {
        window.newcodemacro_initialised = true;
        window.oldonloadmethod = window.onload;
        window.onload = function(){
            dp.SyntaxHighlighter.HighlightAll('newcodemacro');
            if(window.oldonloadmethod)
            {
                window.oldonloadmethod();
            }
        }
    }

</script>
</div>


<p>You can be completely specific if you wish via</p>

<div class="code">
<textarea name="newcodemacro" class="java:nocontrols:nogutter" rows="10" readonly="readonly">jms:queue:FOO.BAR</textarea>
<script class="javascript">
    if(!window.newcodemacro_initialised)
    {
        window.newcodemacro_initialised = true;
        window.oldonloadmethod = window.onload;
        window.onload = function(){
            dp.SyntaxHighlighter.HighlightAll('newcodemacro');
            if(window.oldonloadmethod)
            {
                window.oldonloadmethod();
            }
        }
    }

</script>
</div>



<p>If you want to send to a topic called Stocks.Prices then you would use</p>

<div class="code">
<textarea name="newcodemacro" class="java:nocontrols:nogutter" rows="10" readonly="readonly">jms:topic:Stocks.Prices</textarea>
<script class="javascript">
    if(!window.newcodemacro_initialised)
    {
        window.newcodemacro_initialised = true;
        window.oldonloadmethod = window.onload;
        window.onload = function(){
            dp.SyntaxHighlighter.HighlightAll('newcodemacro');
            if(window.oldonloadmethod)
            {
                window.oldonloadmethod();
            }
        }
    }

</script>
</div>


<h4><a name="JMS-UsingTemporaryDestinations"></a>Using Temporary Destinations</h4>

<p>As of 1.4.0 of Camel you can use temporary queues using the following URL format</p>

<div class="code">
<textarea name="newcodemacro" class="java:nocontrols:nogutter" rows="10" readonly="readonly">jms:temp:queue:foo</textarea>
<script class="javascript">
    if(!window.newcodemacro_initialised)
    {
        window.newcodemacro_initialised = true;
        window.oldonloadmethod = window.onload;
        window.onload = function(){
            dp.SyntaxHighlighter.HighlightAll('newcodemacro');
            if(window.oldonloadmethod)
            {
                window.oldonloadmethod();
            }
        }
    }

</script>
</div>


<p>or temporary topics as</p>

<div class="code">
<textarea name="newcodemacro" class="java:nocontrols:nogutter" rows="10" readonly="readonly">jms:temp:topic:bar</textarea>
<script class="javascript">
    if(!window.newcodemacro_initialised)
    {
        window.newcodemacro_initialised = true;
        window.oldonloadmethod = window.onload;
        window.onload = function(){
            dp.SyntaxHighlighter.HighlightAll('newcodemacro');
            if(window.oldonloadmethod)
            {
                window.oldonloadmethod();
            }
        }
    }

</script>
</div>


<p>Where <b>foo</b> and <b>bar</b>, the text after the String <b>jms:temp:queue:</b> or <b>jms:temp:topic:</b>, are the names of the destinations. This enables multiple routes or processors or beans to refer to the same temporary destination. e.g. you can create 3 temporary destinations and use them in routes as inputs or outputs by referring to them by name.</p>

<h3><a name="JMS-Notes"></a>Notes</h3>


<div class='panelMacro'><table class='infoMacro'><colgroup><col width='24'><col></colgroup><tr><td valign='top'><img src="/confluence/images/icons/emoticons/information.gif" width="16" height="16" align="absmiddle" alt="" border="0"></td><td><b>If you are using ActiveMQ</b><br /><p>Note that the JMS component reuses Spring 2's JmsTemplate for sending messages. This is not ideal for use in a non-J2EE container and typically requires some caching JMS provider to avoid performance <a href="http://activemq.apache.org/jmstemplate-gotchas.html" rel="nofollow">being lousy</a>.</p>

<p>So if you intent to use <a href="http://activemq.apache.org/" rel="nofollow">Apache ActiveMQ</a> as your Message Broker - which is a good choice as ActiveMQ rocks <img class="emoticon" src="/confluence/images/icons/emoticons/smile.gif" height="20" width="20" align="absmiddle" alt="" border="0"/>, then we recommend that you either</p>

<ul>
	<li>use the <a href="/confluence/display/CAMEL/ActiveMQ" title="ActiveMQ">ActiveMQ</a> component which is already configured to use ActiveMQ efficiently</li>
	<li>use the PoolingConnectionFactory in ActiveMQ</li>
</ul>
</td></tr></table></div>

<p>If you wish to use durable topic subscriptions, you need to specify both <b>clientId</b> and <b>durableSubscriptionName</b>. Note that the value of the clientId must be unique and can only be used by a single JMS connection instance in your entire network. You may prefer to use <a href="http://activemq.apache.org/virtual-destinations.html" rel="nofollow">Virtual Topics</a> instead to avoid this limitation. More background on durable messaging <a href="http://activemq.apache.org/how-do-durable-queues-and-topics-work.html" rel="nofollow">here</a>.</p>

<p>When using message headers; the JMS specification states that header names must be valid Java identifiers. So by default camel will ignore any headers which do not match this rule. So try name your headers as if they are valid Java identifiers. One added bonus of this is that you can then use your headers inside a JMS Selector - which uses SQL92 syntax which mandates Java identifier syntax for headers.</p>

<p>From Camel 1.4 a simple strategy for mapping headers names is used by default. The strategy is to replace any dots in the headername with underscore, and vice-versa when the header name is restored from the JMS message that was sent over the wire. What does this means? No more loosing method names to invoke on a bean component, no more loosing the filename header for the File Component etc. </p>

<p>Current header name strategy used for accepting header names in Camel:</p>
<ul class="alternate" type="square">
	<li>replace all dots with underscores (e.g. <tt>org.apache.camel.MethodName</tt> =&gt; <tt>org_apache_camel_MethodName</tt>)</li>
	<li>test if the name is a valid java identifier using the JDK core classes</li>
	<li>if test success then the header is added and sent over the wire, if not its dropped (logged at DEBUG level)</li>
</ul>



<div class='panelMacro'><table class='warningMacro'><colgroup><col width='24'><col></colgroup><tr><td valign='top'><img src="/confluence/images/icons/emoticons/forbidden.gif" width="16" height="16" align="absmiddle" alt="" border="0"></td><td><b>For Consuming Messages cacheLevelName settings are vital!</b><br /><p>If you are using Spring before 2.5.1 and Camel before 1.3.0 then you might want to set the <b>cacheLevelName</b> to be CACHE_CONSUMER for maximum performance. </p>

<p>Due to a <a href="http://opensource.atlassian.com/projects/spring/browse/SPR-3890" rel="nofollow">bug in earlier Spring versions</a> causing a lack of transactional integrity, previous versions of Camel and Camel versions from 1.3.0 onwwards when used with earlier Spring versions than 2.5.1 will default to use CACHE_CONNECTION. See the JIRAs <a href="https://issues.apache.org/activemq/browse/CAMEL-163" rel="nofollow">CAMEL-163</a> and <a href="https://issues.apache.org/activemq/browse/CAMEL-294" rel="nofollow">CAMEL-294</a>.</p>

<p>Also if you are using XA or running in a J2EE container then you may want to set the <b>cacheLevelName</b> to be CACHE_NONE as we have seen using JBoss with TibCo EMS and JTA/XA you must disable caching.</p>

<p>Another end user reports issue with using WebSphere MQ 6.0.2.5, Camel 1.6.0 and Spring 2.5.6. Not running XA or inside a J2EE Container, but the cacheLevelName=CACHE_NONE seems to have solved the problem with WebSphere MQ.</p>

<p>See also more about <a href="http://activemq.apache.org/jmstemplate-gotchas.html" rel="nofollow">JmsTemplate gotchas</a>.</p></td></tr></table></div>


<h3><a name="JMS-Options"></a>Options</h3>

<p>You can configure lots of different properties on the JMS endpoint which map to properties on the <a href="http://camel.apache.org/maven/camel-jms/apidocs/org/apache/camel/component/jms/JmsConfiguration.html" rel="nofollow">JMSConfiguration POJO</a>. <b>Notice:</b> Many of these properties maps to properties on Spring JMS that Camel uses for sending and receiving messages. So you can get more information about these properties by consulting the Spring documentation.</p>

<div class="confluenceTableSmall"><table class='confluenceTable'><tbody>
<tr>
<th class='confluenceTh'> Option </th>
<th class='confluenceTh'> Default Value </th>
<th class='confluenceTh'> Description </th>
</tr>
<tr>
<td class='confluenceTd'> acceptMessagesWhileStopping </td>
<td class='confluenceTd'> false </td>
<td class='confluenceTd'> Should the consumer accept messages while it is stopping </td>
</tr>
<tr>
<td class='confluenceTd'> acknowledgementModeName </td>
<td class='confluenceTd'> "AUTO_ACKNOWLEDGE" </td>
<td class='confluenceTd'> The JMS acknowledgement name which is one of: TRANSACTED, CLIENT_ACKNOWLEDGE, AUTO_ACKNOWLEDGE, DUPS_OK_ACKNOWLEDGE </td>
</tr>
<tr>
<td class='confluenceTd'> acknowledgementMode </td>
<td class='confluenceTd'> -1 </td>
<td class='confluenceTd'> The JMS acknowledgement mode defined as an Integer. Allows to set vendor-specific extensions to the acknowledgment mode. For the regular modes prefer to use the acknowledgementModeName instead. </td>
</tr>
<tr>
<td class='confluenceTd'> alwaysCopyMessage </td>
<td class='confluenceTd'> false </td>
<td class='confluenceTd'> If true then Camel will always make a JMS message copy of the message when it's passed to the producer for sending. Copying the message is needed in some situations such as when a replyToDestinationSelectorName is set (Camel will by the way set the alwaysCopyMessage to true if a replyToDestinationSelectorName is set) </td>
</tr>
<tr>
<td class='confluenceTd'> autoStartup </td>
<td class='confluenceTd'> true </td>
<td class='confluenceTd'> Should the consumer container auto-startup </td>
</tr>
<tr>
<td class='confluenceTd'> cacheLevelName </td>
<td class='confluenceTd'> "CACHE_CONSUMER" </td>
<td class='confluenceTd'> Sets the cache level by name for the underlying JMS resources. Possible values are: <tt>CACHE_AUTO, CACHE_CONNECTION, CACHE_CONSUMER, CACHE_NONE and CACHE_SESSION</tt>. See the <a href="http://static.springframework.org/spring/docs/2.5.x/api/org/springframework/jms/listener/DefaultMessageListenerContainer.html" rel="nofollow">Spring documentation</a>. And see the warning above. </td>
</tr>
<tr>
<td class='confluenceTd'> cacheLevel </td>
<td class='confluenceTd'> -1 </td>
<td class='confluenceTd'> Sets the cache level by id for the underlying JMS resources </td>
</tr>
<tr>
<td class='confluenceTd'> clientId </td>
<td class='confluenceTd'> null </td>
<td class='confluenceTd'> Sets the JMS client ID to use. Note that this value if specified must be unique and can only be used by a single JMS connection instance. Its typically only required for durable topic subscriptions. You may prefer to use <a href="http://activemq.apache.org/virtual-destinations.html" rel="nofollow">Virtual Topics</a> instead </td>
</tr>
<tr>
<td class='confluenceTd'> consumerType </td>
<td class='confluenceTd'> Default </td>
<td class='confluenceTd'> The consumer type to use, either: <tt>Simple</tt>, <tt>Default</tt> or <tt>ServerSessionPool</tt>. The consumer type determines which Spring JMS listener should be used. <tt>Default</tt> will use <tt>org.springframework.jms.listener.DefaultMessageListenerContainer</tt>. <tt>Simple</tt> will use <tt>org.springframework.jms.listener.SimpleMessageListenerContainer</tt> and <tt>ServerSessionPool</tt> will use <tt>org.springframework.jms.listener.serversession.ServerSessionMessageListenerContainer</tt>. If option <tt>useVersion102=true</tt> then Camel will of course use the JMS 1.0.2 Spring classes instead. <tt>ServerSessionPool</tt> is <b>@deprecated</b> and will be removed in Camel 2.0. </td>
</tr>
<tr>
<td class='confluenceTd'> concurrentConsumers </td>
<td class='confluenceTd'> 1 </td>
<td class='confluenceTd'> Specifies the default number of concurrent consumers </td>
</tr>
<tr>
<td class='confluenceTd'> connectionFactory </td>
<td class='confluenceTd'> null </td>
<td class='confluenceTd'> The default JMS connection factory to use for the <em>listenerConnectionFactory</em> and <em>templateConnectionFactory</em> if neither are specified </td>
</tr>
<tr>
<td class='confluenceTd'> deliveryMode </td>
<td class='confluenceTd'> 2 </td>
<td class='confluenceTd'> Specifies the delivery mode when sending. 1 = non persistent. 2 = persistent. </td>
</tr>
<tr>
<td class='confluenceTd'> deliveryPersistent </td>
<td class='confluenceTd'> true </td>
<td class='confluenceTd'> Is persistent delivery used by default? </td>
</tr>
<tr>
<td class='confluenceTd'> destination </td>
<td class='confluenceTd'> null </td>
<td class='confluenceTd'> (2.0 onwards) specifies the JMS Destination object to use on this endpoint </td>
</tr>
<tr>
<td class='confluenceTd'> destinationName </td>
<td class='confluenceTd'> null </td>
<td class='confluenceTd'> (2.0 onwards) specifies the JMS destination name to use on this endpoint </td>
</tr>
<tr>
<td class='confluenceTd'> destinationResolver </td>
<td class='confluenceTd'> null </td>
<td class='confluenceTd'> A pluggable <tt>org.springframework.jms.support.destination.DestinationResolver</tt> that allows you to use your own resolver to e.g. lookup the real destination in a JNDI registry. </td>
</tr>
<tr>
<td class='confluenceTd'> disableReplyTo </td>
<td class='confluenceTd'> false </td>
<td class='confluenceTd'> Do you want to ignore the JMSReplyTo header and so treat messages as InOnly by default and not send a reply back? </td>
</tr>
<tr>
<td class='confluenceTd'> durableSubscriptionName </td>
<td class='confluenceTd'> null </td>
<td class='confluenceTd'> The durable subscriber name for specifying durable topic subscriptions </td>
</tr>
<tr>
<td class='confluenceTd'> eagerLoadingOfProperties </td>
<td class='confluenceTd'> false </td>
<td class='confluenceTd'> Enables eager loading of JMS properties as soon as a message is received which generally is inefficient as the JMS properties may not be required but sometimes can catch early any issues with the underlying JMS provider and the use of JMS properties. Can be used for testing purpose to ensure JMS properties can be understood and handled correctly. </td>
</tr>
<tr>
<td class='confluenceTd'> exceptionListener </td>
<td class='confluenceTd'> null </td>
<td class='confluenceTd'> The JMS Exception Listener used to be notified of any underlying JMS exceptions </td>
</tr>
<tr>
<td class='confluenceTd'> explicitQosEnabled </td>
<td class='confluenceTd'> false </td>
<td class='confluenceTd'> Set if the deliveryMode, priority or timeToLive should be used when sending messages. This option is from Spring JmsTemplate. The deliveryMode, priority and timeToLive is options set on this endpoint that is used. As opposed to <tt>preserveMessageQos</tt> that uses options exclusively from the Camel IN message headers only. </td>
</tr>
<tr>
<td class='confluenceTd'> exposeListenerSession </td>
<td class='confluenceTd'> true </td>
<td class='confluenceTd'> Set if the listener session should be exposed when consuming messages </td>
</tr>
<tr>
<td class='confluenceTd'> idleTaskExecutionLimit </td>
<td class='confluenceTd'> 1 </td>
<td class='confluenceTd'> Specify the limit for idle executions of a receive task, not having received any message within its execution. If this limit is reached, the task will shut down and leave receiving to other executing tasks (in case of dynamic scheduling; see the "maxConcurrentConsumers" setting). </td>
</tr>
<tr>
<td class='confluenceTd'> jmsMessageType </td>
<td class='confluenceTd'> null </td>
<td class='confluenceTd'> <b>Camel 2.0:</b> Allows you to force to use a specific javax.jms.Message implementation for sending a jms message. Possible values: <tt>Bytes, Map, Object, Stream, Text</tt>. By default Camel will determine from the IN body type which Jms message type to use. This option allows you to choose it. </td>
</tr>
<tr>
<td class='confluenceTd'> jmsKeyFormatStrategy </td>
<td class='confluenceTd'> default </td>
<td class='confluenceTd'> <b>Camel 2.0:</b> Pluggable strategy for encoding and decoding JMS keys so they can be compliant with the JMS spec. Camel provides two implementations out of the box: <tt>default</tt> and <tt>passthrough</tt>. Default will safely marshal dots and hyphens (. and -). Passthrough lets the key as is. Can be used for JMS brokers which do not care about JMS header keys containing illegal characters. You can provide you own implementation of the <tt>org.apache.camel.component.jms.JmsKeyFormatStrategy</tt> and refer to it using the # notation.</td>
</tr>
<tr>
<td class='confluenceTd'> jmsOperations </td>
<td class='confluenceTd'> null </td>
<td class='confluenceTd'> Allow to use your own implementation of the <tt>org.springframework.jms.core.JmsOperations</tt> interface. Camel uses JmsTemplate as default. Can be used for testing purpose, but not used much as stated in the spring API docs. </td>
</tr>
<tr>
<td class='confluenceTd'> lazyCreateTransactionManager </td>
<td class='confluenceTd'> true </td>
<td class='confluenceTd'> <b>Camel 2.0:</b> If it is true , Camel will create a <tt>JmsTransactionManager</tt> if there is no transactionManager injected when option <tt>transacted=true</tt>. </td>
</tr>
<tr>
<td class='confluenceTd'> listenerConnectionFactory </td>
<td class='confluenceTd'> null </td>
<td class='confluenceTd'> The JMS connection factory used for consuming messages </td>
</tr>
<tr>
<td class='confluenceTd'> mapJmsMessage </td>
<td class='confluenceTd'> true </td>
<td class='confluenceTd'> <b>Camel 2.0:</b> Specifies whether Camel should auto map the received JMS message to an appropiate payload type, such as <tt>javax.jms.TextMessage</tt> to a <tt>String</tt> etc. See section about how mapping works below for more details. </td>
</tr>
<tr>
<td class='confluenceTd'> maxConcurrentConsumers </td>
<td class='confluenceTd'> 1 </td>
<td class='confluenceTd'> Specifies the maximum number of concurrent consumers </td>
</tr>
<tr>
<td class='confluenceTd'> maxMessagesPerTask </td>
<td class='confluenceTd'> -1 </td>
<td class='confluenceTd'> The number of messages per task. -1 is unlimited. </td>
</tr>
<tr>
<td class='confluenceTd'> messageConverter </td>
<td class='confluenceTd'> null </td>
<td class='confluenceTd'> <b>Camel 1.6.2/2.0:</b> To use a custom Spring <tt>org.springframework.jms.support.converter.MessageConverter</tt> so you can be 100% in control how to map to/from a <tt>javax.jms.Message</tt>. </td>
</tr>
<tr>
<td class='confluenceTd'> messageIdEnabled </td>
<td class='confluenceTd'> true </td>
<td class='confluenceTd'> When sending, should message IDs be added </td>
</tr>
<tr>
<td class='confluenceTd'> messageTimestampEnabled </td>
<td class='confluenceTd'> true </td>
<td class='confluenceTd'> Should timestamps be enabled by default on sending messages </td>
</tr>
<tr>
<td class='confluenceTd'> password </td>
<td class='confluenceTd'> null </td>
<td class='confluenceTd'> The password which is set for the connector factory</td>
</tr>
<tr>
<td class='confluenceTd'> priority </td>
<td class='confluenceTd'> 4 </td>
<td class='confluenceTd'> Values of &gt; 1 specify the message priority when sending, if the explicitQosEnabled property is specified (with 0 as the lowest priority and 9 as the highest) </td>
</tr>
<tr>
<td class='confluenceTd'> preserveMessageQos </td>
<td class='confluenceTd'> false </td>
<td class='confluenceTd'>  <b>Camel 2.0</b>: Set to true if you want to send message using the QoS settings specified on the message, instead of the QoS settings on the JMS endpoint. The following 3 headers is used <tt>JMSPriority</tt>, <tt>JMSDeliveryMode</tt> and <tt>JMSExpiration</tt>. You can provide all or only some of them. If not provided then Camel will fallback to use the values from this endpoint instead. So when using this option the headers will override the values from the endpoint. The option <tt>explicitQosEnabled</tt> on the other hand will only use options set on the endpoint and not values from the message header. </td>
</tr>
<tr>
<td class='confluenceTd'> pubSubNoLocal </td>
<td class='confluenceTd'> false </td>
<td class='confluenceTd'> Set whether to inhibit the delivery of messages published by its own connection </td>
</tr>
<tr>
<td class='confluenceTd'> receiveTimeout </td>
<td class='confluenceTd'> none </td>
<td class='confluenceTd'> The timeout when receiving messages </td>
</tr>
<tr>
<td class='confluenceTd'> recoveryInterval </td>
<td class='confluenceTd'> 5000 </td>
<td class='confluenceTd'> Specify the interval between recovery attempts, in milliseconds. The default is 5000 ms, that is, 5 seconds. </td>
</tr>
<tr>
<td class='confluenceTd'> replyTo </td>
<td class='confluenceTd'> null </td>
<td class='confluenceTd'> Provides an explicit reply to destination which overrides any incoming value of <tt>Message.getJMSReplyTo()</tt> </td>
</tr>
<tr>
<td class='confluenceTd'> replyToTempDestinationAffinity </td>
<td class='confluenceTd'> endpoint </td>
<td class='confluenceTd'> defines the component created temporary replyTo destination sharing strategy. Possible values are: <tt>component</tt>, <tt>endpoint</tt> or <tt>producer</tt>. <b>component</b> = a single temp queue is shared among all producers for a given component instance. <b>endpoint</b> = a single temp queue is shared among all producers for a given endpoint instance. <b>producer</b> = a single temp queue is created per producer. </td>
</tr>
<tr>
<td class='confluenceTd'> replyToDestinationSelectorName </td>
<td class='confluenceTd'> null </td>
<td class='confluenceTd'> Sets the JMS Selector using the fixed name to be used so you can filter out your own replies from the others, when using a shared queue (i.e. if you are not using a temporary reply queue). </td>
</tr>
<tr>
<td class='confluenceTd'> replyToDeliveryPersistent </td>
<td class='confluenceTd'> true </td>
<td class='confluenceTd'> Is persistent delivery used by default for reply? </td>
</tr>
<tr>
<td class='confluenceTd'> requestTimeout </td>
<td class='confluenceTd'> 20000 </td>
<td class='confluenceTd'> The timeout when sending messages </td>
</tr>
<tr>
<td class='confluenceTd'> selector </td>
<td class='confluenceTd'> null </td>
<td class='confluenceTd'> Sets the JMS Selector which is an SQL 92 predicate used to apply to messages to filter them at the message broker. You may have to encode special characters such as = as %3D </td>
</tr>
<tr>
<td class='confluenceTd'> serverSessionFactory </td>
<td class='confluenceTd'> null </td>
<td class='confluenceTd'> <b>@deprecated</b> - will be removed in Camel 2.0. The JMS ServerSessionFactory if you wish to use ServerSessionFactory for consumption </td>
</tr>
<tr>
<td class='confluenceTd'> subscriptionDurable </td>
<td class='confluenceTd'> false </td>
<td class='confluenceTd'> Enabled by default if you specify a durableSubscriberName and a clientId </td>
</tr>
<tr>
<td class='confluenceTd'> taskExecutor </td>
<td class='confluenceTd'> null </td>
<td class='confluenceTd'> Allows you to specify a custom task executor for consuming messages </td>
</tr>
<tr>
<td class='confluenceTd'> templateConnectionFactory </td>
<td class='confluenceTd'> null </td>
<td class='confluenceTd'> The JMS connection factory used for sending messages </td>
</tr>
<tr>
<td class='confluenceTd'> timeToLive </td>
<td class='confluenceTd'> null </td>
<td class='confluenceTd'> Is a time to live specified when sending messages </td>
</tr>
<tr>
<td class='confluenceTd'> transacted </td>
<td class='confluenceTd'> false </td>
<td class='confluenceTd'> If transacted mode will be used for sending/receiving messages using the InOnly <a href="/confluence/display/CAMEL/Exchange+Pattern" title="Exchange Pattern">Exchange Pattern</a>. See section Enabling Transacted Consumption for more details. </td>
</tr>
<tr>
<td class='confluenceTd'> transactedInOut </td>
<td class='confluenceTd'> false </td>
<td class='confluenceTd'> If transacted mode will be used when sending/receiving messages using the InOut <a href="/confluence/display/CAMEL/Exchange+Pattern" title="Exchange Pattern">Exchange Pattern</a>. See section Enabling Transacted Consumption for more details. </td>
</tr>
<tr>
<td class='confluenceTd'> transactionManager </td>
<td class='confluenceTd'> null </td>
<td class='confluenceTd'> The Spring transaction manager to use </td>
</tr>
<tr>
<td class='confluenceTd'> transactionName </td>
<td class='confluenceTd'> null </td>
<td class='confluenceTd'> The name of the transaction to use </td>
</tr>
<tr>
<td class='confluenceTd'> transactionTimeout </td>
<td class='confluenceTd'> null </td>
<td class='confluenceTd'> The timeout value of the transaction if using transacted mode </td>
</tr>
<tr>
<td class='confluenceTd'> transferException </td>
<td class='confluenceTd'> false </td>
<td class='confluenceTd'> <b>Camel 2.0:</b> If enabled and you are using <a href="/confluence/display/CAMEL/Request+Reply" title="Request Reply">Request Reply</a> messaging (InOut) and an <a href="/confluence/display/CAMEL/Exchange" title="Exchange">Exchange</a> failed on the consumer side then the caused Exception will be send back as response as a <tt>javax.jms.ObjectMessage</tt>. If the client is Camel then that returned Exception will be rethrown. This allows you to use Camel <a href="/confluence/display/CAMEL/JMS" title="JMS">JMS</a> as a bridge in your routing, e.g. using persistent queues to enable robust routing. Notice that if you also have <b>transferExchange</b> enabled then this option takes precedence. The exceptions caught is required to be serializable. The original caused Exception on the consumer side can be wrapped in an outer exception such as <tt>org.apache.camel.RuntimeCamelException</tt> when returned to the producer. </td>
</tr>
<tr>
<td class='confluenceTd'> transferExchange </td>
<td class='confluenceTd'> false </td>
<td class='confluenceTd'> <b>Camel 2.0:</b> You can transfer the exchange over the wire instead of just the body and headers. The following fields is transferred: in body, out body, fault body, in headers, out headers, fault headers, exchange properties, exchange exception. This requires that the objects are Serializable. Camel will exclude any non serializable objects and log it at WARN level. </td>
</tr>
<tr>
<td class='confluenceTd'> username </td>
<td class='confluenceTd'> null </td>
<td class='confluenceTd'> The username which is set for the connector factory</td>
</tr>
<tr>
<td class='confluenceTd'> useMessageIDAsCorrelationID </td>
<td class='confluenceTd'> false </td>
<td class='confluenceTd'> Should <tt>JMSMessageID</tt> be used as <tt>JMSCorrelationID</tt> for <b>InOut</b> messages. Camel will by default use a GUID  </td>
</tr>
<tr>
<td class='confluenceTd'> useVersion102 </td>
<td class='confluenceTd'> false </td>
<td class='confluenceTd'> Should the old JMS API be used </td>
</tr>
</tbody></table></div>

<h3><a name="JMS-MessageMappingbetweenJMSandCamel"></a>Message Mapping between JMS and Camel</h3>
<p>Camel will automatically map messages between <tt>javax.jms.Message</tt> and <tt>org.apache.camel.Message</tt>. </p>

<p>When sending a JMS message Camel will convert the body to the following JMS message:</p>
<table class='confluenceTable'><tbody>
<tr>
<th class='confluenceTh'> Body Type </th>
<th class='confluenceTh'> JMS Message </th>
<th class='confluenceTh'> Comment </th>
</tr>
<tr>
<td class='confluenceTd'> String </td>
<td class='confluenceTd'> <tt>javax.jms.TextMessage</tt> </td>
<td class='confluenceTd'>&nbsp;</td>
</tr>
<tr>
<td class='confluenceTd'> org.w3c.dom.Node </td>
<td class='confluenceTd'> <tt>javax.jms.TextMessage</tt> </td>
<td class='confluenceTd'> The DOM will be converted to String </td>
</tr>
<tr>
<td class='confluenceTd'> Map </td>
<td class='confluenceTd'> <tt>javax.jms.MapMessage</tt> </td>
<td class='confluenceTd'>&nbsp;</td>
</tr>
<tr>
<td class='confluenceTd'> java.io.Serializable </td>
<td class='confluenceTd'> <tt>javax.jms.ObjectMessage</tt> </td>
<td class='confluenceTd'>&nbsp;</td>
</tr>
<tr>
<td class='confluenceTd'> byte[] </td>
<td class='confluenceTd'> <tt>javax.jms.BytesMessage</tt> </td>
<td class='confluenceTd'>&nbsp;</td>
</tr>
<tr>
<td class='confluenceTd'> java.io.File </td>
<td class='confluenceTd'> <tt>javax.jms.BytesMessage</tt> </td>
<td class='confluenceTd'>&nbsp;</td>
</tr>
<tr>
<td class='confluenceTd'> java.io.Reader </td>
<td class='confluenceTd'> <tt>javax.jms.BytesMessage</tt> </td>
<td class='confluenceTd'>&nbsp;</td>
</tr>
<tr>
<td class='confluenceTd'> java.io.InputStream </td>
<td class='confluenceTd'> <tt>javax.jms.BytesMessage</tt> </td>
<td class='confluenceTd'>&nbsp;</td>
</tr>
<tr>
<td class='confluenceTd'> java.nio.ByteBuffer </td>
<td class='confluenceTd'> <tt>javax.jms.BytesMessage</tt> </td>
<td class='confluenceTd'>&nbsp;</td>
</tr>
</tbody></table>

<p>When receiving a JMS message Camel will convert the JMS message to the following body type:</p>
<table class='confluenceTable'><tbody>
<tr>
<th class='confluenceTh'> JMS Message </th>
<th class='confluenceTh'> Body Type </th>
<th class='confluenceTh'> Comment </th>
</tr>
<tr>
<td class='confluenceTd'> <tt>javax.jms.TextMessage</tt> </td>
<td class='confluenceTd'> String </td>
<td class='confluenceTd'>&nbsp;</td>
</tr>
<tr>
<td class='confluenceTd'> <tt>javax.jms.BytesMessage</tt> </td>
<td class='confluenceTd'> byte[] </td>
<td class='confluenceTd'>&nbsp;</td>
</tr>
<tr>
<td class='confluenceTd'> <tt>javax.jms.MapMessage</tt> </td>
<td class='confluenceTd'> Map&lt;String, Object&gt; </td>
<td class='confluenceTd'>&nbsp;</td>
</tr>
<tr>
<td class='confluenceTd'> <tt>javax.jms.ObjectMessage</tt> </td>
<td class='confluenceTd'> Object </td>
<td class='confluenceTd'>&nbsp;</td>
</tr>
</tbody></table>

<h4><a name="JMS-DisablingautomappingJMSmessage"></a>Disabling auto mapping JMS message</h4>
<p><b>Available as of Camel 2.0</b></p>

<p>You can use the <tt>mapJmsMessage</tt> option to disable the auto mapping above. If disable Camel will not try to map the received JMS message but use it directly as payload. This allows you to avoid the overhead of mapping and let Camel just pass through the JMS message. For instance it even allows you to route <tt>javax.jms.ObjectMessage</tt> JMS messages with classes you do <b>not</b> have on the classpath.</p>

<h4><a name="JMS-UsingacustomMessageConverter"></a>Using a custom MessageConverter</h4>
<p><b>Available as of Camel 1.6.2/2.0</b></p>

<p>You can use the <tt>messageConverter</tt> option to do the mapping yourself in a Spring <tt>org.springframework.jms.support.converter.MessageConverter</tt> class. </p>

<p>For example in the route below we use a custom message converter when sending a message to the JMS order queue.</p>
<div class="code">
<textarea name="newcodemacro" class="java:nocontrols:nogutter" rows="10" readonly="readonly">from("file://inbox/order").to("jms:queue:order?messageConcter=#myMessageConverter");</textarea>
<script class="javascript">
    if(!window.newcodemacro_initialised)
    {
        window.newcodemacro_initialised = true;
        window.oldonloadmethod = window.onload;
        window.onload = function(){
            dp.SyntaxHighlighter.HighlightAll('newcodemacro');
            if(window.oldonloadmethod)
            {
                window.oldonloadmethod();
            }
        }
    }

</script>
</div>


<p>You can also use a custom message converter when consuming from a JMS destination.</p>

<h4><a name="JMS-Controllingthemappingstrategyselected"></a>Controlling the mapping strategy selected</h4>
<p><b>Available as of Camel 2.0</b></p>

<p>You can use the option <b>jmsMessageType</b> on the endpoint to force using a specific message type for all messages.<br/>
In the route below we will poll files from a folder and send them as <tt>javax.jms.TextMessage</tt> as we have forced the JMS producer endpoint to use Text messages.</p>
<div class="code">
<textarea name="newcodemacro" class="java:nocontrols:nogutter" rows="10" readonly="readonly">from("file://inbox/order").to("jms:queue:order?jmsMessageType=Text");</textarea>
<script class="javascript">
    if(!window.newcodemacro_initialised)
    {
        window.newcodemacro_initialised = true;
        window.oldonloadmethod = window.onload;
        window.onload = function(){
            dp.SyntaxHighlighter.HighlightAll('newcodemacro');
            if(window.oldonloadmethod)
            {
                window.oldonloadmethod();
            }
        }
    }

</script>
</div>


<p>You can also provide a per. message type as a header with the key <tt>CamelJmsMessageType</tt>.</p>
<div class="code">
<textarea name="newcodemacro" class="java:nocontrols:nogutter" rows="10" readonly="readonly">from("file://inbox/order").setHeader("CamelJmsMessageType", JmsMessageType.Text).to("jms:queue:order");</textarea>
<script class="javascript">
    if(!window.newcodemacro_initialised)
    {
        window.newcodemacro_initialised = true;
        window.oldonloadmethod = window.onload;
        window.onload = function(){
            dp.SyntaxHighlighter.HighlightAll('newcodemacro');
            if(window.oldonloadmethod)
            {
                window.oldonloadmethod();
            }
        }
    }

</script>
</div>


<p>The possible values is defined in an enum class <tt>org.apache.camel.jms.JmsMessageType</tt>.</p>

<h3><a name="JMS-Messageformatwhensending"></a>Message format when sending</h3>
<p>The exchange that is sent over the JMS wire must conform to the <a href="http://java.sun.com/j2ee/1.4/docs/api/javax/jms/Message.html" rel="nofollow">JMS Message spec</a>.</p>

<p>For the <tt>exchange.in.header</tt> the following rules apply for the <b>keys</b>:</p>
<ul class="alternate" type="square">
	<li>Keys stating with JMS or JMSX is reserved.</li>
	<li><tt>exchange.in.headers</tt> keys must be literals and all be valid Java identifiers. (do not use dots in the key name)</li>
	<li>In Camel 1.4 onwards Camel will automatically replace all dots with underscore for key names. And vice-versa when Camel consumes JMS messages.</li>
	<li>In Camel 2.0 onwards Camel will also replace all hyphens with the special token: <tt>&#95;HYPHEN&#95;</tt>. And vice-versa when Camel consumes JMS messages.</li>
	<li>See also option <tt>jmsKeyFormatStrategy</tt> introduced in <b>Camel 2.0</b>.</li>
</ul>


<p>For the <tt>exchange.in.header</tt> the following rules apply for the <b>values</b>:</p>
<ul class="alternate" type="square">
	<li>The values must be primitives or their counter objects (such as Integer, Long, Character). String, CharSequence, Date, BigDecimal or BigInteger is all converted to their <tt>toString()</tt> representation. All other types is dropped.</li>
</ul>


<p>Camel will log with category <tt>org.apache.camel.component.jms.JmsBinding</tt> at <b>DEBUG</b> level if it drops a given header value. Example:</p>
<div class="code">
<textarea name="newcodemacro" class="java:nocontrols:nogutter" rows="10" readonly="readonly">2008-07-09 06:43:04,046 [main           ] DEBUG JmsBinding  
  - Ignoring non primitive header: order of class: org.apache.camel.component.jms.issues.DummyOrder with value: DummyOrder{orderId=333, itemId=4444, quantity=2}</textarea>
<script class="javascript">
    if(!window.newcodemacro_initialised)
    {
        window.newcodemacro_initialised = true;
        window.oldonloadmethod = window.onload;
        window.onload = function(){
            dp.SyntaxHighlighter.HighlightAll('newcodemacro');
            if(window.oldonloadmethod)
            {
                window.oldonloadmethod();
            }
        }
    }

</script>
</div>



<h3><a name="JMS-Messageformatwhenreceiving"></a>Message format when receiving</h3>

<p>Camel will add the following properties to the Exchange when it receives a message:</p>
<table class='confluenceTable'><tbody>
<tr>
<th class='confluenceTh'> Property </th>
<th class='confluenceTh'> Type </th>
<th class='confluenceTh'> Description </th>
</tr>
<tr>
<td class='confluenceTd'> <tt>org.apache.camel.jms.replyDestination</tt> </td>
<td class='confluenceTd'> <tt>javax.jms.Destination</tt> </td>
<td class='confluenceTd'> The reply destination </td>
</tr>
</tbody></table>

<p>Camel will add the following JMS properties to the <b>IN</b> Message headers when it receives a JMS message:</p>
<table class='confluenceTable'><tbody>
<tr>
<th class='confluenceTh'> Header </th>
<th class='confluenceTh'> Type </th>
<th class='confluenceTh'> Description </th>
</tr>
<tr>
<td class='confluenceTd'> JMSCorrelationID </td>
<td class='confluenceTd'> String </td>
<td class='confluenceTd'> The JMS correlation id </td>
</tr>
<tr>
<td class='confluenceTd'> JMSDeliveryMode</td>
<td class='confluenceTd'> int </td>
<td class='confluenceTd'> The JMS delivery mode </td>
</tr>
<tr>
<td class='confluenceTd'> JMSDestination</td>
<td class='confluenceTd'> <tt>javax.jms.Destination</tt> </td>
<td class='confluenceTd'> The JMS destination </td>
</tr>
<tr>
<td class='confluenceTd'> JMSExpiration</td>
<td class='confluenceTd'> long </td>
<td class='confluenceTd'> The JMS expiration </td>
</tr>
<tr>
<td class='confluenceTd'> JMSMessageID</td>
<td class='confluenceTd'> String </td>
<td class='confluenceTd'> The JMS unique message id </td>
</tr>
<tr>
<td class='confluenceTd'> JMSPriority</td>
<td class='confluenceTd'> int </td>
<td class='confluenceTd'> The JMS priority (with 0 as the lowest priority and 9 as the highest) </td>
</tr>
<tr>
<td class='confluenceTd'> JMSRedelivered</td>
<td class='confluenceTd'> boolean </td>
<td class='confluenceTd'> Is the JMS message redelivered </td>
</tr>
<tr>
<td class='confluenceTd'> JMSReplyTo</td>
<td class='confluenceTd'> <tt>javax.jms.Destination</tt> </td>
<td class='confluenceTd'> The JMS reply to destination </td>
</tr>
<tr>
<td class='confluenceTd'> JMSTimestamp</td>
<td class='confluenceTd'> long </td>
<td class='confluenceTd'> The JMS timestamp </td>
</tr>
<tr>
<td class='confluenceTd'> JMSType</td>
<td class='confluenceTd'> String </td>
<td class='confluenceTd'> The JMS type </td>
</tr>
<tr>
<td class='confluenceTd'> JMSXGroupID</td>
<td class='confluenceTd'> String </td>
<td class='confluenceTd'> The JMS group id </td>
</tr>
</tbody></table>
<p>As all the above information is standard JMS you can check the <a href="http://java.sun.com/javaee/5/docs/api/javax/jms/Message.html" rel="nofollow">JMS documentation</a> for further details.</p>


<h3><a name="JMS-AboutusingCameltosendandreceivemessagesandJMSReplyTo"></a>About using Camel to send and receive messages and JMSReplyTo </h3>
<p>The JMS component is complex and you have to pay attention how it works depending what you do. So this is a short summary of some of the areas/pitfalls to look for.</p>

<p>When Camel sends a message using its <tt>JMSProducer</tt> it will check the following conditions</p>
<ul class="alternate" type="square">
	<li>the message exchange pattern</li>
	<li>whether a <tt>JMSReplyTo</tt> was set in endpoint or message header</li>
	<li>whether any of these options have been set on the JMS endpoint: <tt>disableReplyTo, preserveMessageQos, explicitQosEnabled</tt></li>
</ul>


<p>All this can be a tad complex to understand and configured to support your use case.</p>

<h4><a name="JMS-JmsProducer"></a>JmsProducer</h4>
<p>The <tt>JmsProducer</tt> behaves like this depending on configuration:</p>
<table class='confluenceTable'><tbody>
<tr>
<th class='confluenceTh'> Exchange Pattern </th>
<th class='confluenceTh'> Other options </th>
<th class='confluenceTh'> Description </th>
</tr>
<tr>
<td class='confluenceTd'> InOut </td>
<td class='confluenceTd'><ul class="alternate" type="square">
	<li></li>
</ul>
</td>
<td class='confluenceTd'> Camel will expect a reply and set a temporary JMSReplyTo and after sending the message, it will start to listen for the reply message on the temporary queue. </td>
</tr>
<tr>
<td class='confluenceTd'> InOut </td>
<td class='confluenceTd'> JMSReplyTo set </td>
<td class='confluenceTd'> Camel will expect a reply and after sending the message, it will start to listen for the reply message on the JMSReplyTo queue. </td>
</tr>
<tr>
<td class='confluenceTd'> InOnly </td>
<td class='confluenceTd'><ul class="alternate" type="square">
	<li></li>
</ul>
</td>
<td class='confluenceTd'> Camel will send the message and <b>not</b> expect a reply. </td>
</tr>
<tr>
<td class='confluenceTd'> InOnly </td>
<td class='confluenceTd'> JMSReplyTo set </td>
<td class='confluenceTd'> Camel sees this as a contradiction and will suppress the <tt>JMSReplyTo</tt>. In fact Camel will disable it by clearing it before sending. Camel will send the message and <b>not</b> expect a reply. Camel logs this in the log at WARN level and you should see: <tt>WARN  JmsProducer - Disabling JMSReplyTo as this Exchange is not OUT capable with JMSReplyTo: myReplyQueue to destination: myQueue ...</tt>. <b>Note:</b> You can use option <tt>preserveMessageQos=true</tt> or <tt>explicitQosEnabled=true</tt> to force Camel to send the JMSReplyTo anyway, and the WARN log will disappear. </td>
</tr>
</tbody></table>

<h4><a name="JMS-JmsConsumer"></a>JmsConsumer</h4>
<p>The <tt>JmsConsumer</tt> behaves like this depending on configuration:</p>
<table class='confluenceTable'><tbody>
<tr>
<th class='confluenceTh'> Exchange Pattern </th>
<th class='confluenceTh'> Other options </th>
<th class='confluenceTh'> Description </th>
</tr>
<tr>
<td class='confluenceTd'> InOut </td>
<td class='confluenceTd'><ul class="alternate" type="square">
	<li></li>
</ul>
</td>
<td class='confluenceTd'> Camel will send the reply back to the JMSReplyTo queue. </td>
</tr>
<tr>
<td class='confluenceTd'> InOnly </td>
<td class='confluenceTd'><ul class="alternate" type="square">
	<li></li>
</ul>
</td>
<td class='confluenceTd'> Camel will not send a reply back as the pattern is inOnly.</td>
</tr>
<tr>
<td class='confluenceTd'><ul class="alternate" type="square">
	<li></li>
</ul>
</td>
<td class='confluenceTd'> disableReplyTo=true </td>
<td class='confluenceTd'> This option will suppress Camel for sending a reply back. </td>
</tr>
</tbody></table>

<p>So pay attention what the message exchange pattern is on your messages.</p>

<p>If you send a message to a JMS destination in the middle of your route you can specify the exchange pattern to use, see more at <a href="/confluence/display/CAMEL/Request+Reply" title="Request Reply">Request Reply</a>.<br/>
This is useful if you want to send an <tt>inOnly</tt> message to a JMS topic:</p>
<div class="code">
<textarea name="newcodemacro" class="java:nocontrols:nogutter" rows="10" readonly="readonly">from("activemq:queue:in")
   .to("bean:validateOrder")
   .to(ExchangePattern.InOnly, "activemq:topic:order")
   .to("bean:handleOrder");</textarea>
<script class="javascript">
    if(!window.newcodemacro_initialised)
    {
        window.newcodemacro_initialised = true;
        window.oldonloadmethod = window.onload;
        window.onload = function(){
            dp.SyntaxHighlighter.HighlightAll('newcodemacro');
            if(window.oldonloadmethod)
            {
                window.oldonloadmethod();
            }
        }
    }

</script>
</div>


<h3><a name="JMS-Reuseendpointandsendingtodifferentdestinationscomputedatruntime"></a>Reuse endpoint and sending to different destinations computed at runtime</h3>
<p><b>Available as of Camel 1.6.2/2.0</b><br/>
If you need to send messages to a lot of different JMS destinations it makes sense to reuse a jms endpoint and provide the real destination as a header with the message. This allows Camel to reuse the same endpoint but send to different destinations. This will greatly reduce the number of endpoints created, memory and thread usage.</p>

<p>You can provide the destination in the following headers:</p>
<table class='confluenceTable'><tbody>
<tr>
<th class='confluenceTh'> Header </th>
<th class='confluenceTh'> Type </th>
<th class='confluenceTh'> Description </th>
</tr>
<tr>
<td class='confluenceTd'> CamelJmsDestination </td>
<td class='confluenceTd'> <tt>javax.jms.Destination</tt> </td>
<td class='confluenceTd'> <b>Camel 2.0:</b> A destination object </td>
</tr>
<tr>
<td class='confluenceTd'> CamelJmsDestinationName </td>
<td class='confluenceTd'> String </td>
<td class='confluenceTd'> <b>Camel 1.6.2/2.0:</b> A string with the destination name </td>
</tr>
</tbody></table>

<h4><a name="JMS-Reusingendpointbutsendingtoadestinationofchoice"></a>Reusing endpoint but sending to a destination of choice</h4>
<p>In the route below we send messages to a jms destination</p>
<div class="code">
<textarea name="newcodemacro" class="java:nocontrols:nogutter" rows="10" readonly="readonly">from("file://inbox")
  .to("bean:validateFile")
  .to("activemq:queue:dummy");</textarea>
<script class="javascript">
    if(!window.newcodemacro_initialised)
    {
        window.newcodemacro_initialised = true;
        window.oldonloadmethod = window.onload;
        window.onload = function(){
            dp.SyntaxHighlighter.HighlightAll('newcodemacro');
            if(window.oldonloadmethod)
            {
                window.oldonloadmethod();
            }
        }
    }

</script>
</div>


<p>Notice that we have used a <tt>dummy</tt> as queue name in the activemq destination. Its just something we need to provide.</p>

<p>Then in our <tt>validateFile</tt> bean we must set the header with the real destination</p>
<div class="code">
<textarea name="newcodemacro" class="java:nocontrols:nogutter" rows="10" readonly="readonly">public void validateIt(Exchange exchange) {
   String id = ....
   exchange.getIn().setHeader("CamelJmsDestinationName", "order:" + id");
}</textarea>
<script class="javascript">
    if(!window.newcodemacro_initialised)
    {
        window.newcodemacro_initialised = true;
        window.oldonloadmethod = window.onload;
        window.onload = function(){
            dp.SyntaxHighlighter.HighlightAll('newcodemacro');
            if(window.oldonloadmethod)
            {
                window.oldonloadmethod();
            }
        }
    }

</script>
</div>


<p>Then Camel will see this header and use it as destination instead of the one configured on the endpoint. So in this example Camel will use <tt>activemq:queue:order:2</tt> assuming the id was 2.</p>

<p>If both is provided as a header then the <tt>CamelJmsDestination</tt> will be prefered</p>


<h3><a name="JMS-ConfiguringdifferentJMSproviders"></a>Configuring different JMS providers</h3>

<p>You can configure your JMS provider inside the <a href="/confluence/display/CAMEL/Spring" title="Spring">Spring</a> XML as follows... </p>

<style type="text/css">
@import url(/confluence/download/resources/confluence.ext.code:code/shStyles.css);
</style>
<!--[if IE]>
<style type="text/css">
    .code textarea, .code input { padding: 0 !important; }
</style>
<![endif]-->
<script class="javascript" src="/confluence/download/resources/confluence.ext.code:code/shCore.js"></script>
<script class="javascript" src="/confluence/download/resources/confluence.ext.code:code/shBrushCSharp.js"></script>
<script class="javascript" src="/confluence/download/resources/confluence.ext.code:code/shBrushPhp.js"></script>
<script class="javascript" src="/confluence/download/resources/confluence.ext.code:code/shBrushJScript.js"></script>
<script class="javascript" src="/confluence/download/resources/confluence.ext.code:code/shBrushVb.js"></script>
<script class="javascript" src="/confluence/download/resources/confluence.ext.code:code/shBrushSql.js"></script>
<script class="javascript" src="/confluence/download/resources/confluence.ext.code:code/shBrushXml.js"></script>
<script class="javascript" src="/confluence/download/resources/confluence.ext.code:code/shBrushShell.js"></script>
<script class="javascript" src="/confluence/download/resources/confluence.ext.code:code/shBrushDelphi.js"></script>
<script class="javascript" src="/confluence/download/resources/confluence.ext.code:code/shBrushPython.js"></script>
<script class="javascript" src="/confluence/download/resources/confluence.ext.code:code/shBrushJava.js"></script>
<div class="code">
<textarea name="newcodemacro" class="xml:nocontrols:nogutter" rows="10" readonly="readonly">&lt;camelContext id="camel" xmlns="http://camel.apache.org/schema/spring"&gt;
&lt;/camelContext&gt;

&lt;bean id="activemq" class="org.apache.camel.component.jms.JmsComponent"&gt;
  &lt;property name="connectionFactory"&gt;
    &lt;bean class="org.apache.activemq.ActiveMQConnectionFactory"&gt;
      &lt;property name="brokerURL" value="vm://localhost?broker.persistent=false"/&gt;
    &lt;/bean&gt;
  &lt;/property&gt;
&lt;/bean&gt;</textarea>
<script class="javascript">
    if(!window.newcodemacro_initialised)
    {
        window.newcodemacro_initialised = true;
        window.oldonloadmethod = window.onload;
        window.onload = function(){
            dp.SyntaxHighlighter.HighlightAll('newcodemacro');
            if(window.oldonloadmethod)
            {
                window.oldonloadmethod();
            }
        }
    }

</script>
</div>


<p>Basically you can configure as many JMS component instances as you wish and give them <b>a unique name via the id attribute</b>. The above example configures an <em>'activemq'</em> component. You could do the same to configure MQSeries, TibCo, BEA, Sonic etc.</p>

<p>Once you have a named JMS component you can then refer to endpoints within that component using URIs. For example for the component name'activemq' you can then refer to destinations as <b>activemq:[queue:&#124;topic:]destinationName</b>. So you could use the same approach for working with all other JMS providers.</p>

<p>This works by the SpringCamelContext lazily fetching components from the spring context for the scheme name you use for <a href="/confluence/display/CAMEL/Endpoint" title="Endpoint">Endpoint</a> <a href="/confluence/display/CAMEL/URIs" title="URIs">URIs</a> and having the <a href="/confluence/display/CAMEL/Component" title="Component">Component</a> resolve the endpoint URIs. </p>


<h4><a name="JMS-UsingJNDItofindtheConnectionFactory"></a>Using JNDI to find the ConnectionFactory</h4>

<p>If you are using a J2EE container you might want to lookup in JNDI to find your ConnectionFactory rather than use the usual &lt;bean&gt; mechanism in spring. You can do this using Spring's factory bean or the new Spring XML namespace. e.g.</p>

<div class="code">
<textarea name="newcodemacro" class="xml:nocontrols:nogutter" rows="10" readonly="readonly">&lt;bean id="weblogic" class="org.apache.camel.component.jms.JmsComponent"&gt;
  &lt;property name="connectionFactory" ref="myConnectionFactory"/&gt;
&lt;/bean&gt;

&lt;jee:jndi-lookup id="myConnectionFactory" jndi-name="jms/connectionFactory"/&gt;</textarea>
<script class="javascript">
    if(!window.newcodemacro_initialised)
    {
        window.newcodemacro_initialised = true;
        window.oldonloadmethod = window.onload;
        window.onload = function(){
            dp.SyntaxHighlighter.HighlightAll('newcodemacro');
            if(window.oldonloadmethod)
            {
                window.oldonloadmethod();
            }
        }
    }

</script>
</div>



<h4><a name="JMS-UsingJNDItolookupthephysicalqueues"></a>Using JNDI to lookup the physical queues</h4>
<p>You need to use the <tt>destinationResolver</tt> option to use the Spring JNDI resolver that can lookup in the JNDI, or use your own custom implementation. </p>

<p>See this nabble post for more details:
<a href="http://www.nabble.com/JMS-queue---JNDI-instead-of-physical-name-td24484994.html" rel="nofollow">http://www.nabble.com/JMS-queue---JNDI-instead-of-physical-name-td24484994.html</a></p>


<h4><a name="JMS-UsingWebSphereMQ"></a>Using WebSphere MQ</h4>
<p>See this <a href="http://www.nabble.com/Camel-and-IBM-MQ-Series-td24524277.html" rel="nofollow">link at nabble</a> how a Camel user configure <a href="/confluence/display/CAMEL/JMS" title="JMS">JMS</a> to connect to remote WebSphere MQ brokers.</p>


<h3><a name="JMS-ConcurrentConsuming"></a>Concurrent Consuming</h3>

<p>A common requirement with JMS is to consume messages concurrently in many threads to achieve high throughput. As shown above you use the <b>concurrentConsumers</b> property above.</p>

<div class="code">
<textarea name="newcodemacro" class="java:nocontrols:nogutter" rows="10" readonly="readonly">from("jms:SomeQueue?concurrentConsumers=20").
  bean(MyClass.class);</textarea>
<script class="javascript">
    if(!window.newcodemacro_initialised)
    {
        window.newcodemacro_initialised = true;
        window.oldonloadmethod = window.onload;
        window.onload = function(){
            dp.SyntaxHighlighter.HighlightAll('newcodemacro');
            if(window.oldonloadmethod)
            {
                window.oldonloadmethod();
            }
        }
    }

</script>
</div>


<p>You can configure the properties on the JmsComponent if you wish or on specific endpoints via the URI or by configuring the JmsEndpoint directly.</p>


<h3><a name="JMS-EnablingTransactedConsumption"></a>Enabling Transacted Consumption</h3>

<p>A common requirement is to consume from a queue in a transaction then process the message using the Camel route. To do this just ensure you set the following properties on the component/endpoint</p>

<ul>
	<li>transacted = true</li>
	<li>transactionManager = a Transsaction Manager - typically the JmsTransactionManager</li>
</ul>


<p>See also the <a href="/confluence/display/CAMEL/Transactional+Client" title="Transactional Client">Transactional Client</a> EIP pattern for further details.</p>

<div class='panelMacro'><table class='infoMacro'><colgroup><col width='24'><col></colgroup><tr><td valign='top'><img src="/confluence/images/icons/emoticons/information.gif" width="16" height="16" align="absmiddle" alt="" border="0"></td><td><b>Transaction and <a href="/confluence/display/CAMEL/Request+Reply" title="Request Reply">Request Reply</a> over JMS</b><br /><p>Note that when using <a href="/confluence/display/CAMEL/Request+Reply" title="Request Reply">Request Reply</a> over JMS you cannot use a single transaction; as JMS will not send any messages until a commit is performed so the server side won't receive anything at all until the transaction commits. So with request/response you must commit a transaction after sending the first request and then use a separate transaction for receiving the response.</p>

<p>Its for this reason that the <b>transacted</b> property only applies to InOnly message <a href="/confluence/display/CAMEL/Exchange+Pattern" title="Exchange Pattern">Exchange Pattern</a>. If you still want to use transacted for InOut then you must use <b>transactedInOut=true</b>.</p>

<p>To recap: if you have <tt>transacted=true</tt>, <tt>transactedInOut=false</tt> and are sending an <a href="/confluence/display/CAMEL/Exchange+Pattern" title="Exchange Pattern">InOut</a> then the <a href="/confluence/display/CAMEL/Exchange" title="Exchange">Exchange</a> will <b>not</b> use transaction.</p></td></tr></table></div>

<h3><a name="JMS-UsingJMSReplyToforlatereplies"></a>Using JMSReplyTo for late replies</h3>
<p><b>Avaiable as of Camel 2.0</b></p>

<p>When using Camel as a JMS listener it will place a property on the Exchange with the ReplyTo <tt>javax.jms.Destination</tt> object in the key <tt>ReplyTo</tt>.<br/>
You can obtain this Destination as shown here:</p>
<div class="code">
<textarea name="newcodemacro" class="java:nocontrols:nogutter" rows="10" readonly="readonly">Destination replyDestination = exchange.getIn().getHeader(JmsConstants.JMS_REPLY_DESTINATION, Destination.class);</textarea>
<script class="javascript">
    if(!window.newcodemacro_initialised)
    {
        window.newcodemacro_initialised = true;
        window.oldonloadmethod = window.onload;
        window.onload = function(){
            dp.SyntaxHighlighter.HighlightAll('newcodemacro');
            if(window.oldonloadmethod)
            {
                window.oldonloadmethod();
            }
        }
    }

</script>
</div>


<p>And then later use it to send a reply using regular or Camel JMS.</p>
<div class="code">
<textarea name="newcodemacro" class="java:nocontrols:nogutter" rows="10" readonly="readonly">// we need to pass in the JMS component, and in this sample we use ActiveMQ
    JmsEndpoint endpoint = JmsEndpoint.newInstance(replyDestination, activeMQComponent);
    // now we have the endpoint we can use regular Camel API to send a message to it
    template.sendBody(endpoint, "Here is the late reply.");</textarea>
<script class="javascript">
    if(!window.newcodemacro_initialised)
    {
        window.newcodemacro_initialised = true;
        window.oldonloadmethod = window.onload;
        window.onload = function(){
            dp.SyntaxHighlighter.HighlightAll('newcodemacro');
            if(window.oldonloadmethod)
            {
                window.oldonloadmethod();
            }
        }
    }

</script>
</div>


<p>A different solution to sending it is to provide the replyDestination object in the same Exchange property when sending. Then Camel will pickup this property and use it for the real destination. This requires however that you send it to some dummy destination. Okay here goes:</p>
<div class="code">
<textarea name="newcodemacro" class="java:nocontrols:nogutter" rows="10" readonly="readonly">// we pretend to send it to some non existing dummy queue
    template.send("activemq:queue:dummy, new Processor() {
        public void process(Exchange exchange) throws Exception {
            // and here we override the destination with the ReplyTo destination object so the message is sent to there instead of dummy
            exchange.getIn().setHeader(JmsConstants.JMS_DESTINATION, replyDestination);
            exchange.getIn().setBody("Here is the late reply.");
        }
    }</textarea>
<script class="javascript">
    if(!window.newcodemacro_initialised)
    {
        window.newcodemacro_initialised = true;
        window.oldonloadmethod = window.onload;
        window.onload = function(){
            dp.SyntaxHighlighter.HighlightAll('newcodemacro');
            if(window.oldonloadmethod)
            {
                window.oldonloadmethod();
            }
        }
    }

</script>
</div>



<h3><a name="JMS-Usingrequesttimeout"></a>Using request timeout</h3>
<p>In the sample below we send a <a href="/confluence/display/CAMEL/Request+Reply" title="Request Reply">Request Reply</a> style message <a href="/confluence/display/CAMEL/Exchange" title="Exchange">Exchange</a> (we use the <tt>requestBody</tt> method = <tt>InOut</tt>) to the slow queue for further processing in Camel and we wait for a return reply. </p>

<style type="text/css">
@import url(/confluence/download/resources/confluence.ext.code:code/shStyles.css);
</style>
<!--[if IE]>
<style type="text/css">
    .code textarea, .code input { padding: 0 !important; }
</style>
<![endif]-->
<script class="javascript" src="/confluence/download/resources/confluence.ext.code:code/shCore.js"></script>
<script class="javascript" src="/confluence/download/resources/confluence.ext.code:code/shBrushCSharp.js"></script>
<script class="javascript" src="/confluence/download/resources/confluence.ext.code:code/shBrushPhp.js"></script>
<script class="javascript" src="/confluence/download/resources/confluence.ext.code:code/shBrushJScript.js"></script>
<script class="javascript" src="/confluence/download/resources/confluence.ext.code:code/shBrushVb.js"></script>
<script class="javascript" src="/confluence/download/resources/confluence.ext.code:code/shBrushSql.js"></script>
<script class="javascript" src="/confluence/download/resources/confluence.ext.code:code/shBrushXml.js"></script>
<script class="javascript" src="/confluence/download/resources/confluence.ext.code:code/shBrushShell.js"></script>
<script class="javascript" src="/confluence/download/resources/confluence.ext.code:code/shBrushDelphi.js"></script>
<script class="javascript" src="/confluence/download/resources/confluence.ext.code:code/shBrushPython.js"></script>
<script class="javascript" src="/confluence/download/resources/confluence.ext.code:code/shBrushJava.js"></script>
<div class="code">
<textarea name="newcodemacro" class="java:nocontrols:nogutter" rows="10" readonly="readonly">// send a in-out with a timeout for 5 sec
Object out = template.requestBody("activemq:queue:slow?requestTimeout=5000", "Hello World");</textarea>
<script class="javascript">
    if(!window.newcodemacro_initialised)
    {
        window.newcodemacro_initialised = true;
        window.oldonloadmethod = window.onload;
        window.onload = function(){
            dp.SyntaxHighlighter.HighlightAll('newcodemacro');
            if(window.oldonloadmethod)
            {
                window.oldonloadmethod();
            }
        }
    }

</script>
</div>


<h3><a name="JMS-Samples"></a>Samples</h3>
<p>JMS is used in many examples for other components as well. But we provide a few samples below to get started.</p>

<h4><a name="JMS-ReceivingfromJMS"></a>Receiving from JMS</h4>
<p>In this sample we configure a route that receives JMS messages and routes the message to a POJO</p>

<div class="code">
<textarea name="newcodemacro" class="java:nocontrols:nogutter" rows="10" readonly="readonly">from("jms:queue:foo").
     to("bean:myBusinessLogic");</textarea>
<script class="javascript">
    if(!window.newcodemacro_initialised)
    {
        window.newcodemacro_initialised = true;
        window.oldonloadmethod = window.onload;
        window.onload = function(){
            dp.SyntaxHighlighter.HighlightAll('newcodemacro');
            if(window.oldonloadmethod)
            {
                window.oldonloadmethod();
            }
        }
    }

</script>
</div>


<p>You can of course use any of the EIP pattern so the route can be context based, such as filtering an order topic for the big spenders:</p>
<div class="code">
<textarea name="newcodemacro" class="java:nocontrols:nogutter" rows="10" readonly="readonly">from("jms:topic:OrdersTopic").
  filter().method("myBean", "isGoldCustomer").
    to("jms:queue:BigSpendersQueue");</textarea>
<script class="javascript">
    if(!window.newcodemacro_initialised)
    {
        window.newcodemacro_initialised = true;
        window.oldonloadmethod = window.onload;
        window.onload = function(){
            dp.SyntaxHighlighter.HighlightAll('newcodemacro');
            if(window.oldonloadmethod)
            {
                window.oldonloadmethod();
            }
        }
    }

</script>
</div>


<h4><a name="JMS-SendingtoaJMS"></a>Sending to a JMS </h4>
<p>In the sample below we poll a file folder and send the file content to a JMS topic. As we want the content of the file as a TextMessage instead of a BytesMessage we need to convert the body to a String.</p>
<div class="code">
<textarea name="newcodemacro" class="java:nocontrols:nogutter" rows="10" readonly="readonly">from("file://orders").
  convertBodyTo(String.class).
  to("jms:topic:OrdersTopic");</textarea>
<script class="javascript">
    if(!window.newcodemacro_initialised)
    {
        window.newcodemacro_initialised = true;
        window.oldonloadmethod = window.onload;
        window.onload = function(){
            dp.SyntaxHighlighter.HighlightAll('newcodemacro');
            if(window.oldonloadmethod)
            {
                window.oldonloadmethod();
            }
        }
    }

</script>
</div>


<h4><a name="JMS-UsingAnnotationsBeanIntegration"></a>Using <a href="/confluence/display/CAMEL/Bean+Integration" title="Bean Integration">Annotations</a></h4>
<p>Camel also has annotations so you can use <a href="/confluence/display/CAMEL/POJO+Consuming" title="POJO Consuming">POJO Consuming</a> and <a href="/confluence/display/CAMEL/POJO+Producing" title="POJO Producing">POJO Producing</a>. </p>

<h4><a name="JMS-SpringDSLsample"></a>Spring DSL sample</h4>
<p>The sample above are using the Java DSL. Camel also supports using Spring XML DSL. Here is the big spender sample using Spring DSL:</p>
<div class="code">
<textarea name="newcodemacro" class="xml:nocontrols:nogutter" rows="10" readonly="readonly">&lt;route&gt;
  &lt;from uri="jms:topic:OrdersTopic"/&gt;
  &lt;filter&gt;
    &lt;method bean="myBean" method="isGoldCustomer"/&gt;
    &lt;to uri="jms:queue:BigSpendersQueue"/&gt;
  &lt;/filter&gt;
&lt;/route&gt;</textarea>
<script class="javascript">
    if(!window.newcodemacro_initialised)
    {
        window.newcodemacro_initialised = true;
        window.oldonloadmethod = window.onload;
        window.onload = function(){
            dp.SyntaxHighlighter.HighlightAll('newcodemacro');
            if(window.oldonloadmethod)
            {
                window.oldonloadmethod();
            }
        }
    }

</script>
</div>


<h4><a name="JMS-Othersamples"></a>Other samples</h4>
<p>JMS is used a lot in other samples for other components and EIP patterns as well in this Camel documentation. So feel free to browse the documentation. If you have good time then check out the this tutorial that uses JMS but focuses on how well Spring Remoting and Camel works together <a href="/confluence/display/CAMEL/Tutorial-JmsRemoting" title="Tutorial-JmsRemoting">Tutorial&#45;JmsRemoting</a>.</p>

<h4><a name="JMS-UsingJMSasaDeadLetterQueuestoringExchange"></a>Using JMS as a Dead Letter Queue storing Exchange</h4>
<p><b>Available as of Camel 2.0</b><br/>
Normally when using <a href="/confluence/display/CAMEL/JMS" title="JMS">JMS</a> as transport in only transfers the body and headers as payload. If you want to use <a href="/confluence/display/CAMEL/JMS" title="JMS">JMS</a> with <a href="/confluence/display/CAMEL/Dead+Letter+Channel" title="Dead Letter Channel">Dead Letter Channel</a> using a JMS queue as the Dead Letter Queue then normally the caused Exception is not stored in the JMS message. You can therefore use the option <b>transferExchange</b> on the JMS dead letter queue to instruct Camel to store the entire <a href="/confluence/display/CAMEL/Exchange" title="Exchange">Exchange</a> in the queue as a <tt>javax.jms.ObjectMessage</tt> that holds a <tt>org.apache.camel.impl.DefaultExchangeHolder</tt>. This allows you to consume from the Dead Letter Queue and grap the caused exception using a Exchange property with the key <tt>Exchange.EXCEPTION_CAUGHT</tt>. The demo below illustrates this:</p>

<div class="code">
<textarea name="newcodemacro" class="java:nocontrols:nogutter" rows="10" readonly="readonly">// setup error handler to use JMS as queue and store the entire Exchange
errorHandler(deadLetterChannel("jms:queue:dead?transferExchange=true"));</textarea>
<script class="javascript">
    if(!window.newcodemacro_initialised)
    {
        window.newcodemacro_initialised = true;
        window.oldonloadmethod = window.onload;
        window.onload = function(){
            dp.SyntaxHighlighter.HighlightAll('newcodemacro');
            if(window.oldonloadmethod)
            {
                window.oldonloadmethod();
            }
        }
    }

</script>
</div>


<p>Then you can consume from the JMS queue and analyze the problem:</p>
<div class="code">
<textarea name="newcodemacro" class="java:nocontrols:nogutter" rows="10" readonly="readonly">from("jms:queue:dead").to("bean:myErrorAnalyzer");

// and in our bean
String body = exchange.getIn().getBody();
Exception cause = exchange.getProperty(Exchange.EXCEPTION_CAUGHT, Exception.class);
// the cause message is
String problem = cause.getMessage();</textarea>
<script class="javascript">
    if(!window.newcodemacro_initialised)
    {
        window.newcodemacro_initialised = true;
        window.oldonloadmethod = window.onload;
        window.onload = function(){
            dp.SyntaxHighlighter.HighlightAll('newcodemacro');
            if(window.oldonloadmethod)
            {
                window.oldonloadmethod();
            }
        }
    }

</script>
</div>


<h4><a name="JMS-UsingJMSasDeadLetterChannelstoringerroronly"></a>Using JMS as Dead Letter Channel storing error only</h4>
<p>You can use JMS to store the cause error message or a custom body as you can set as you like. We use <a href="/confluence/display/CAMEL/Message+Translator" title="Message Translator">Message Translator</a> EIP to do a transformation on the failed exchange before its moved to the <a href="/confluence/display/CAMEL/JMS" title="JMS">JMS</a> dead letter queue. The demo below illustrates this:</p>
<div class="code">
<textarea name="newcodemacro" class="java:nocontrols:nogutter" rows="10" readonly="readonly">// we sent it to a seda dead queue first
errorHandler(deadLetterChannel("seda:dead"));

// and on the seda dead queue we can do the custom transformation before its sent to the JMS queue
from("seda:dead").transform(exceptionMessage()).to("jms:queue:dead");</textarea>
<script class="javascript">
    if(!window.newcodemacro_initialised)
    {
        window.newcodemacro_initialised = true;
        window.oldonloadmethod = window.onload;
        window.onload = function(){
            dp.SyntaxHighlighter.HighlightAll('newcodemacro');
            if(window.oldonloadmethod)
            {
                window.oldonloadmethod();
            }
        }
    }

</script>
</div>

<p>Here we only store the original cause error message in the transform. You can however use any <a href="/confluence/display/CAMEL/Expression" title="Expression">Expression</a> to send whatever you like. Eg you can invoke a method on a Bean, use a custom processor or what else.</p>

<h3><a name="JMS-SeeAlso"></a>See Also</h3>
<ul>
	<li><a href="/confluence/display/CAMEL/Configuring+Camel" title="Configuring Camel">Configuring Camel</a></li>
	<li><a href="/confluence/display/CAMEL/Component" title="Component">Component</a></li>
	<li><a href="/confluence/display/CAMEL/Endpoint" title="Endpoint">Endpoint</a></li>
	<li><a href="/confluence/display/CAMEL/Getting+Started" title="Getting Started">Getting Started</a></li>
</ul>

<ul class="alternate" type="square">
	<li><a href="/confluence/display/CAMEL/Transactional+Client" title="Transactional Client">Transactional Client</a></li>
	<li><a href="/confluence/display/CAMEL/Bean+Integration" title="Bean Integration">Bean Integration</a></li>
	<li><a href="/confluence/display/CAMEL/Tutorial-JmsRemoting" title="Tutorial-JmsRemoting">Tutorial&#45;JmsRemoting</a></li>
	<li><a href="http://activemq.apache.org/jmstemplate-gotchas.html" rel="nofollow">JMSTemplate gotchas</a></li>
</ul>

     </div>
     <div id="commentsSection" class="wiki-content pageSection">
       <div style="float: right;">
            <a href="http://cwiki.apache.org/confluence/users/viewnotifications.action" class="grey">Change Notification Preferences</a>
       </div>

       <a href="http://cwiki.apache.org/confluence/display/CAMEL/JMS">View Online</a>
       |
       <a href="http://cwiki.apache.org/confluence/pages/diffpagesbyversion.action?pageId=51893&revisedVersion=92&originalVersion=91">View Change</a>
              |
       <a href="http://cwiki.apache.org/confluence/display/CAMEL/JMS?showComments=true&amp;showCommentArea=true#addcomment">Add Comment</a>
            </div>
</div>
</div>
</div>
</div>
</body>
</html>

Mime
View raw message