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 Wed, 09 Nov 2011 09:28:00 GMT
<html>
<head>
    <base href="https://cwiki.apache.org/confluence">
            <link rel="stylesheet" href="/confluence/s/2042/9/1/_/styles/combined.css?spaceKey=CAMEL&amp;forWysiwyg=true" type="text/css">
    </head>
<body style="background: white;" bgcolor="white" class="email-body">
<div id="pageContent">
<div id="notificationFormat">
<div class="wiki-content">
<div class="email">
    <h2><a href="https://cwiki.apache.org/confluence/display/CAMEL/JMS">JMS</a></h2>
    <h4>Page <b>edited</b> by             <a href="https://cwiki.apache.org/confluence/display/~davsclaus">Claus Ibsen</a>
    </h4>
        <br/>
                         <h4>Changes (1)</h4>
                                 
    
<div id="page-diffs">
                    <table class="diff" cellpadding="0" cellspacing="0">
    
            <tr><td class="diff-snipped" >...<br></td></tr>
            <tr><td class="diff-unchanged" >| {{replyTo}} | {{null}} | Provides an explicit ReplyTo destination, which overrides any incoming value of {{Message.getJMSReplyTo()}}. If you do [Request Reply] over JMS then read the section further below for more details. | <br>| {{replyToType}} | {{null}} | *Camel 2.9:* Allows to explicit specify which kind of strategy to use for replyTo queues when doing request/reply over JMS. Possible values are: {{Temporary}}, {{Shared}}, or {{Exclusive}}. By default Camel will use temporary queues. However if {{replyTo}} has been configured, then {{Shared}} is used by default. This option allows you to use exclusive instead of shared queues. See further below for more details, and especially the notes about the implications if running in a clustered environment. | <br></td></tr>
            <tr><td class="diff-changed-lines" >| {{requestTimeout}} | {{20000}} | <span class="diff-added-words"style="background-color: #dfd;">*Producer only:*</span> The timeout for waiting for a reply when using the InOut [Exchange Pattern] (in milliseconds). The default is 20 seconds. See below in section _About time to live_ for more details. | <br></td></tr>
            <tr><td class="diff-unchanged" >| {{selector}} | {{null}} | Sets the JMS Selector, which is an SQL 92 predicate that is used to filter messages within the broker. You may have to encode special characters such as = as %3D *Before Camel 2.3.0*, we don&#39;t support this option in CamelConsumerTemplate | <br>| {{timeToLive}} | {{null}} | When sending messages, specifies the time-to-live of the message (in milliseconds). See below in section _About time to live_ for more details. | <br></td></tr>
            <tr><td class="diff-snipped" >...<br></td></tr>
    
            </table>
    </div>                            <h4>Full Content</h4>
                    <div class="notificationGreySide">
        <h2><a name="JMS-JMSComponent"></a>JMS Component</h2>

<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>Using ActiveMQ</b><br />If you are using <a href="http://activemq.apache.org/" class="external-link" rel="nofollow">Apache ActiveMQ</a>, you should prefer the <a href="/confluence/display/CAMEL/ActiveMQ" title="ActiveMQ">ActiveMQ</a> component as it has been optimized for <a href="/confluence/display/CAMEL/ActiveMQ" title="ActiveMQ">ActiveMQ</a>. All of the options and samples on this page are also valid for the <a href="/confluence/display/CAMEL/ActiveMQ" title="ActiveMQ">ActiveMQ</a> component.</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>Transacted and caching</b><br />See section <em>Transactions and Cache Levels</em> below if you are using transactions with <a href="/confluence/display/CAMEL/JMS" title="JMS">JMS</a> as it can impact performance.</td></tr></table></div>

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

<p>Maven users will need to add the following dependency to their <tt>pom.xml</tt> for this component:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-xml">
<span class="code-tag">&lt;dependency&gt;</span>
    <span class="code-tag">&lt;groupId&gt;</span>org.apache.camel<span class="code-tag">&lt;/groupId&gt;</span>
    <span class="code-tag">&lt;artifactId&gt;</span>camel-jms<span class="code-tag">&lt;/artifactId&gt;</span>
    <span class="code-tag">&lt;version&gt;</span>x.x.x<span class="code-tag">&lt;/version&gt;</span>
    <span class="code-tag"><span class="code-comment">&lt;!-- use the same version as your Camel core version --&gt;</span></span>
<span class="code-tag">&lt;/dependency&gt;</span>
</pre>
</div></div>

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

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
jms:[queue:|topic:]destinationName[?options]
</pre>
</div></div>

<p>Where <tt>destinationName</tt> is a JMS queue or topic name. By default, the <tt>destinationName</tt> is interpreted as a queue name. For example, to connect to the queue, <tt>FOO.BAR</tt> use:</p>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
jms:FOO.BAR
</pre>
</div></div>

<p>You can include the optional <tt>queue:</tt> prefix, if you prefer:</p>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
jms:queue:FOO.BAR
</pre>
</div></div>

<p>To connect to a topic, you <em>must</em> include the <tt>topic:</tt> prefix. For example, to<br/>
connect to the topic, <tt>Stocks.Prices</tt>, use:</p>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
jms:topic:Stocks.Prices
</pre>
</div></div>

<p>You append query options to the URI using the following format, <tt>?option=value&amp;option=value&amp;...</tt></p>

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


<h4><a name="JMS-UsingActiveMQ"></a>Using ActiveMQ</h4>
<p>The JMS component reuses Spring 2's <tt>JmsTemplate</tt> for sending messages. This is not ideal for use in a non-J2EE container and typically requires some caching in the JMS provider to avoid <a href="http://activemq.apache.org/jmstemplate-gotchas.html" class="external-link" rel="nofollow">poor performance</a>.</p>

<p>If you intend to use <a href="http://activemq.apache.org/" class="external-link" 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 optimized to use ActiveMQ efficiently</li>
	<li>Use the <tt>PoolingConnectionFactory</tt> in ActiveMQ.</li>
</ul>


<h4><a name="JMS-TransactionsandCacheLevels"></a>Transactions and Cache Levels</h4>
<p><a name="JMS-transactionCacheLevels"></a><br/>
If you are consuming messages and using transactions (<tt>transacted=true</tt>) then the default settings for cache level can impact performance. <br/>
If you are using XA transactions then you cannot cache as it can cause the XA transaction not to work properly.</p>

<p>If you are <b>not</b> using XA, then you should consider caching as it speedup performance, such as setting <tt>cacheLevelName=CACHE_CONSUMER</tt>.</p>

<p>Through Camel 2.7.x, the default setting for <tt>cacheLevelName</tt> is <tt>CACHE_CONSUMER</tt>. You will need to explicitly set <tt>cacheLevelName=CACHE_NONE</tt>.<br/>
In Camel 2.8 onwards, the default setting for <tt>cacheLevelName</tt> is <tt>CACHE_AUTO</tt>. This default auto detects the mode and sets the cache level accordingly to:</p>
<ul class="alternate" type="square">
	<li>CACHE_CONSUMER = if transacted=false</li>
	<li>CACHE_NONE = if transacted=true</li>
</ul>


<p>So you can say the default setting is conservative. Consider using <tt>cacheLevelName=CACHE_CONSUMER</tt> if you are using non-XA transactions.</p>

<h4><a name="JMS-DurableSubscriptions"></a>Durable Subscriptions</h4>
<p>If you wish to use durable topic subscriptions, you need to specify both <b>clientId</b> and <b>durableSubscriptionName</b>. The value of the <tt>clientId</tt> 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" class="external-link" 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" class="external-link" rel="nofollow">here</a>.</p>

<h4><a name="JMS-MessageHeaderMapping"></a>Message Header Mapping</h4>
<p>When using message headers, the JMS specification states that header names must be valid Java identifiers. So, by default, Camel ignores any headers that do not match this rule. So try to name your headers as if they are valid Java identifiers. One benefit of doing this is that you can then use your headers inside a JMS Selector (whose SQL92 syntax mandates Java identifier syntax for headers).</p>

<p>From Camel 1.4 onwards, a simple strategy for mapping header names is used by default. The strategy is to replace any dots in the header name with the underscore character and to reverse the replacement when the header name is restored from a JMS message sent over the wire. What does this mean? No more losing method names to invoke on a bean component, no more losing the filename header for the File Component, and so on. </p>

<p>The current header name strategy for accepting header names in Camel is as follows:</p>
<ul class="alternate" type="square">
	<li>Replace all dots with underscores (for example, <tt>org.apache.camel.MethodName</tt> becomes <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 the test success, the header is added and sent over the wire; otherwise it is dropped (and logged at <tt>DEBUG</tt> level).</li>
</ul>


<p>In Camel 2.0 this strategy has been change a bit to use the following replacement strategy:</p>
<ul class="alternate" type="square">
	<li>Dots are replaced by <tt>&#95;DOT&#95;</tt> and the replacement is reversed when Camel consume the message</li>
	<li>Hyphen is replaced by <tt>&#95;HYPHEN&#95;</tt> and the replacement is reversed when Camel consumes the message</li>
</ul>


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

<p>You can configure many different properties on the JMS endpoint which map to properties on the <a href="http://camel.apache.org/maven/current/camel-jms/apidocs/org/apache/camel/component/jms/JmsConfiguration.html" class="external-link" rel="nofollow">JMSConfiguration POJO</a>.</p>

<div class='panelMacro'><table class='noteMacro'><colgroup><col width='24'><col></colgroup><tr><td valign='top'><img src="/confluence/images/icons/emoticons/warning.gif" width="16" height="16" align="absmiddle" alt="" border="0"></td><td><b>Mapping to Spring JMS</b><br />Many of these properties map to properties on Spring JMS, which Camel uses for sending and receiving messages. So you can get more information about these properties by consulting the relevant Spring documentation.</td></tr></table></div>

<p>The options are divided into two tables, the first one with the most common options used. The latter contains the rest.</p>

<h4><a name="JMS-Mostcommonlyusedoptions"></a>Most commonly used options</h4>
<div class="confluenceTableSmall"><div class='table-wrap'>
<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'> <tt>clientId</tt> </td>
<td class='confluenceTd'> <tt>null</tt> </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. It is typically only required for durable topic subscriptions. You may prefer to use <a href="http://activemq.apache.org/virtual-destinations.html" class="external-link" rel="nofollow">Virtual Topics</a> instead. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>concurrentConsumers</tt> </td>
<td class='confluenceTd'> <tt>1</tt> </td>
<td class='confluenceTd'> Specifies the default number of concurrent consumers. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>disableReplyTo</tt> </td>
<td class='confluenceTd'> <tt>false</tt> </td>
<td class='confluenceTd'> If <tt>true</tt>, a producer will behave like a InOnly exchange with the exception that <tt>JMSReplyTo</tt> header is sent out and not be suppressed like in the case of <tt>InOnly</tt>. Like <tt>InOnly</tt> the producer will not wait for a reply. A consumer with this flag will behave like <tt>InOnly</tt>. This feature can be used to bridge <tt>InOut</tt> requests to another queue so that a route on the other queue will send it´s response directly back to the original <tt>JMSReplyTo</tt>. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>durableSubscriptionName</tt> </td>
<td class='confluenceTd'> <tt>null</tt> </td>
<td class='confluenceTd'> The durable subscriber name for specifying durable topic subscriptions. The <tt>clientId</tt> option <b>must</b> be configured as well. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>maxConcurrentConsumers</tt> </td>
<td class='confluenceTd'> <tt>1</tt> </td>
<td class='confluenceTd'> Specifies the maximum number of concurrent consumers. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>preserveMessageQos</tt> </td>
<td class='confluenceTd'> <tt>false</tt> </td>
<td class='confluenceTd'>  <b>Camel 2.0</b>: Set to <tt>true</tt>, 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 three headers are considered <tt>JMSPriority</tt>, <tt>JMSDeliveryMode</tt>, and <tt>JMSExpiration</tt>. You can provide all or only some of them. If not provided, Camel will fall back to use the values from the endpoint instead. So, when using this option, the headers override the values from the endpoint. The <tt>explicitQosEnabled</tt> option, by contrast, will only use options set on the endpoint, and not values from the message header. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>replyTo</tt> </td>
<td class='confluenceTd'> <tt>null</tt> </td>
<td class='confluenceTd'> Provides an explicit ReplyTo destination, which overrides any incoming value of <tt>Message.getJMSReplyTo()</tt>. If you do <a href="/confluence/display/CAMEL/Request+Reply" title="Request Reply">Request Reply</a> over JMS then read the section further below for more details. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>replyToType</tt> </td>
<td class='confluenceTd'> <tt>null</tt> </td>
<td class='confluenceTd'> <b>Camel 2.9:</b> Allows to explicit specify which kind of strategy to use for replyTo queues when doing request/reply over JMS. Possible values are: <tt>Temporary</tt>, <tt>Shared</tt>, or <tt>Exclusive</tt>. By default Camel will use temporary queues. However if <tt>replyTo</tt> has been configured, then <tt>Shared</tt> is used by default. This option allows you to use exclusive instead of shared queues. See further below for more details, and especially the notes about the implications if running in a clustered environment. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>requestTimeout</tt> </td>
<td class='confluenceTd'> <tt>20000</tt> </td>
<td class='confluenceTd'> <b>Producer only:</b> The timeout for waiting for a reply when using the InOut <a href="/confluence/display/CAMEL/Exchange+Pattern" title="Exchange Pattern">Exchange Pattern</a> (in milliseconds). The default is 20 seconds. See below in section <em>About time to live</em> for more details. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>selector</tt> </td>
<td class='confluenceTd'> <tt>null</tt> </td>
<td class='confluenceTd'> Sets the JMS Selector, which is an SQL 92 predicate that is used to filter messages within the broker. You may have to encode special characters such as = as %3D <b>Before Camel 2.3.0</b>, we don't support this option in CamelConsumerTemplate </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>timeToLive</tt> </td>
<td class='confluenceTd'> <tt>null</tt> </td>
<td class='confluenceTd'> When sending messages, specifies the time-to-live of the message (in milliseconds). See below in section <em>About time to live</em> for more details. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>transacted</tt> </td>
<td class='confluenceTd'> <tt>false</tt> </td>
<td class='confluenceTd'> Specifies whether to use transacted mode for sending/receiving messages using the InOnly <a href="/confluence/display/CAMEL/Exchange+Pattern" title="Exchange Pattern">Exchange Pattern</a>.</td>
</tr>
<tr>
<td class='confluenceTd'> <tt>testConnectionOnStartup</tt> </td>
<td class='confluenceTd'> <tt>false</tt> </td>
<td class='confluenceTd'> <b>Camel 2.1:</b> Specifies whether to test the connection on startup. This ensures that when Camel starts that all the JMS consumers have a valid connection to the JMS broker. If a connection cannot be granted then Camel throws an exception on startup. This ensure that Camel is not started with failed connections. From <b>Camel 2.8</b> onwards also the JMS producers is tested as well. </td>
</tr>
</tbody></table>
</div>


<h4><a name="JMS-Alltheotheroptions"></a>All the other options</h4>

<div class="confluenceTableSmall"></div>
<div class='table-wrap'>
<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'> <tt>autoStartup</tt> </td>
<td class='confluenceTd'> <tt>true</tt> </td>
<td class='confluenceTd'> Specifies whether the consumer container should auto-startup. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>acceptMessagesWhileStopping</tt> </td>
<td class='confluenceTd'> <tt>false</tt> </td>
<td class='confluenceTd'> Specifies whether the consumer accept messages while it is stopping. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>acknowledgementModeName</tt> </td>
<td class='confluenceTd'> <tt>AUTO_ACKNOWLEDGE</tt> </td>
<td class='confluenceTd'> The JMS acknowledgement name, which is one of: <tt>TRANSACTED</tt>, <tt>CLIENT_ACKNOWLEDGE</tt>, <tt>AUTO_ACKNOWLEDGE</tt>, <tt>DUPS_OK_ACKNOWLEDGE</tt> </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>acknowledgementMode</tt> </td>
<td class='confluenceTd'> <tt>-1</tt> </td>
<td class='confluenceTd'> The JMS acknowledgement mode defined as an Integer. Allows you to set vendor-specific extensions to the acknowledgment mode. For the regular modes, it is preferable to use the <tt>acknowledgementModeName</tt> instead. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>alwaysCopyMessage</tt> </td>
<td class='confluenceTd'> <tt>false</tt> </td>
<td class='confluenceTd'> If <tt>true</tt>, Camel will always make a JMS message copy of the message when it is passed to the producer for sending. Copying the message is needed in some situations, such as when a <tt>replyToDestinationSelectorName</tt> is set (incidentally, Camel will set the <tt>alwaysCopyMessage</tt> option to <tt>true</tt>, if a <tt>replyToDestinationSelectorName</tt> is set) </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>asyncConsumer</tt> </td>
<td class='confluenceTd'> <tt>false</tt> </td>
<td class='confluenceTd'> <b>Camel 2.9:</b> Whether the <tt>JmsConsumer</tt> processes the <a href="/confluence/display/CAMEL/Exchange" title="Exchange">Exchange</a> <a href="/confluence/display/CAMEL/Asynchronous+Routing+Engine" title="Asynchronous Routing Engine">asynchronously</a>. If enabled then the <tt>JmsConsumer</tt> may pickup the next message from the JMS queue, while the previous message is being processed asynchronously (by the <a href="/confluence/display/CAMEL/Asynchronous+Routing+Engine" title="Asynchronous Routing Engine">Asynchronous Routing Engine</a>). This means that messages may be processed not 100% strictly in order. If disabled (as default) then the <a href="/confluence/display/CAMEL/Exchange" title="Exchange">Exchange</a> is fully processed before the <tt>JmsConsumer</tt> will pickup the next message from the JMS queue. Note if <tt>transacted</tt> has been enabled, then <tt>asyncConsumer=true</tt> does not run asynchronously, as transactions must be executed synchronously (Camel 3.0 may support async transactions). </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>cacheLevelName</tt> </td>
<td class='confluenceTd'><ul class="alternate" type="square">
	<li></li>
</ul>
</td>
<td class='confluenceTd'> Sets the cache level by name for the underlying JMS resources. Possible values are: <tt>CACHE_AUTO</tt>, <tt>CACHE_CONNECTION</tt>, <tt>CACHE_CONSUMER</tt>, <tt>CACHE_NONE</tt>, and <tt>CACHE_SESSION</tt>. The default setting for <b>Camel 2.8</b> and newer is <tt>CACHE_AUTO</tt>. For <b>Camel 2.7.1</b> and older the default is <tt>CACHE_CONSUMER</tt>. See the <a href="http://static.springframework.org/spring/docs/2.5.x/api/org/springframework/jms/listener/DefaultMessageListenerContainer.html" class="external-link" rel="nofollow">Spring documentation</a> and <a href="#JMS-transactionCacheLevels">Transactions Cache Levels</a> for more information. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>cacheLevel</tt> </td>
<td class='confluenceTd'><ul class="alternate" type="square">
	<li></li>
</ul>
</td>
<td class='confluenceTd'> Sets the cache level by ID for the underlying JMS resources. See <tt>cacheLevelName</tt> option for more details. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>consumerType</tt> </td>
<td class='confluenceTd'> <tt>Default</tt> </td>
<td class='confluenceTd'> The consumer type to use, which can be one of: <tt>Simple</tt> or <tt>Default</tt>. The consumer type determines which Spring JMS listener to use. <tt>Default</tt> will use <tt>org.springframework.jms.listener.DefaultMessageListenerContainer</tt>, <tt>Simple</tt> will use <tt>org.springframework.jms.listener.SimpleMessageListenerContainer</tt>. This option was temporary removed in Camel 2.7 and 2.8. But has been added back from Camel 2.9 onwards. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>connectionFactory</tt> </td>
<td class='confluenceTd'> <tt>null</tt> </td>
<td class='confluenceTd'> The default JMS connection factory to use for the <tt>listenerConnectionFactory</tt> and <tt>templateConnectionFactory</tt>, if neither is specified. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>deliveryPersistent</tt> </td>
<td class='confluenceTd'> <tt>true</tt> </td>
<td class='confluenceTd'> Specifies whether persistent delivery is used by default. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>destination</tt> </td>
<td class='confluenceTd'> <tt>null</tt> </td>
<td class='confluenceTd'> <b>Camel 2.0:</b> Specifies the JMS Destination object to use on this endpoint. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>destinationName</tt> </td>
<td class='confluenceTd'> <tt>null</tt> </td>
<td class='confluenceTd'> <b>Camel 2.0:</b> Specifies the JMS destination name to use on this endpoint. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>destinationResolver</tt> </td>
<td class='confluenceTd'> <tt>null</tt> </td>
<td class='confluenceTd'> A pluggable <tt>org.springframework.jms.support.destination.DestinationResolver</tt> that allows you to use your own resolver (for example, to lookup the real destination in a JNDI registry). </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>disableTimeToLive</tt> </td>
<td class='confluenceTd'> <tt>false</tt> </td>
<td class='confluenceTd'> <b>Camel 2.8:</b> Use this option to force disabling time to live. For example when you do request/reply over JMS, then Camel will by default use the <tt>requestTimeout</tt> value as time to live on the message being send. The problem is that the sender and receiver systems have to have their clocks synchronized, so they are in sync. This is not always so easy to archive. So you can use <tt>disableTimeToLive=true</tt> to <b>not</b> set a time to live value on the send message. Then the message will not expire on the receiver system. See below in section <em>About time to live</em> for more details. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>eagerLoadingOfProperties</tt> </td>
<td class='confluenceTd'> <tt>false</tt> </td>
<td class='confluenceTd'> Enables eager loading of JMS properties as soon as a message is received, which is generally inefficient, because the JMS properties might not be required. But this feature can sometimes catch early any issues with the underlying JMS provider and the use of JMS properties. This feature can also be used for testing purposes, to ensure JMS properties can be understood and handled correctly. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>exceptionListener</tt> </td>
<td class='confluenceTd'> <tt>null</tt> </td>
<td class='confluenceTd'> Specifies the JMS Exception Listener that is to be notified of any underlying JMS exceptions. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>errorHandler</tt> </td>
<td class='confluenceTd'> <tt>null</tt> </td>
<td class='confluenceTd'> <b>Camel 2.8.2, 2.9:</b> Specifies a <tt>org.springframework.util.ErrorHandler</tt> to be invoked in case of any uncaught exceptions thrown while processing a <tt>Message</tt>. By default these exceptions will be logged at the ERROR level. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>explicitQosEnabled</tt> </td>
<td class='confluenceTd'> <tt>false</tt> </td>
<td class='confluenceTd'> Set if the <tt>deliveryMode</tt>, <tt>priority</tt> or <tt>timeToLive</tt> qualities of service should be used when sending messages. This option is based on Spring's <tt>JmsTemplate</tt>. The <tt>deliveryMode</tt>, <tt>priority</tt> and <tt>timeToLive</tt> options are applied to the current endpoint. This contrasts with the <tt>preserveMessageQos</tt> option, which operates at message granularity, reading QoS properties exclusively from the Camel In message headers. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>exposeListenerSession</tt> </td>
<td class='confluenceTd'> <tt>true</tt> </td>
<td class='confluenceTd'> Specifies whether the listener session should be exposed when consuming messages. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>forceSendOriginalMessage</tt> </td>
<td class='confluenceTd'> <tt>false</tt> </td>
<td class='confluenceTd'> <b>Camel 2.7:</b> When using <tt>mapJmsMessage=false</tt> Camel will create a new JMS message to send to a new JMS destination if you touch the headers (get or set) during the route. Set this option to <tt>true</tt> to force Camel to send the original JMS message that was received. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>idleTaskExecutionLimit</tt> </td>
<td class='confluenceTd'> <tt>1</tt> </td>
<td class='confluenceTd'> Specifies 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 the case of dynamic scheduling; see the <tt>maxConcurrentConsumers</tt> setting). </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>idleConsumerLimit</tt> </td>
<td class='confluenceTd'> <tt>1</tt> </td>
<td class='confluenceTd'> <b>Camel 2.8.2, 2.9:</b> Specify the limit for the number of consumers that are allowed to be idle at any given time. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>jmsMessageType</tt> </td>
<td class='confluenceTd'> <tt>null</tt> </td>
<td class='confluenceTd'> <b>Camel 2.0:</b> Allows you to force the use of a specific <tt>javax.jms.Message</tt> implementation for sending JMS messages. Possible values are: <tt>Bytes</tt>, <tt>Map</tt>, <tt>Object</tt>, <tt>Stream</tt>, <tt>Text</tt>. By default, Camel would determine which JMS message type to use from the In body type. This option allows you to specify it. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>jmsKeyFormatStrategy</tt> </td>
<td class='confluenceTd'> <tt>default</tt> </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 specification. Camel provides two implementations out of the box: <tt>default</tt> and <tt>passthrough</tt>. The <tt>default</tt> strategy will safely marshal dots and hyphens (<tt>.</tt> and <tt>-</tt>). The <tt>passthrough</tt> strategy leaves the key as is. Can be used for JMS brokers which do not care whether JMS header keys contain illegal characters. You can provide your own implementation of the <tt>org.apache.camel.component.jms.JmsKeyFormatStrategy</tt> and refer to it using the <tt>#</tt> notation.</td>
</tr>
<tr>
<td class='confluenceTd'> <tt>jmsOperations</tt> </td>
<td class='confluenceTd'> <tt>null</tt> </td>
<td class='confluenceTd'> Allows you to use your own implementation of the <tt>org.springframework.jms.core.JmsOperations</tt> interface. Camel uses <tt>JmsTemplate</tt> 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'> <tt>lazyCreateTransactionManager</tt> </td>
<td class='confluenceTd'> <tt>true</tt> </td>
<td class='confluenceTd'> <b>Camel 2.0:</b> If <tt>true</tt>, Camel will create a <tt>JmsTransactionManager</tt>, if there is no <tt>transactionManager</tt> injected when option <tt>transacted=true</tt>. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>listenerConnectionFactory</tt> </td>
<td class='confluenceTd'> <tt>null</tt> </td>
<td class='confluenceTd'> The JMS connection factory used for consuming messages. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>mapJmsMessage</tt> </td>
<td class='confluenceTd'> <tt>true</tt> </td>
<td class='confluenceTd'> <b>Camel 1.6.2/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'> <tt>maxMessagesPerTask</tt> </td>
<td class='confluenceTd'> <tt>-1</tt> </td>
<td class='confluenceTd'> The number of messages per task. -1 is unlimited. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>maximumBrowseSize</tt> </td>
<td class='confluenceTd'> <tt>-1</tt> </td>
<td class='confluenceTd'> Limits the number of messages fetched at most, when browsing endpoints using <a href="/confluence/display/CAMEL/Browse" title="Browse">Browse</a> or JMX API. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>messageConverter</tt> </td>
<td class='confluenceTd'> <tt>null</tt> </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'> <tt>messageIdEnabled</tt> </td>
<td class='confluenceTd'> <tt>true</tt> </td>
<td class='confluenceTd'> When sending, specifies whether message IDs should be added. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>messageTimestampEnabled</tt> </td>
<td class='confluenceTd'> <tt>true</tt> </td>
<td class='confluenceTd'> Specifies whether timestamps should be enabled by default on sending messages. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>password</tt> </td>
<td class='confluenceTd'> <tt>null</tt> </td>
<td class='confluenceTd'> The password for the connector factory. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>priority</tt> </td>
<td class='confluenceTd'> <tt>4</tt> </td>
<td class='confluenceTd'> Values greater than 1 specify the message priority when sending (where 0 is the lowest priority and 9 is the highest). The <tt>explicitQosEnabled</tt> option <b>must</b> also be enabled in order for this option to have any effect. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>pubSubNoLocal</tt> </td>
<td class='confluenceTd'> <tt>false</tt> </td>
<td class='confluenceTd'> Specifies whether to inhibit the delivery of messages published by its own connection. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>receiveTimeout</tt> </td>
<td class='confluenceTd'> <em>None</em> </td>
<td class='confluenceTd'> The timeout for receiving messages (in milliseconds). </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>recoveryInterval</tt> </td>
<td class='confluenceTd'> <tt>5000</tt> </td>
<td class='confluenceTd'> Specifies the interval between recovery attempts, i.e. when a connection is being refreshed, in milliseconds. The default is 5000 ms, that is, 5 seconds. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>replyToDestinationSelectorName</tt> </td>
<td class='confluenceTd'> <tt>null</tt> </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 (that is, if you are not using a temporary reply queue). </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>replyToDeliveryPersistent</tt> </td>
<td class='confluenceTd'> <tt>true</tt> </td>
<td class='confluenceTd'> Specifies whether to use persistent delivery by default for replies. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>subscriptionDurable</tt> </td>
<td class='confluenceTd'> <tt>false</tt> </td>
<td class='confluenceTd'> <b>@deprecated:</b> Enabled by default, if you specify a <tt>durableSubscriberName</tt> and a <tt>clientId</tt>. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>taskExecutor</tt> </td>
<td class='confluenceTd'> <tt>null</tt> </td>
<td class='confluenceTd'> Allows you to specify a custom task executor for consuming messages. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>taskExecutorSpring2</tt> </td>
<td class='confluenceTd'> <tt>null</tt> </td>
<td class='confluenceTd'> <b>Camel 2.6:</b> To use when using Spring 2.x with Camel. Allows you to specify a custom task executor for consuming messages. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>templateConnectionFactory</tt> </td>
<td class='confluenceTd'> <tt>null</tt> </td>
<td class='confluenceTd'> The JMS connection factory used for sending messages. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>transactedInOut</tt> </td>
<td class='confluenceTd'> <tt>false</tt> </td>
<td class='confluenceTd'> <b>@deprecated:</b> Specifies whether to use transacted mode for sending messages using the InOut <a href="/confluence/display/CAMEL/Exchange+Pattern" title="Exchange Pattern">Exchange Pattern</a>. Applies only to producer endpoints. See section <a href="#JMS-transactedConsumption">Enabling Transacted Consumption</a> for more details. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>transactionManager</tt> </td>
<td class='confluenceTd'> <tt>null</tt> </td>
<td class='confluenceTd'> The Spring transaction manager to use. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>transactionName</tt> </td>
<td class='confluenceTd'> <tt>"JmsConsumer[destinationName]"</tt> </td>
<td class='confluenceTd'> The name of the transaction to use. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>transactionTimeout</tt> </td>
<td class='confluenceTd'> <tt>null</tt> </td>
<td class='confluenceTd'> The timeout value of the transaction, if using transacted mode. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>transferException</tt> </td>
<td class='confluenceTd'> <tt>false</tt> </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 <tt>Exception</tt> will be send back in response as a <tt>javax.jms.ObjectMessage</tt>. If the client is Camel, the returned <tt>Exception</tt> is rethrown. This allows you to use Camel <a href="/confluence/display/CAMEL/JMS" title="JMS">JMS</a> as a bridge in your routing - for example, using persistent queues to enable robust routing. Notice that if you also have <b>transferExchange</b> enabled, this option takes precedence. The caught exception is required to be serializable. The original <tt>Exception</tt> 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'> <tt>transferExchange</tt> </td>
<td class='confluenceTd'> <tt>false</tt> </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 are 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 <tt>WARN</tt> level. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>username</tt> </td>
<td class='confluenceTd'> <tt>null</tt> </td>
<td class='confluenceTd'> The username for the connector factory. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>useMessageIDAsCorrelationID</tt> </td>
<td class='confluenceTd'> <tt>false</tt> </td>
<td class='confluenceTd'> Specifies whether <tt>JMSMessageID</tt> should always be used as <tt>JMSCorrelationID</tt> for <b>InOut</b> messages. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>useVersion102</tt> </td>
<td class='confluenceTd'> <tt>false</tt> </td>
<td class='confluenceTd'> <b>@deprecated (removed from Camel 2.5 onwards):</b> Specifies whether the old JMS API should be used. </td>
</tr>
</tbody></table>
</div>
</div>

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

<p>When sending a JMS message, Camel converts the message body to the following JMS message types:</p>

<div class="confluenceTableSmall"><div class='table-wrap'>
<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'> <tt>String</tt> </td>
<td class='confluenceTd'> <tt>javax.jms.TextMessage</tt> </td>
<td class='confluenceTd'>&nbsp;</td>
</tr>
<tr>
<td class='confluenceTd'> <tt>org.w3c.dom.Node</tt> </td>
<td class='confluenceTd'> <tt>javax.jms.TextMessage</tt> </td>
<td class='confluenceTd'> The DOM will be converted to <tt>String</tt>. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>Map</tt> </td>
<td class='confluenceTd'> <tt>javax.jms.MapMessage</tt> </td>
<td class='confluenceTd'>&nbsp;</td>
</tr>
<tr>
<td class='confluenceTd'> <tt>java.io.Serializable</tt> </td>
<td class='confluenceTd'> <tt>javax.jms.ObjectMessage</tt> </td>
<td class='confluenceTd'>&nbsp;</td>
</tr>
<tr>
<td class='confluenceTd'> <tt>byte[]</tt> </td>
<td class='confluenceTd'> <tt>javax.jms.BytesMessage</tt> </td>
<td class='confluenceTd'>&nbsp;</td>
</tr>
<tr>
<td class='confluenceTd'> <tt>java.io.File</tt> </td>
<td class='confluenceTd'> <tt>javax.jms.BytesMessage</tt> </td>
<td class='confluenceTd'>&nbsp;</td>
</tr>
<tr>
<td class='confluenceTd'> <tt>java.io.Reader</tt> </td>
<td class='confluenceTd'> <tt>javax.jms.BytesMessage</tt> </td>
<td class='confluenceTd'>&nbsp;</td>
</tr>
<tr>
<td class='confluenceTd'> <tt>java.io.InputStream</tt> </td>
<td class='confluenceTd'> <tt>javax.jms.BytesMessage</tt> </td>
<td class='confluenceTd'>&nbsp;</td>
</tr>
<tr>
<td class='confluenceTd'> <tt>java.nio.ByteBuffer</tt> </td>
<td class='confluenceTd'> <tt>javax.jms.BytesMessage</tt> </td>
<td class='confluenceTd'>&nbsp;</td>
</tr>
</tbody></table>
</div>
</div>

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

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

<p>You can use the <tt>mapJmsMessage</tt> option to disable the auto-mapping above. If disabled, Camel will not try to map the received JMS message, but instead uses it directly as the 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 panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
  from(<span class="code-quote">"file:<span class="code-comment">//inbox/order"</span>).to(<span class="code-quote">"jms:queue:order?messageConverter=#myMessageConverter"</span>);</span>
</pre>
</div></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 <b>jmsMessageType</b> option on the endpoint URL to force a specific message type for all messages.<br/>
In the route below, we 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 panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
  from(<span class="code-quote">"file:<span class="code-comment">//inbox/order"</span>).to(<span class="code-quote">"jms:queue:order?jmsMessageType=Text"</span>);</span>
</pre>
</div></div>

<p>You can also specify the message type to use for each messabe by setting the header with the key <tt>CamelJmsMessageType</tt>. For example:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
  from(<span class="code-quote">"file:<span class="code-comment">//inbox/order"</span>).setHeader(<span class="code-quote">"CamelJmsMessageType"</span>, JmsMessageType.Text).to(<span class="code-quote">"jms:queue:order"</span>);</span>
</pre>
</div></div>

<p>The possible values are defined in the <tt>enum</tt> 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" class="external-link" rel="nofollow">JMS Message spec</a>.</p>

<p>For the <tt>exchange.in.header</tt> the following rules apply for the header <b>keys</b>:</p>
<ul class="alternate" type="square">
	<li>Keys starting with <tt>JMS</tt> or <tt>JMSX</tt> are 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>From Camel 1.4 until Camel 1.6.x, Camel automatically replaces all dots with underscores in key names. This replacement is reversed when Camel consumes JMS messages.</li>
	<li>From Camel 2.0 onwards, Camel replaces dots &amp; hyphens and the reverse when when consuming JMS messages:<br/>
   <tt>.</tt> is replaced by <tt>&#95;DOT&#95;</tt> and the reverse replacement when Camel consumes the message.<br/>
   <tt>&#45;</tt> is replaced by <tt>&#95;HYPHEN&#95;</tt> and the reverse replacement when Camel consumes the message.</li>
	<li>See also the option <tt>jmsKeyFormatStrategy</tt> introduced in <b>Camel 2.0</b>, which allows you to use your own custom strategy for formatting keys.</li>
</ul>


<p>For the <tt>exchange.in.header</tt>, the following rules apply for the header <b>values</b>:</p>
<ul class="alternate" type="square">
	<li>The values must be primitives or their counter objects (such as <tt>Integer</tt>, <tt>Long</tt>, <tt>Character</tt>). The types, <tt>String</tt>, <tt>CharSequence</tt>, <tt>Date</tt>, <tt>BigDecimal</tt> and <tt>BigInteger</tt> are all converted to their <tt>toString()</tt> representation. All other types are 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. For example:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
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}
</pre>
</div></div>


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

<p>Camel adds the following properties to the <tt>Exchange</tt> when it receives a message:</p>
<div class="confluenceTableSmall"><div class='table-wrap'>
<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>
</div>
</div>

<p>Camel adds the following JMS properties to the In message headers when it receives a JMS message:</p>
<div class="confluenceTableSmall"><div class='table-wrap'>
<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'> <tt>JMSCorrelationID</tt> </td>
<td class='confluenceTd'> <tt>String</tt> </td>
<td class='confluenceTd'> The JMS correlation ID. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>JMSDeliveryMode</tt> </td>
<td class='confluenceTd'> <tt>int</tt> </td>
<td class='confluenceTd'> The JMS delivery mode. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>JMSDestination</tt> </td>
<td class='confluenceTd'> <tt>javax.jms.Destination</tt> </td>
<td class='confluenceTd'> The JMS destination. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>JMSExpiration</tt> </td>
<td class='confluenceTd'> <tt>long</tt> </td>
<td class='confluenceTd'> The JMS expiration. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>JMSMessageID</tt> </td>
<td class='confluenceTd'> <tt>String</tt> </td>
<td class='confluenceTd'> The JMS unique message ID. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>JMSPriority</tt> </td>
<td class='confluenceTd'> <tt>int</tt> </td>
<td class='confluenceTd'> The JMS priority (with 0 as the lowest priority and 9 as the highest). </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>JMSRedelivered</tt> </td>
<td class='confluenceTd'> <tt>boolean</tt> </td>
<td class='confluenceTd'> Is the JMS message redelivered. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>JMSReplyTo</tt> </td>
<td class='confluenceTd'> <tt>javax.jms.Destination</tt> </td>
<td class='confluenceTd'> The JMS reply-to destination. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>JMSTimestamp</tt> </td>
<td class='confluenceTd'> <tt>long</tt> </td>
<td class='confluenceTd'> The JMS timestamp. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>JMSType</tt> </td>
<td class='confluenceTd'> <tt>String</tt> </td>
<td class='confluenceTd'> The JMS type. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>JMSXGroupID</tt> </td>
<td class='confluenceTd'> <tt>String</tt> </td>
<td class='confluenceTd'> The JMS group ID. </td>
</tr>
</tbody></table>
</div>
</div> 

<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" class="external-link" 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 close attention to how it works in some cases. 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 checks the following conditions:</p>
<ul class="alternate" type="square">
	<li>The message exchange pattern,</li>
	<li>Whether a <tt>JMSReplyTo</tt> was set in the endpoint or in the message headers,</li>
	<li>Whether any of the following options have been set on the JMS endpoint: <tt>disableReplyTo</tt>, <tt>preserveMessageQos</tt>, <tt>explicitQosEnabled</tt>.</li>
</ul>


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

<h4><a name="JMS-JmsProducer"></a>JmsProducer</h4>
<p>The <tt>JmsProducer</tt> behaves as follows, depending on configuration:</p>
<div class="confluenceTableSmall"><div class='table-wrap'>
<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'> <em>InOut</em> </td>
<td class='confluenceTd'> &#45; </td>
<td class='confluenceTd'> Camel will expect a reply, set a temporary <tt>JMSReplyTo</tt>, and after sending the message, it will start to listen for the reply message on the temporary queue. </td>
</tr>
<tr>
<td class='confluenceTd'> <em>InOut</em> </td>
<td class='confluenceTd'> <tt>JMSReplyTo</tt> is 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 specified <tt>JMSReplyTo</tt> queue. </td>
</tr>
<tr>
<td class='confluenceTd'> <em>InOnly</em> </td>
<td class='confluenceTd'> &#45; </td>
<td class='confluenceTd'> Camel will send the message and <b>not</b> expect a reply. </td>
</tr>
<tr>
<td class='confluenceTd'> <em>InOnly</em> </td>
<td class='confluenceTd'> <tt>JMSReplyTo</tt> is set </td>
<td class='confluenceTd'> By default, Camel discards the <tt>JMSReplyTo</tt> destination and clears the <tt>JMSReplyTo</tt> header before sending the message. Camel then sends the message and does <b>not</b> expect a reply. Camel logs this in the log at <tt>WARN</tt> level (changed to <tt>DEBUG</tt> level from <b>Camel 2.6</b> onwards. You can use <tt>preserveMessageQuo=true</tt> to instruct Camel to keep the <tt>JMSReplyTo</tt>. In all situations the <tt>JmsProducer</tt> does <b>not</b> expect any reply and thus continue after sending the message. </td>
</tr>
</tbody></table>
</div>
</div>

<h4><a name="JMS-JmsConsumer"></a>JmsConsumer</h4>
<p>The <tt>JmsConsumer</tt> behaves as follows, depending on configuration:</p>
<div class="confluenceTableSmall"><div class='table-wrap'>
<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'> <em>InOut</em> </td>
<td class='confluenceTd'> &#45; </td>
<td class='confluenceTd'> Camel will send the reply back to the <tt>JMSReplyTo</tt> queue. </td>
</tr>
<tr>
<td class='confluenceTd'> <em>InOnly</em> </td>
<td class='confluenceTd'> &#45; </td>
<td class='confluenceTd'> Camel will not send a reply back, as the pattern is <em>InOnly</em>.</td>
</tr>
<tr>
<td class='confluenceTd'> &#45; </td>
<td class='confluenceTd'> <tt>disableReplyTo=true</tt> </td>
<td class='confluenceTd'> This option suppresses replies. </td>
</tr>
</tbody></table>
</div>
</div>

<p>So pay attention to the message exchange pattern set on your exchanges.</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 panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
from(<span class="code-quote">"activemq:queue:in"</span>)
   .to(<span class="code-quote">"bean:validateOrder"</span>)
   .to(ExchangePattern.InOnly, <span class="code-quote">"activemq:topic:order"</span>)
   .to(<span class="code-quote">"bean:handleOrder"</span>);
</pre>
</div></div>

<h3><a name="JMS-Reuseendpointandsendtodifferentdestinationscomputedatruntime"></a>Reuse endpoint and send 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 specify the real destination in a message header. This allows Camel to reuse the same endpoint, but send to different destinations. This greatly reduces the number of endpoints created and economizes on memory and thread resources.</p>

<p>You can specify the destination in the following headers:</p>
<div class="confluenceTableSmall"><div class='table-wrap'>
<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'> <tt>CamelJmsDestination</tt> </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'> <tt>CamelJmsDestinationName</tt> </td>
<td class='confluenceTd'> <tt>String</tt> </td>
<td class='confluenceTd'> <b>Camel 1.6.2/2.0:</b> The destination name. </td>
</tr>
</tbody></table>
</div>
</div>

<p>For example, the following route shows how you can compute a destination at run time and use it to override the destination appearing in the JMS URL:</p>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
from(<span class="code-quote">"file:<span class="code-comment">//inbox"</span>)
</span>  .to(<span class="code-quote">"bean:computeDestination"</span>)
  .to(<span class="code-quote">"activemq:queue:dummy"</span>);
</pre>
</div></div>

<p>The queue name, <tt>dummy</tt>, is just a placeholder. It must be provided as part of the JMS endpoint URL, but it will be ignored in this example.</p>

<p>In the <tt>computeDestination</tt> bean, specify the real destination by setting the <tt>CamelJmsDestinationName</tt> header as follows:</p>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
<span class="code-keyword">public</span> void setJmsHeader(Exchange exchange) {
   <span class="code-object">String</span> id = ....
   exchange.getIn().setHeader(<span class="code-quote">"CamelJmsDestinationName"</span>, <span class="code-quote">"order:"</span> + id");
}
</pre>
</div></div>

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

<p>If both the <tt>CamelJmsDestination</tt> and the <tt>CamelJmsDestinationName</tt> headers are set, <tt>CamelJmsDestination</tt> takes priority.</p>


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

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

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-xml"><span class="code-tag">&lt;camelContext id=<span class="code-quote">"camel"</span> xmlns=<span class="code-quote">"http://camel.apache.org/schema/spring"</span>&gt;</span>
    <span class="code-tag">&lt;jmxAgent id=<span class="code-quote">"agent"</span> disabled=<span class="code-quote">"true"</span>/&gt;</span>
<span class="code-tag">&lt;/camelContext&gt;</span>

<span class="code-tag">&lt;bean id=<span class="code-quote">"activemq"</span> class=<span class="code-quote">"org.apache.activemq.camel.component.ActiveMQComponent"</span>&gt;</span>
  <span class="code-tag">&lt;property name=<span class="code-quote">"connectionFactory"</span>&gt;</span>
    <span class="code-tag">&lt;bean class=<span class="code-quote">"org.apache.activemq.ActiveMQConnectionFactory"</span>&gt;</span>
      <span class="code-tag">&lt;property name=<span class="code-quote">"brokerURL"</span> value=<span class="code-quote">"vm://localhost?broker.persistent=false&amp;amp;broker.useJmx=false"</span>/&gt;</span>
    <span class="code-tag">&lt;/bean&gt;</span>
  <span class="code-tag">&lt;/property&gt;</span>
<span class="code-tag">&lt;/bean&gt;</span>
</pre>
</div></div>

<p>Basically, you can configure as many JMS component instances as you wish and give them <b>a unique name using the <tt>id</tt> attribute</b>. The preceding example configures an <tt>activemq</tt> component. You could do the same to configure MQSeries, TibCo, BEA, Sonic and so on.</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, <tt>activemq</tt>, you can then refer to destinations using the URI format, <tt>activemq:[queue:&#124;topic:]destinationName</tt>. You can use the same approach for 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 need to look up JNDI to find the JMS <tt>ConnectionFactory</tt> rather than use the usual <tt>&lt;bean&gt;</tt> mechanism in Spring. You can do this using Spring's factory bean or the new Spring XML namespace. For example:</p>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-xml">
<span class="code-tag">&lt;bean id=<span class="code-quote">"weblogic"</span> class=<span class="code-quote">"org.apache.camel.component.jms.JmsComponent"</span>&gt;</span>
  <span class="code-tag">&lt;property name=<span class="code-quote">"connectionFactory"</span> ref=<span class="code-quote">"myConnectionFactory"</span>/&gt;</span>
<span class="code-tag">&lt;/bean&gt;</span>

<span class="code-tag">&lt;jee:jndi-lookup id=<span class="code-quote">"myConnectionFactory"</span> jndi-name=<span class="code-quote">"jms/connectionFactory"</span>/&gt;</span>
</pre>
</div></div>

<p>See <a href="http://static.springsource.org/spring/docs/3.0.x/spring-framework-reference/html/apcs02.html#xsd-config-body-schemas-jee" class="external-link" rel="nofollow">The jee schema</a> in the Spring reference documentation for more details about JNDI lookup.</p>


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

<p>A common requirement with JMS is to consume messages concurrently in multiple threads in order to make an application more responsive. You can set the <tt>concurrentConsumers</tt> option to specify the number of threads servicing the JMS endpoint, as follows:</p>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
from(<span class="code-quote">"jms:SomeQueue?concurrentConsumers=20"</span>).
  bean(MyClass.class);
</pre>
</div></div>

<p>You can configure this option in one of the following ways:</p>
<ul>
	<li>On the <tt>JmsComponent</tt>,</li>
	<li>On the endpoint URI or,</li>
	<li>By invoking <tt>setConcurrentConsumers()</tt> directly on the <tt>JmsEndpoint</tt>.</li>
</ul>



<h3><a name="JMS-RequestreplyoverJMS"></a>Request-reply over JMS</h3>

<p>Camel supports <a href="/confluence/display/CAMEL/Request+Reply" title="Request Reply">Request Reply</a> over JMS. In essence the MEP of the Exchange should be <tt>InOut</tt> when you send a message to a JMS queue.<br/>
The <tt>JmsProducer</tt> detects the <tt>InOut</tt> and provides a <tt>JMSReplyTo</tt> header with the reply destination to be used. By default Camel uses a temporary queue, but you can use the <tt>replyTo</tt> option on the endpoint to specify a fixed reply queue (see more below about fixed reply queue). </p>

<p>Camel will automatic setup a consumer which listen on the reply queue, so you should <b>not</b> do anything.<br/>
This consumer is a Spring <tt>DefaultMessageListenerContainer</tt> which listen for replies. However it's fixed to 1 concurrent consumer.<br/>
That means replies will be processed in sequence as there are only 1 thread to process the replies. If you want to process replies faster, then we need to use concurrency. But <b>not</b> using the <tt>concurrentConsumer</tt> option. We should use the <tt>threads</tt> from the Camel DSL instead, as shown in the route below:</p>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
from(xxx)
.inOut().to(<span class="code-quote">"activemq:queue:foo"</span>)
.threads(5)
.to(yyy)
.to(zzz);
</pre>
</div></div>

<p>In this route we instruct Camel to route replies <a href="/confluence/display/CAMEL/Async" title="Async">asynchronously</a> using a thread pool with 5 threads. </p>

<h4><a name="JMS-RequestreplyoverJMSandusingasharedfixedreplyqueue"></a>Request-reply over JMS and using a shared fixed reply queue</h4>
<p>If you use a fixed reply queue when doing <a href="/confluence/display/CAMEL/Request+Reply" title="Request Reply">Request Reply</a> over JMS as shown in the example below, then pay attention.</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
from(xxx)
.inOut().to(<span class="code-quote">"activemq:queue:foo?replyTo=bar"</span>)
.to(yyy)
</pre>
</div></div>

<p>In this example the fixed reply queue named "bar" is used. By default Camel assumes the queue is shared when using fixed reply queues, and therefore it uses a <tt>JMSSelector</tt> to only pickup the expected reply messages (eg based on the <tt>JMSCorrelationID</tt>). See next section for exclusive fixed reply queues. That means its not as fast as temporary queues. You can speedup how often Camel will pull for reply messages using the <tt>receiveTimeout</tt> option. By default its 1000 millis. So to make it faster you can set it to 250 millis to pull 4 times per second as shown:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
from(xxx)
.inOut().to(<span class="code-quote">"activemq:queue:foo?replyTo=bar&amp;receiveTimeout=250"</span>)
.to(yyy)
</pre>
</div></div>

<p>Notice this will cause the Camel to send pull requests to the message broker more frequent, and thus require more network traffic.<br/>
It is generally recommended to use temporary queues if possible.</p>

<h4><a name="JMS-RequestreplyoverJMSandusinganexclusivefixedreplyqueue"></a>Request-reply over JMS and using an exclusive fixed reply queue</h4>
<p><b>Available as of Camel 2.9</b></p>

<p>In the previous example, Camel would anticipate the fixed reply queue named "bar" was shared, and thus it uses a <tt>JMSSelector</tt> to only consume reply messages which it expects. However there is a drawback doing this as JMS selectos is slower. Also the consumer on the reply queue is slower to update with new JMS selector ids. In fact it only updates when the <tt>receiveTimeout</tt> option times out, which by default is 1 second. So in theory the reply messages could take up till about 1 sec to be detected. On the other hand if the fixed reply queue is exclusive to the Camel reply consumer, then we can avoid using the JMS selectors, and thus be more performant. In fact as fast as using temporary queues. So in <b>Camel 2.9</b> onwards we introduced the <tt>ReplyToType</tt> option which you can configure to <tt>Exclusive</tt><br/>
to tell Camel that the reply queue is exclusive as shown in the example below:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
from(xxx)
.inOut().to(<span class="code-quote">"activemq:queue:foo?replyTo=bar?replyToType=Exclusive"</span>)
.to(yyy)
</pre>
</div></div>

<p>Mind that the queue must be exclusive to each and every endpoint. So if you have two routes, then they each need an unique reply queue as shown in the next example:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
from(xxx)
.inOut().to(<span class="code-quote">"activemq:queue:foo?replyTo=bar?replyToType=Exclusive"</span>)
.to(yyy)

from(aaa)
.inOut().to(<span class="code-quote">"activemq:queue:order?replyTo=order.reply?replyToType=Exclusive"</span>)
.to(bbb)
</pre>
</div></div>

<p>The same applies if you run in a clustered environment. Then each node in the cluster must use an unique reply queue name. As otherwise each node in the cluster may pickup messages which was intended as a reply on another node. For clustered environments its recommended to use shared reply queues instead.</p>



<h3><a name="JMS-Synchronizingclocksbetweensendersandreceivers"></a>Synchronizing clocks between senders and receivers</h3>
<p>When doing messaging between systems, its desirable that the systems have synchronized clocks. For example when sending a <a href="/confluence/display/CAMEL/JMS" title="JMS">JMS</a> message, then you can set a time to live value on the message. Then the receiver can inspect this value, and determine if the message is already expired, and thus drop the message instead of consume and process it. However this requires that both sender and receiver have synchronized clocks. If you are using <a href="http://activemq.apache.org/" class="external-link" rel="nofollow">ActiveMQ</a> then you can use the <a href="http://activemq.apache.org/timestampplugin.html" class="external-link" rel="nofollow">timestamp plugin</a> to synchronize clocks. </p>

<h3><a name="JMS-Abouttimetolive"></a>About time to live</h3>
<p>Read first above about synchronized clocks. </p>

<p>When you do request/reply (InOut) over <a href="/confluence/display/CAMEL/JMS" title="JMS">JMS</a> with Camel then Camel uses a timeout on the sender side, which is default 20 seconds from the <tt>requestTimeout</tt> option. You can control this by setting a higher/lower value. However the time to live value is still set on the <a href="/confluence/display/CAMEL/JMS" title="JMS">JMS</a> message being send. So that requires the clocks to be synchronized between the systems. If they are not, then you may want to disable the time to live value being set. This is now possible using the <tt>disableTimeToLive</tt> option from <b>Camel 2.8</b> onwards. So if you set this option to <tt>disableTimeToLive=true</tt>, then Camel does <b>not</b> set any time to live value when sending <a href="/confluence/display/CAMEL/JMS" title="JMS">JMS</a> messages. <b>But</b> the request timeout is still active. So for example if you do request/reply over <a href="/confluence/display/CAMEL/JMS" title="JMS">JMS</a> and have disabled time to live, then Camel will still use a timeout by 20 seconds (the <tt>requestTimeout</tt> option). That option can of course also be configured. So the two options <tt>requestTimeout</tt> and <tt>disableTimeToLive</tt> gives you fine grained control when doing request/reply.</p>

<p>When you do fire and forget (InOut) over <a href="/confluence/display/CAMEL/JMS" title="JMS">JMS</a> with Camel then Camel by default does <b>not</b> set any time to live value on the message. You can configure a value by using the <tt>timeToLive</tt> option. For example to indicate a 5 sec., you set <tt>timeToLive=5000</tt>. The option <tt>disableTimeToLive</tt> can be used to force disabling the time to live, also for InOnly messaging. The <tt>requestTimeout</tt> option is not being used for InOnly messaging.</p>


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

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

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


<p>See 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>Transactions and <a href="/confluence/display/CAMEL/Request+Reply" title="Request Reply">Request Reply</a> over JMS</b><br />When using <a href="/confluence/display/CAMEL/Request+Reply" title="Request Reply">Request Reply</a> over JMS you cannot use a single transaction; 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. Therefore to use <a href="/confluence/display/CAMEL/Request+Reply" title="Request Reply">Request Reply</a> you must commit a transaction after sending the request and then use a separate transaction for receiving the response.

<p>To address this issue the JMS component uses different properties to specify transaction use for oneway messaging and request reply messaging:</p>

<p>The <tt>transacted</tt> property applies <b>only</b> to the InOnly message <a href="/confluence/display/CAMEL/Exchange+Pattern" title="Exchange Pattern">Exchange Pattern</a> (MEP).</p>

<p>The <tt>transactedInOut</tt> property applies to the InOut(<a href="/confluence/display/CAMEL/Request+Reply" title="Request Reply">Request Reply</a>) message <a href="/confluence/display/CAMEL/Exchange+Pattern" title="Exchange Pattern">Exchange Pattern</a> (MEP).</p>

<p>If you want to use transactions for <a href="/confluence/display/CAMEL/Request+Reply" title="Request Reply">Request Reply</a>(InOut MEP), you <b>must</b> set <tt>transactedInOut=true</tt>.</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 sets an Exchange property with the value of the ReplyTo <tt>javax.jms.Destination</tt> object, having the key <tt>ReplyTo</tt>. You can obtain this <tt>Destination</tt> as follows:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
Destination replyDestination = exchange.getIn().getHeader(JmsConstants.JMS_REPLY_DESTINATION, Destination.class);
</pre>
</div></div>

<p>And then later use it to send a reply using regular JMS or Camel.</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
    <span class="code-comment">// we need to pass in the JMS component, and in <span class="code-keyword">this</span> sample we use ActiveMQ
</span>    JmsEndpoint endpoint = JmsEndpoint.newInstance(replyDestination, activeMQComponent);
    <span class="code-comment">// now we have the endpoint we can use regular Camel API to send a message to it
</span>    template.sendBody(endpoint, <span class="code-quote">"Here is the late reply."</span>);
</pre>
</div></div>

<p>A different solution to sending a reply is to provide the <tt>replyDestination</tt> object in the same Exchange property when sending. Camel will then pick up this property and use it for the real destination. The endpoint URI must include a dummy destination, however. For example:</p>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
    <span class="code-comment">// we pretend to send it to some non existing dummy queue
</span>    template.send("activemq:queue:dummy, <span class="code-keyword">new</span> Processor() {
        <span class="code-keyword">public</span> void process(Exchange exchange) <span class="code-keyword">throws</span> Exception {
            <span class="code-comment">// and here we override the destination with the ReplyTo destination object so the message is sent to there instead of dummy
</span>            exchange.getIn().setHeader(JmsConstants.JMS_DESTINATION, replyDestination);
            exchange.getIn().setBody(<span class="code-quote">"Here is the late reply."</span>);
        }
    }
</pre>
</div></div>


<h3><a name="JMS-Usingarequesttimeout"></a>Using a 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>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java"><span class="code-comment">// send a in-out with a timeout <span class="code-keyword">for</span> 5 sec
</span><span class="code-object">Object</span> out = template.requestBody(<span class="code-quote">"activemq:queue:slow?requestTimeout=5000"</span>, <span class="code-quote">"Hello World"</span>);
</pre>
</div></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 the following sample we configure a route that receives JMS messages and routes the message to a POJO:</p>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
   from(<span class="code-quote">"jms:queue:foo"</span>).
     to(<span class="code-quote">"bean:myBusinessLogic"</span>);
</pre>
</div></div>

<p>You can of course use any of the EIP patterns so the route can be context based. For example, here's how to filter an order topic for the big spenders:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
from(<span class="code-quote">"jms:topic:OrdersTopic"</span>).
  filter().method(<span class="code-quote">"myBean"</span>, <span class="code-quote">"isGoldCustomer"</span>).
    to(<span class="code-quote">"jms:queue:BigSpendersQueue"</span>);
</pre>
</div></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 <tt>TextMessage</tt> instead of a <tt>BytesMessage</tt>, we need to convert the body to a <tt>String</tt>:</p>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
from(<span class="code-quote">"file:<span class="code-comment">//orders"</span>).
</span>  convertBodyTo(<span class="code-object">String</span>.class).
  to(<span class="code-quote">"jms:topic:OrdersTopic"</span>);
</pre>
</div></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 preceding examples use the Java DSL. Camel also supports Spring XML DSL. Here is the big spender sample using Spring DSL:</p>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-xml">
<span class="code-tag">&lt;route&gt;</span>
  <span class="code-tag">&lt;from uri=<span class="code-quote">"jms:topic:OrdersTopic"</span>/&gt;</span>
  <span class="code-tag">&lt;filter&gt;</span>
    <span class="code-tag">&lt;method bean=<span class="code-quote">"myBean"</span> method=<span class="code-quote">"isGoldCustomer"</span>/&gt;</span>
    <span class="code-tag">&lt;to uri=<span class="code-quote">"jms:queue:BigSpendersQueue"</span>/&gt;</span>
  <span class="code-tag">&lt;/filter&gt;</span>
<span class="code-tag">&lt;/route&gt;</span>
</pre>
</div></div>

<h4><a name="JMS-Othersamples"></a>Other samples</h4>
<p>JMS appears in many of the examples for other components and EIP patterns, as well in this Camel documentation. So feel free to browse the documentation. If you have time, 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 the transport, it only transfers the body and headers as the payload. If you want to use <a href="/confluence/display/CAMEL/JMS" title="JMS">JMS</a> with a <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, however, use the <b>transferExchange</b> option 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 retrieve the caused exception from the Exchange property with the key <tt>Exchange.EXCEPTION_CAUGHT</tt>. The demo below illustrates this:</p>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
<span class="code-comment">// setup error handler to use JMS as queue and store the entire Exchange
</span>errorHandler(deadLetterChannel(<span class="code-quote">"jms:queue:dead?transferExchange=<span class="code-keyword">true</span>"</span>));
</pre>
</div></div>

<p>Then you can consume from the JMS queue and analyze the problem:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
from(<span class="code-quote">"jms:queue:dead"</span>).to(<span class="code-quote">"bean:myErrorAnalyzer"</span>);

<span class="code-comment">// and in our bean
</span><span class="code-object">String</span> body = exchange.getIn().getBody();
Exception cause = exchange.getProperty(Exchange.EXCEPTION_CAUGHT, Exception.class);
<span class="code-comment">// the cause message is
</span><span class="code-object">String</span> problem = cause.getMessage();
</pre>
</div></div>

<h4><a name="JMS-UsingJMSasaDeadLetterChannelstoringerroronly"></a>Using JMS as a Dead Letter Channel storing error only</h4>
<p>You can use JMS to store the cause error message or to store a custom body, which you can initialize yourself. The following example uses the <a href="/confluence/display/CAMEL/Message+Translator" title="Message Translator">Message Translator</a> EIP to do a transformation on the failed exchange before it is moved to the <a href="/confluence/display/CAMEL/JMS" title="JMS">JMS</a> dead letter queue:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
<span class="code-comment">// we sent it to a seda dead queue first
</span>errorHandler(deadLetterChannel(<span class="code-quote">"seda:dead"</span>));

<span class="code-comment">// and on the seda dead queue we can <span class="code-keyword">do</span> the custom transformation before its sent to the JMS queue
</span>from(<span class="code-quote">"seda:dead"</span>).transform(exceptionMessage()).to(<span class="code-quote">"jms:queue:dead"</span>);
</pre>
</div></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. For example, you can invoke a method on a Bean or use a custom processor.</p>

<h3><a name="JMS-SendinganInOnlymessageandkeepingtheJMSReplyToheader"></a>Sending an InOnly message and keeping the JMSReplyTo header</h3>

<p>When sending to a <a href="/confluence/display/CAMEL/JMS" title="JMS">JMS</a> destination using <b>camel-jms</b> the producer will use the MEP to detect if its InOnly or InOut messaging. However there can be times where you want to send an InOnly message but keeping the JMSReplyTo header. To do so you have to instruct Camel to keep it, otherwise the JMSReplyTo header will be dropped.</p>

<p>For example to send an InOnly message to the foo queue, but with a JMSReplyTo with bar queue you can do as follows:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
        template.send(<span class="code-quote">"activemq:queue:foo?preserveMessageQos=<span class="code-keyword">true</span>"</span>, <span class="code-keyword">new</span> Processor() {
            <span class="code-keyword">public</span> void process(Exchange exchange) <span class="code-keyword">throws</span> Exception {
                exchange.getIn().setBody(<span class="code-quote">"World"</span>);
                exchange.getIn().setHeader(<span class="code-quote">"JMSReplyTo"</span>, <span class="code-quote">"bar"</span>);
            }
        });
</pre>
</div></div>

<p>Notice we use <tt>preserveMessageQos=true</tt> to instruct Camel to keep the JMSReplyTo header.</p>

<h3><a name="JMS-SettingJMSprovideroptionsonthedestination"></a>Setting JMS provider options on the destination</h3>

<p>Some JMS providers, like IBM's WebSphere MQ need options to be set on the JMS destination. For example, you may need to specify the targetClient option. Since targetClient is a WebSphere MQ option and not a Camel URI option, you need to set that on the JMS destination name like so:</p>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
...
.setHeader(<span class="code-quote">"CamelJmsDestinationName"</span>, constant(<span class="code-quote">"queue:<span class="code-comment">///MY_QUEUE?targetClient=1"</span>))
</span>.to(<span class="code-quote">"wmq:queue:MY_QUEUE?useMessageIDAsCorrelationID=<span class="code-keyword">true</span>"</span>);
</pre>
</div></div>

<p>Some versions of WMQ won't accept this option on the destination name and you will get an exception like:</p>

<blockquote>
<p>com.ibm.msg.client.jms.DetailedJMSException: JMSCC0005: The specified value 'MY_QUEUE?targetClient=1' is not allowed for 'XMSC_DESTINATION_NAME'</p></blockquote>

<p>A workaround is to use a custom DestinationResolver:</p>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
JmsComponent wmq = <span class="code-keyword">new</span> JmsComponent(connectionFactory); 
        
wmq.setDestinationResolver(<span class="code-keyword">new</span> DestinationResolver(){ 
    <span class="code-keyword">public</span> Destination resolveDestinationName(Session session, <span class="code-object">String</span> destinationName, <span class="code-object">boolean</span> pubSubDomain) <span class="code-keyword">throws</span> JMSException { 
        MQQueueSession wmqSession = (MQQueueSession) session;	
        <span class="code-keyword">return</span> wmqSession.createQueue(<span class="code-quote">"queue:<span class="code-comment">///"</span> + destinationName + <span class="code-quote">"?targetClient=1"</span>); 
</span>    }        
}); 
</pre>
</div></div>

<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" class="external-link" rel="nofollow">JMSTemplate gotchas</a></li>
</ul>

    </div>
        <div id="commentsSection" class="wiki-content pageSection">
        <div style="float: right;">
            <a href="https://cwiki.apache.org/confluence/users/viewnotifications.action" class="grey">Change Notification Preferences</a>
        </div>
        <a href="https://cwiki.apache.org/confluence/display/CAMEL/JMS">View Online</a>
        |
        <a href="https://cwiki.apache.org/confluence/pages/diffpagesbyversion.action?pageId=51893&revisedVersion=148&originalVersion=147">View Changes</a>
                |
        <a href="https://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