Camel Components

JMS

Since Camel 1.0

Both producer and consumer are supported

This component allows messages to be sent to (or consumed from) a JMS Queue or Topic. It uses Spring’s JMS support for declarative transactions, including Spring’s JmsTemplate for sending and a MessageListenerContainer for consuming.

Maven users will need to add the following dependency to their pom.xml for this component:

<dependency>
    <groupId>org.apache.camel</groupId>
    <artifactId>camel-jms</artifactId>
    <version>x.x.x</version>
    <!-- use the same version as your Camel core version -->
</dependency>

Using ActiveMQ

If you are using Apache ActiveMQ Classic, you should prefer the ActiveMQ component as it has been optimized for ActiveMQ. All the options and samples on this page are also valid for the ActiveMQ component. For ActiveMQ Artemis, use this component, as shown in Connecting to a broker below.

Transacted and caching

See section Transactions and Cache Levels below if you are using transactions with JMS as it can impact performance.

Request/Reply over JMS

Make sure to read the section Request-reply over JMS further below on this page for important notes about request/reply, as Camel offers a number of options to configure for performance, and clustered environments.

Connecting to a broker

The JMS component needs a ConnectionFactory from the client library of the broker. Create it as a bean, and set it on the component with the connectionFactory option. Put a connection pool around it: without a pool, the component opens a new connection for every message it sends.

For example, for ActiveMQ Artemis (such as the broker that camel infra run artemis starts), with the pooled-jms connection pool:

  • Application properties

  • Java

  • Spring XML

camel.beans.artemisCF = #class:org.apache.activemq.artemis.jms.client.ActiveMQConnectionFactory
camel.beans.artemisCF.brokerURL = tcp://localhost:61616
camel.beans.artemisCF.user = artemis
camel.beans.artemisCF.password = artemis
camel.beans.pooledCF = #class:org.messaginghub.pooled.jms.JmsPoolConnectionFactory
camel.beans.pooledCF.connectionFactory = #bean:artemisCF
camel.beans.pooledCF.maxConnections = 8
camel.component.jms.connection-factory = #bean:pooledCF
ActiveMQConnectionFactory artemis = new ActiveMQConnectionFactory("tcp://localhost:61616", "artemis", "artemis");
JmsPoolConnectionFactory pool = new JmsPoolConnectionFactory();
pool.setConnectionFactory(artemis);
pool.setMaxConnections(8);
context.getComponent("jms", JmsComponent.class).setConnectionFactory(pool);
<bean id="artemisCF" class="org.apache.activemq.artemis.jms.client.ActiveMQConnectionFactory">
  <property name="brokerURL" value="tcp://localhost:61616"/>
  <property name="user" value="artemis"/>
  <property name="password" value="artemis"/>
</bean>

<bean id="pooledCF" class="org.messaginghub.pooled.jms.JmsPoolConnectionFactory" destroy-method="stop">
  <property name="connectionFactory" ref="artemisCF"/>
  <property name="maxConnections" value="8"/>
</bean>

<bean id="jms" class="org.apache.camel.component.jms.JmsComponent">
  <property name="connectionFactory" ref="pooledCF"/>
</bean>

The application properties work with routes in any DSL (YAML, XML or Java) on Camel Main and Camel JBang. Then the routes use the broker as usual, for example jms:queue:orders.

When the registry has exactly one ConnectionFactory, the component uses it without the connectionFactory option (allowAutoWiredConnectionFactory, which is on by default). The example has two, the one of the client and the pool, so it sets the pool on the component.

When no connection factory is set, the endpoints fail with connectionFactory must be specified. The message names the endpoint and says why the component did not autowire one: the registry has no ConnectionFactory, or several, which it names.

camel run downloads the client libraries of these classes. In a Maven project, add org.apache.artemis:artemis-jakarta-client and org.messaginghub:pooled-jms.

Other brokers work the same way, with the ConnectionFactory of their client library, for example com.ibm.mq.jakarta.jms.MQConnectionFactory for IBM MQ (with hostName, port, channel, queueManager, and transportType set to 1 for a client connection). For ActiveMQ Classic, the ActiveMQ component sets up the connection factory from a brokerURL.

Rotated credentials

When a vault detects that a secret changed and Camel reloads the context, the JMS component uses the new value of the username and password options:

  • set in an endpoint URI, such as jms:queue:orders?username=camel&password=RAW({{aws:jms/password}}): the routes and their endpoints are created again, with the new value. Keep RAW() around the placeholder: Camel resolves it before it parses the URI, and a generated secret can contain +, & or %, which would change the password or break the URI after a rotation.

  • set with a placeholder on the component, such as camel.component.jms.password = {{aws:jms/password}} on Camel Main: the component is created again with the new value, and the endpoints of the reloaded routes use it.

With a new password the component wraps its connection factory in a new UserCredentialsConnectionFactoryAdapter, so the new connections authenticate with it. A pool that keys its connections by username and password, such as pooled-jms, then opens new connections for the new password, and no longer hands out the ones opened with the old one.

The connection factory bean is not reloaded, and the component does not create it, so it cannot authenticate it again:

  • A connection factory of the broker client keeps the user and password it was created with, also when they are set with a placeholder such as camel.beans.artemisCF.password = {{aws:jms/password}}: a reload does not change a bean that exists already.

  • A pool, or a Spring CachingConnectionFactory, keeps the connections it has open, authenticated with the credentials of the connection factory it wraps. A CachingConnectionFactory cannot take username and password from the component, as it does not support credentials per connection.

So when the credentials rotate, set them on the component or the endpoints, not on the connection factory. Otherwise the connection factory must be created again by the application, or the application restarted.

URI format

jms:[queue:|topic:]destinationName[?options]

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

jms:FOO.BAR

You can include the optional queue: prefix, if you prefer:

jms:queue:FOO.BAR

To connect to a topic, you must include the topic: prefix. For example, to
connect to the topic, Stocks.Prices, use:

jms:topic:Stocks.Prices

You append query options to the URI by using the following format, ?option=value&option=value&…​

Notes

Using ActiveMQ

The JMS component reuses Spring’s JmsTemplate 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 poor performance.

If you intend to use Apache ActiveMQ as your message broker, the recommendation is that you do one of the following:

  • Use the ActiveMQ component, which is already optimized to use ActiveMQ efficiently

  • Use the PoolingConnectionFactory in ActiveMQ.

Transactions and Cache Levels

If you are consuming messages and using transactions (transacted=true) then the default settings for cache level can impact performance.

If you are using XA transactions, then you cannot cache as it can cause the XA transaction to not work properly.

If you are not using XA, then you should consider caching as it speeds up performance, such as setting cacheLevelName=CACHE_CONSUMER.

The default setting for cacheLevelName is CACHE_AUTO. This default auto-detects the mode and sets the cache level accordingly to:

  • CACHE_CONSUMER if transacted=false

  • CACHE_NONE if transacted=true

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

Durable Subscriptions

Durable Subscriptions with JMS 2.0

If you wish to use durable topic subscriptions, you need to specify the durableSubscriptionName.

Durable Subscriptions with JMS 1.1

If you wish to use durable topic subscriptions, you need to specify both clientId and durableSubscriptionName. The value of the clientId must be unique and can only be used by a single JMS connection instance in your entire network.

If you are using the Apache ActiveMQ Classic or Apache ActiveMQ Artemis, you may prefer to use a feature called Virtual Topic. This should remove the necessity of having a unique clientId.

You can consult the specific documentation for Artemis or for ActiveMQ Classic for details about how to leverage this feature.

You can find more details about durable messaging for ActiveMQ Classic here.

Message Header Mapping

When using message headers, the JMS specification states that header names must be valid Java identifiers. So try to name your headers to be 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).

The current header name strategy for accepting header names in Camel is as follows:

  • Dots are replaced by _DOT_ and the replacement is reversed when Camel consume the message

  • Hyphen is replaced by _HYPHEN_ and the replacement is reversed when Camel consumes the message

Camel comes with two implementations of HeaderFilterStrategy:

  • org.apache.camel.component.jms.ClassicJmsHeaderFilterStrategy - classic strategy used until Camel 4.8.

  • org.apache.camel.component.jms.JmsHeaderFilterStrategy - newer default strategy from Camel 4.9 onwards.

ClassicJmsHeaderFilterStrategy

A classic strategy for mapping header names is used in Camel 4.8 or older.

This strategy also includes Camel internal headers such as CamelFileName and CamelBeanMethodName which means that you can send Camel messages over JMS to another Camel instance and preserve this information. However, this also means that JMS messages contains properties with Camel…​ keys. This is not desirable always, and therefore we changed default from Camel 4.9 onwards.

You can always configure a custom HeaderFilterStrategy to remove all Camel…​ headers in Camel 4.8 or older.

JmsHeaderFilterStrategy

The new default strategy from Camel 4.9 onwards behaves similar to other components, where Camel…​ headers are removed, and only allowing explicit end user headers.

Mapping to Spring JMS

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.

Configuring Options

Camel components are configured on two separate levels:

  • component level

  • endpoint level

Configuring Component Options

At the component level, you set general and shared configurations that are, then, inherited by the endpoints. It is the highest configuration level.

For example, a component may have security settings, credentials for authentication, urls for network connection and so forth.

Some components only have a few options, and others may have many. Because components typically have pre-configured defaults that are commonly used, then you may often only need to configure a few options on a component; or none at all.

You can configure components using:

  • the Component DSL.

  • in a configuration file (application.properties, *.yaml files, etc).

  • directly in the Java code.

Configuring Endpoint Options

You usually spend more time setting up endpoints because they have many options. These options help you customize what you want the endpoint to do. The options are also categorized into whether the endpoint is used as a consumer (from), as a producer (to), or both.

Configuring endpoints is most often done directly in the endpoint URI as path and query parameters. You can also use the Endpoint DSL and DataFormat DSL as a type safe way of configuring endpoints and data formats in Java.

A good practice when configuring options is to use Property Placeholders.

Property placeholders provide a few benefits:

  • They help prevent using hardcoded urls, port numbers, sensitive information, and other settings.

  • They allow externalizing the configuration from the code.

  • They help the code to become more flexible and reusable.

The following two sections list all the options, firstly for the component followed by the endpoint.

Component Options

The JMS component supports the following options which are listed below.

Name Description Default Type

clientId (common)

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 with JMS 1.1.

String

connectionFactory (common)

The jakarta.jms.ConnectionFactory that the consumers and producers create their JMS connections with. When none is configured, the component uses the single ConnectionFactory found in the registry (see allowAutoWiredConnectionFactory).

ConnectionFactory

disableReplyTo (common)

Whether to disable request/reply. A consumer then ignores the JMSReplyTo of the received messages and sends no reply, for example when another part of the application sends the reply, or when Camel routes the messages from one message broker to another. A producer sends the messages as InOnly and without JMSReplyTo, also when the exchange is InOut.

false

boolean

durableSubscriptionName (common)

The name of a durable topic subscription. Setting it makes the subscription durable, as subscriptionDurable together with subscriptionName does (subscriptionName takes precedence for the name). A durable subscription that is not shared also requires the clientId option.

String

jmsMessageType (common)

The JMS message type (Bytes, Map, Object, Stream or Text) of the messages that the producer sends (also the requests of request/reply) and of the replies that the consumer sends, instead of the type that Camel chooses from the message body. The CamelJmsMessageType header overrides it. Not used when receiving, as a received message keeps the type that its sender chose. Object requires objectMessageEnabled.

Enum values:

  • Bytes

  • Map

  • Object

  • Stream

  • Text

JmsMessageType

replyTo (common)

The reply destination. A producer doing request/reply over JMS sets it as JMSReplyTo of the request and receives the replies from it (see replyToType); without it, a temporary queue is used. A consumer sends its replies to it, instead of to the JMSReplyTo of the received message.

String

testConnectionOnStartup (common)

Whether the consumers and producers create (and close) a JMS connection when they start, so that Camel fails to start, with an exception, when the JMS broker cannot be reached, instead of starting with failed connections.

false

boolean

acknowledgementModeName (consumer)

The JMS acknowledgement mode of the sessions of the consumer: AUTO_ACKNOWLEDGE, CLIENT_ACKNOWLEDGE, DUPS_OK_ACKNOWLEDGE or SESSION_TRANSACTED. Not used when transacted is enabled, as the sessions are then transacted. With the DefaultMessageListenerContainer, AUTO_ACKNOWLEDGE acknowledges a message when it is received, before the route processes it, so a failed message is not redelivered. CLIENT_ACKNOWLEDGE acknowledges it after it has been processed successfully, and transacted also redelivers it when the processing fails.

Enum values:

  • SESSION_TRANSACTED

  • CLIENT_ACKNOWLEDGE

  • AUTO_ACKNOWLEDGE

  • DUPS_OK_ACKNOWLEDGE

AUTO_ACKNOWLEDGE

String

artemisConsumerPriority (consumer)

The consumer priority of the consumer on an Apache ActiveMQ Artemis broker, which Camel adds to the destination name as the consumer-priority parameter (0, the default, adds none). The broker delivers the messages to the consumers of the highest priority (round-robin between those of the same priority), and to consumers of a lower priority only when those have no credit or do not accept the message, for example because of their selector.

int

asyncConsumer (consumer)

Whether the JmsConsumer processes the Exchange asynchronously. If enabled then the JmsConsumer may pickup the next message from the JMS queue, while the previous message is being processed asynchronously (by the Asynchronous Routing Engine). This means that messages may be processed not 100% strictly in order. If disabled (as default) then the Exchange is fully processed before the JmsConsumer will pickup the next message from the JMS queue. Note if transacted has been enabled, then asyncConsumer=true does not run asynchronously, as transaction must be executed synchronously.

false

boolean

autoStartup (consumer)

Whether the consumer starts its listener container, and so receives messages, when the consumer starts. When disabled, the listener container is started when the consumer is resumed.

true

boolean

cacheLevel (consumer)

The cache level of the JMS resources of the DefaultMessageListenerContainer of the consumer, by number: 0 (CACHE_NONE), 1 (CACHE_CONNECTION), 2 (CACHE_SESSION), 3 (CACHE_CONSUMER) or 4 (CACHE_AUTO). Takes precedence over cacheLevelName, which describes the levels.

int

cacheLevelName (consumer)

The cache level of the JMS resources (connection, session and consumer) that the DefaultMessageListenerContainer of the consumer keeps between receives: CACHE_NONE, CACHE_CONNECTION, CACHE_SESSION, CACHE_CONSUMER or CACHE_AUTO. CACHE_AUTO uses CACHE_NONE when there is a transaction manager (including the JmsTransactionManager that Camel creates when transacted is enabled), and CACHE_CONSUMER otherwise. Not used by the SimpleMessageListenerContainer. See also cacheLevel.

Enum values:

  • CACHE_AUTO

  • CACHE_CONNECTION

  • CACHE_CONSUMER

  • CACHE_NONE

  • CACHE_SESSION

CACHE_AUTO

String

concurrentConsumers (consumer)

The number of concurrent consumers that consume from the destination: the minimum number with the DefaultMessageListenerContainer, which scales up to maxConcurrentConsumers. The SimpleMessageListenerContainer uses a fixed number, which is maxConcurrentConsumers when that is set. Not used by the reply consumer of request/reply over JMS (see replyToConcurrentConsumers). On a topic, each consumer has its own subscription and receives every message, unless subscriptionShared is enabled.

1

int

maxConcurrentConsumers (consumer)

The maximum number of concurrent consumers that consume from the destination: the DefaultMessageListenerContainer scales between concurrentConsumers and this number (see also maxMessagesPerTask, idleTaskExecutionLimit and idleConsumerLimit), and the SimpleMessageListenerContainer uses this fixed number of consumers. Must not be lower than concurrentConsumers. Not used by the reply consumer of request/reply over JMS (see replyToMaxConcurrentConsumers). On a topic, each consumer has its own subscription and receives every message, unless subscriptionShared is enabled.

int

replyToDeliveryPersistent (consumer)

Whether the consumer sends its replies of request/reply with persistent delivery (PERSISTENT) or not (NON_PERSISTENT). Takes effect only when the QoS options of the endpoint of the consumer are used (see explicitQosEnabled), not with preserveMessageQos.

true

boolean

selector (consumer)

The JMS message selector (an SQL-92 conditional expression on the JMS headers and properties of the messages, such as color = 'red') that the consumer uses to receive only the matching messages.

String

subscriptionDurable (consumer)

Whether the topic subscription is durable, so the JMS broker keeps its messages while the consumer is not connected. Its name is set with subscriptionName. Only for topics: Spring JMS switches the listener container to the publish-subscribe domain when it is enabled. A durable subscription that is not shared also requires the clientId option.

false

boolean

subscriptionName (consumer)

The name of the shared or durable topic subscription to create. It must be unique within the JMS client id of the connection. Defaults to the class name of the message listener (org.apache.camel.component.jms.EndpointMessageListener). A subscription that is not shared allows only one concurrent consumer.

String

subscriptionShared (consumer)

Whether the topic subscription is shared (JMS 2.0), so its consumers (the concurrent consumers, and those of other connections that use the same subscriptionName) share its messages, instead of each receiving every message. Can be combined with subscriptionDurable. Only for topics: Spring JMS switches the listener container to the publish-subscribe domain when it is enabled. Requires a JMS 2.0 message broker.

false

boolean

acceptMessagesWhileStopping (consumer (advanced))

Specifies whether the consumer accept messages while it is stopping. You may consider enabling this option, if you start and stop JMS routes at runtime, while there are still messages enqueued on the queue. If this option is false, and you stop the JMS route, then messages may be rejected, and the JMS broker would have to attempt redeliveries, which yet again may be rejected, and eventually the message may be moved at a dead letter queue on the JMS broker. To avoid this its recommended to enable this option.

false

boolean

allowReplyManagerQuickStop (consumer (advanced))

Whether the DefaultMessageListenerContainer of the reply consumer of request/reply over JMS stops receiving right away when the CamelContext is stopping and acceptMessagesWhileStopping is disabled, as the regular JMS consumers do. Disabled by default, so the reply consumer keeps receiving replies while the CamelContext is stopping.

false

boolean

consumerType (consumer (advanced))

The consumer type to use, which can be one of: Simple, Default, or Custom. The consumer type determines which Spring JMS listener to use. Default will use org.springframework.jms.listener.DefaultMessageListenerContainer, Simple will use org.springframework.jms.listener.SimpleMessageListenerContainer. When Custom is specified, the MessageListenerContainerFactory defined by the messageListenerContainerFactory option will determine what org.springframework.jms.listener.AbstractMessageListenerContainer to use.

Enum values:

  • Simple

  • Default

  • Custom

Default

ConsumerType

defaultTaskExecutorType (consumer (advanced))

Specifies what default TaskExecutor type to use in the DefaultMessageListenerContainer, for both consumer endpoints and the ReplyTo consumer of producer endpoints. Possible values: SimpleAsync (uses Spring’s SimpleAsyncTaskExecutor) or ThreadPool (uses Spring’s ThreadPoolTaskExecutor with optimal values - cached thread-pool-like). If not set, it defaults to the previous behaviour, which uses a cached thread pool for consumer endpoints and SimpleAsync for reply consumers. The use of ThreadPool is recommended to reduce thread trash in elastic configurations with dynamically increasing and decreasing concurrent consumers.

Enum values:

  • ThreadPool

  • SimpleAsync

DefaultTaskExecutorType

eagerLoadingOfProperties (consumer (advanced))

Whether the consumer reads the body and the properties of a JMS message as soon as it receives it, instead of when the route uses them. This is generally less efficient, but catches problems of the JMS provider with the message early. See also eagerPoisonBody.

false

boolean

eagerPoisonBody (consumer (advanced))

The text that replaces the message body when eagerLoadingOfProperties is enabled and the body or the properties of the JMS message cannot be read (a poison message), so the message can be processed; the cause is stored as the exception of the exchange, which is not redelivered. It can be a simple language expression. Set it to false to turn this off.

Poison JMS message payload: ${exception.message}

String

exposeListenerSession (consumer (advanced))

Whether the listener container exposes the JMS session of the consumer to the Spring JmsTemplate calls on the same thread, so a producer in the route that uses the same connection factory reuses that session (and its local transaction). Disable it to use a new session of the same connection instead, which some JMS providers need. A session of a transaction manager is always exposed.

true

boolean

replyToConsumerType (consumer (advanced))

The consumer type of the reply consumer (when doing request/reply), which can be one of: Simple, Default, or Custom. The consumer type determines which Spring JMS listener to use. Default will use org.springframework.jms.listener.DefaultMessageListenerContainer, Simple will use org.springframework.jms.listener.SimpleMessageListenerContainer. When Custom is specified, the MessageListenerContainerFactory defined by the messageListenerContainerFactory option will determine what org.springframework.jms.listener.AbstractMessageListenerContainer to use.

Enum values:

  • Simple

  • Default

  • Custom

Default

ConsumerType

replyToSameDestinationAllowed (consumer (advanced))

Whether the consumer may send a reply to the destination it consumes from. Disabled by default, to prevent an endless loop of consuming and sending back the same message to itself.

false

boolean

taskExecutor (consumer (advanced))

A custom Spring TaskExecutor that the listener container of the consumer (and of the reply consumer of request/reply) runs its consumers with. When not set, see defaultTaskExecutorType.

TaskExecutor

deliveryDelay (producer)

The delivery delay in milliseconds of the messages sent: the JMS broker delivers a message no earlier than this delay after it was sent. The default -1 sets none. Requires a JMS 2.0 message broker.

-1

long

deliveryMode (producer)

The JMS delivery mode of the messages sent: 1 (NON_PERSISTENT) or 2 (PERSISTENT), as defined by jakarta.jms.DeliveryMode. Takes precedence over deliveryPersistent. Setting it enables explicitQosEnabled, unless that is configured.

Enum values:

  • 1

  • 2

Integer

deliveryPersistent (producer)

Whether the messages are sent with persistent delivery (PERSISTENT) or not (NON_PERSISTENT). Not used when deliveryMode is set. Setting it enables explicitQosEnabled, unless that is configured.

true

boolean

explicitQosEnabled (producer)

Whether the producer sends the messages with the deliveryMode (or deliveryPersistent), priority and timeToLive options of the endpoint (the explicitQosEnabled of Spring’s JmsTemplate); otherwise the defaults of the JMS provider apply. It is enabled automatically when one of these options is set, unless explicitQosEnabled is configured, and always for the requests of request/reply over JMS. In contrast, preserveMessageQos takes the values from the message headers. Also keeps the JMSReplyTo of a message sent as InOnly.

false

Boolean

formatDateHeadersToIso8601 (producer)

Whether the java.util.Date headers are sent as JMS string properties in the ISO 8601 format (in UTC), instead of the format of Date.toString().

false

boolean

lazyStartProducer (producer)

Whether the producer should be started lazy (on the first message). By starting lazy you can use this to allow CamelContext and routes to startup in situations where a producer may otherwise fail during starting and cause the route to fail being started. By deferring this startup to be lazy then the startup failure can be handled during routing messages via Camel’s routing error handlers. Beware that when the first message is processed then creating and starting the producer may take a little time and prolong the total processing time of the processing.

false

boolean

preserveMessageQos (producer)

Whether the producer sends each message with the QoS values of the message instead of those of the endpoint: the JMSPriority, JMSDeliveryMode and JMSExpiration headers, of which you can set all or only some. JMSExpiration is the time in milliseconds at which the message expires, which is turned into the time to live. Without a JMSExpiration header the timeToLive of the endpoint (or the requestTimeout of request/reply) is used. Without a JMSDeliveryMode or JMSPriority header the values of the JMS message are used: PERSISTENT and the default priority of the JMS provider, or those of a received JMS message that is sent on. Also keeps the JMSReplyTo of a message sent as InOnly. In contrast, explicitQosEnabled uses the options of the endpoint.

false

boolean

priority (producer)

The JMS priority of the messages sent, from 0 (lowest) to 9 (highest). Setting it enables explicitQosEnabled, unless that is configured.

Enum values:

  • 0

  • 1

  • 2

  • 3

  • 4

  • 5

  • 6

  • 7

  • 8

  • 9

4

int

replyToConcurrentConsumers (producer)

The number of concurrent consumers of the reply consumer of request/reply over JMS: the minimum number with the DefaultMessageListenerContainer, which scales up to replyToMaxConcurrentConsumers.

1

int

replyToMaxConcurrentConsumers (producer)

The maximum number of concurrent consumers of the reply consumer of request/reply over JMS: the DefaultMessageListenerContainer scales between replyToConcurrentConsumers and this number. Not used with replyToConsumerType Simple.

int

replyToOnTimeoutMaxConcurrentConsumers (producer)

The maximum number of threads of the thread pool that continues routing the exchanges whose reply of request/reply over JMS did not arrive within requestTimeout. Must be at least 1.

1

int

replyToOverride (producer)

The destination to set as JMSReplyTo of the messages sent, instead of the reply queue (replyTo, or the temporary queue) that the producer receives the replies from. Useful when a remote system receives the message, and the reply reaches the reply queue of the producer in another way.

String

replyToType (producer)

The kind of reply queue of request/reply over JMS: Temporary (a temporary queue of the producer, the default without replyTo, and not allowed with replyTo), Shared (the replyTo queue, which others may use as well, so the reply consumer selects its replies with a JMS message selector; the default with replyTo, and slower than the others) or Exclusive (the replyTo queue, which only this producer uses, so no selector is needed). See the documentation about the implications in a clustered environment.

Enum values:

  • Temporary

  • Shared

  • Exclusive

ReplyToType

requestTimeout (producer)

The time in milliseconds that the producer waits for the reply with request/reply over JMS (InOut). The CamelJmsRequestTimeout header overrides it for a message. Also used as the time to live of the request, unless timeToLive is set or disableTimeToLive is enabled. See also requestTimeoutCheckerInterval.

20000

long

timeToLive (producer)

The time to live in milliseconds of the messages sent, after which the JMS broker discards them. The default -1 sets none, so the messages do not expire, except the requests of request/reply over JMS, which use requestTimeout instead (see disableTimeToLive). Setting it enables explicitQosEnabled, unless that is configured.

-1

long

allowAdditionalHeaders (producer (advanced))

This option is used to allow additional headers which may have values that are invalid according to JMS specification. For example, some message systems, such as WMQ, do this with header names using prefix JMS_IBM_MQMD_ containing values with byte array or other invalid types. You can specify multiple header names separated by comma, and use * as suffix for wildcard matching.

String

allowNullBody (producer (advanced))

Whether to allow sending messages with no body. If this option is false and the message body is null, then an JMSException is thrown.

true

boolean

alwaysCopyMessage (producer (advanced))

Whether the producer always creates a new JMS message from the Camel message, instead of sending a received JMS message as it is (when the route did not change it). Camel enables it when replyToDestinationSelectorName is set.

false

boolean

correlationProperty (producer (advanced))

The name of the JMS property that request/reply over JMS (InOut) correlates the request and the reply with, instead of JMSCorrelationID. The producer generates its value, unless the message has a header with that name, and the reply must carry it. JMSCorrelationID is then not used, nor set by Camel.

String

disableTimeToLive (producer (advanced))

Whether to send the messages without a time to live, so they do not expire, also when timeToLive is set. By default request/reply over JMS sends the request with requestTimeout as time to live, which requires the clocks of the sending and the receiving systems to be in sync; enable this option to avoid that.

false

boolean

forceSendOriginalMessage (producer (advanced))

When using mapJmsMessage=false 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 true to force Camel to send the original JMS message that was received.

false

boolean

includeSentJMSMessageID (producer (advanced))

Whether the producer sets the JMSMessageID header to the JMSMessageID that the JMS provider assigned to the message sent. Only for messages sent as InOnly (fire and forget).

false

boolean

replyCorrelationProperty (producer (advanced))

The name of the JMS property of the reply that holds the correlation id, for a Shared reply queue without replyToDestinationSelectorName: the JMS message selector of the reply consumer then matches this property instead of JMSCorrelationID. In contrast, correlationProperty names the property of the request, and does not change the selector.

String

replyToCacheLevelName (producer (advanced))

The cache level of the DefaultMessageListenerContainer of the reply consumer of request/reply over JMS. By default Camel uses CACHE_CONSUMER for a temporary or Exclusive reply queue, and for a Shared reply queue with replyToDestinationSelectorName, and CACHE_SESSION for a Shared reply queue without it (whose message selector changes with the requests). Some JMS brokers, such as IBM WebSphere, may require CACHE_NONE, which is not allowed with temporary reply queues.

Enum values:

  • CACHE_AUTO

  • CACHE_CONNECTION

  • CACHE_CONSUMER

  • CACHE_NONE

  • CACHE_SESSION

String

replyToDestinationSelectorName (producer (advanced))

The name of a JMS property that the producer sets on each request to a value unique to the producer, and that its reply consumer selects the replies on (a fixed JMS message selector), so the producer receives only its own replies from a Shared reply queue. The reply must carry the property with the same value. Enables alwaysCopyMessage.

String

streamMessageTypeEnabled (producer (advanced))

Sets whether StreamMessage type is enabled or not. Message payloads of streaming kind such as files, InputStream, etc will either by sent as BytesMessage or StreamMessage. This option controls which kind will be used. By default BytesMessage is used which enforces the entire message payload to be read into memory. By enabling this option the message payload is read into memory in chunks and each chunk is then written to the StreamMessage until no more data.

false

boolean

allowAutoWiredConnectionFactory (advanced)

Whether to auto-discover ConnectionFactory from the registry, if no connection factory has been configured. If only one instance of ConnectionFactory is found then it will be used. This is enabled by default.

true

boolean

allowAutoWiredDestinationResolver (advanced)

Whether to auto-discover a DestinationResolver (and a TemporaryQueueResolver) from the registry, if none has been configured. If only one instance is found then it will be used. This is enabled by default.

true

boolean

allowSerializedHeaders (advanced)

Whether transferExchange also sends the headers (and exchange properties and variables) whose values are other serializable objects; otherwise only the values of the types String, Number, Character, Boolean and Date are sent, and the others are left out and logged at WARN level. Applies only when transferExchange is enabled.

false

boolean

artemisStreamingEnabled (advanced)

Whether to use the large message streaming of Apache ActiveMQ Artemis: the producer streams the body into a BytesMessage (instead of a StreamMessage) with the JMS_AMQ_InputStream property, and the consumer streams a large BytesMessage into a stream cache with the JMS_AMQ_SaveStream property, instead of reading the whole body into memory. Only enable it with Apache ActiveMQ Artemis.

false

boolean

asyncStartListener (advanced)

Whether to startup the JmsConsumer message listener asynchronously, when starting a route. For example if a JmsConsumer cannot get a connection to a remote JMS broker, then it may block while retrying and/or fail-over. This will cause Camel to block while starting routes. By setting this option to true, you will let routes startup, while the JmsConsumer connects to the JMS broker using a dedicated thread in asynchronous mode. If this option is used, then beware that if the connection could not be established, then an exception is logged at WARN level, and the consumer will not be able to receive messages; You can then restart the route to retry.

false

boolean

asyncStopListener (advanced)

Whether to stop the JmsConsumer message listener asynchronously, when stopping a route.

false

boolean

autowiredEnabled (advanced)

Whether autowiring is enabled. This is used for automatic autowiring options (the option must be marked as autowired) by looking up in the registry to find if there is a single instance of matching type, which then gets configured on the component. This can be used for automatic configuring JDBC data sources, JMS connection factories, AWS Clients, etc.

true

boolean

browseLimit (advanced)

The maximum number of messages that browsing the queue of the endpoint (with a JMS QueueBrowser) reads into memory and returns. Use 0 for unlimited.

100

int

configuration (advanced)

To use a shared JMS configuration.

JmsConfiguration

destinationResolver (advanced)

A pluggable org.springframework.jms.support.destination.DestinationResolver that allows you to use your own resolver (for example, to lookup the real destination in a JNDI registry).

DestinationResolver

errorHandler (advanced)

A Spring org.springframework.util.ErrorHandler that the listener container invokes for the uncaught exceptions thrown while processing a message, such as a failed exchange that the route did not handle. When not set, Camel logs these exceptions at the level of errorHandlerLoggingLevel, with a stack trace unless errorHandlerLogStackTrace is disabled.

ErrorHandler

exceptionListener (advanced)

A jakarta.jms.ExceptionListener that the listener container of the consumer (and of the reply consumer of request/reply) notifies of the JMSExceptions it gets, such as when it cannot connect to the JMS broker.

ExceptionListener

idleConsumerLimit (advanced)

The maximum number of consumers of the DefaultMessageListenerContainer that may be idle at any time: a new consumer is only scheduled when fewer consumers are idle. Raising it scales up faster. Also used by the reply consumer of request/reply.

1

int

idleReceivesPerTaskLimit (advanced)

The number of consecutive receives without a message after which a consumer task of the DefaultMessageListenerContainer is marked idle and released. Each receive waits up to receiveTimeout. Also used by the reply consumer of request/reply. Unlike maxMessagesPerTask, which releases a task after a number of receives whether they got a message or not, this option releases the task only once there are no more messages. idleTaskExecutionLimit then decides after how many idle executions the consumer is shut down. On its own it applies only to the surplus consumers above concurrentConsumers. For example, with receiveTimeout 1000 and idleReceivesPerTaskLimit 60, a task is released after 60 seconds without messages. When not set, Spring JMS uses 10 for the surplus consumers, unless the task executor prefers short-lived tasks.

int

idleTaskExecutionLimit (advanced)

The number of consecutive executions without a message after which a consumer task of the DefaultMessageListenerContainer shuts down when the container scales dynamically (see maxConcurrentConsumers); the concurrentConsumers consumers are kept. Also used by the reply consumer of request/reply. Raise it if the consumers scale up and down too often.

1

int

includeAllJMSXProperties (advanced)

Whether the JMSX headers defined by the JMS specification that the JMS provider sets (JMSXUserID, JMSXAppID, JMSXDeliveryCount, JMSXProducerTXID, JMSXConsumerTXID, JMSXRcvTimestamp and JMSXState) are also sent as JMS properties when sending a message; by default they are left out. Not used with a custom headerFilterStrategy.

false

boolean

includeCorrelationIDAsBytes (advanced)

Whether a received JMS message gets the JMSCorrelationIDAsBytes header, holding its JMSCorrelationID as a byte array.

true

boolean

jmsKeyFormatStrategy (advanced)

The strategy that encodes the names of the Camel headers into valid JMS property names when sending, and decodes them back when receiving: default replaces a dot with DOT and a hyphen with HYPHEN, and passthrough keeps the names as they are (for JMS brokers that accept such names). You can also refer to your own implementation of org.apache.camel.component.jms.JmsKeyFormatStrategy with the # notation.

Enum values:

  • default

  • passthrough

JmsKeyFormatStrategy

mapJmsMessage (advanced)

Whether the body of a received JMS message is mapped to a Java type: a TextMessage to String, a BytesMessage to byte[], a MapMessage to Map, a StreamMessage to InputStream and an ObjectMessage to its object (see objectMessageEnabled). When disabled, the body is the jakarta.jms.Message itself. Not used when messageConverter is set.

true

boolean

maxMessagesPerTask (advanced)

The maximum number of receive attempts (including those that time out without a message, see receiveTimeout) that a consumer task of the DefaultMessageListenerContainer makes before it is released and scheduled again; also used by the reply consumer of request/reply. With a range of concurrent consumers (maxConcurrentConsumers higher than concurrentConsumers), a value such as 100 controls how fast the surplus consumers shrink when less work is required. The default -1 leaves it to Spring JMS: unlimited, or 10 when the task executor prefers short-lived tasks (such as with defaultTaskExecutorType ThreadPool).

-1

int

messageConverter (advanced)

A custom Spring org.springframework.jms.support.converter.MessageConverter that converts the message body to a jakarta.jms.Message when sending, and a received jakarta.jms.Message to the message body. It replaces the body mapping of Camel (mapJmsMessage and jmsMessageType); the headers are still mapped by Camel.

MessageConverter

messageCreatedStrategy (advanced)

A MessageCreatedStrategy that Camel invokes each time it creates a jakarta.jms.Message to send, so the message can be customized.

MessageCreatedStrategy

messageIdEnabled (advanced)

When sending, specifies whether message IDs should be added. This is just an hint to the JMS broker. If the JMS provider accepts this hint, these messages must have the message ID set to null; if the provider ignores the hint, the message ID must be set to its normal unique value.

true

boolean

messageListenerContainerFactory (advanced)

The MessageListenerContainerFactory that creates the org.springframework.jms.listener.AbstractMessageListenerContainer of the consumer (and of the reply consumer when replyToConsumerType is Custom). Setting it sets consumerType to Custom.

MessageListenerContainerFactory

messageTimestampEnabled (advanced)

Specifies whether timestamps should be enabled by default on sending messages. This is just an hint to the JMS broker. If the JMS provider accepts this hint, these messages must have the timestamp set to zero; if the provider ignores the hint the timestamp must be set to its normal value.

true

boolean

objectMessageEnabled (advanced)

Whether to enable sending and receiving JMS ObjectMessage. By default this is disabled because Java object serialization is a known source of security vulnerabilities. Enable this option only if you trust the source of the messages and need to send or receive Java serialized objects via JMS. When disabled, Camel will refuse to create or read JMS ObjectMessage instances. Options that rely on ObjectMessage internally (such as transferExchange and transferException) require this option to be enabled.

false

boolean

pubSubNoLocal (advanced)

Specifies whether to inhibit the delivery of messages published by its own connection.

false

boolean

queueBrowseStrategy (advanced)

To use a custom QueueBrowseStrategy when browsing queues.

QueueBrowseStrategy

receiveTimeout (advanced)

The time in milliseconds that a consumer of the DefaultMessageListenerContainer (also of the reply consumer of request/reply) waits for a message in each receive call. 0 waits without a timeout, which prevents the consumer from stopping cleanly. With a transaction manager it must be shorter than the transaction timeout. Not used by the SimpleMessageListenerContainer.

1000

long

recoveryInterval (advanced)

The interval in milliseconds between the attempts of the DefaultMessageListenerContainer of the consumer (and of the reply consumer of request/reply) to recover, such as to connect again after the connection to the JMS broker failed.

5000

long

requestTimeoutCheckerInterval (advanced)

Configures how often Camel should check for timed out Exchanges when doing request/reply over JMS. By default Camel checks once per second. But if you must react faster when a timeout occurs, then you can lower this interval, to check more frequently. The timeout is determined by the option requestTimeout.

1000

long

serviceLocationEnabled (advanced)

Whether to detect the network address location of the JMS broker on startup. This information is gathered via reflection on the ConnectionFactory, and is vendor specific. This option can be used to turn this off.

true

boolean

synchronous (advanced)

Whether to process strictly synchronously: the consumer processes each message in the thread that received it (also when asyncConsumer is enabled), and the producer blocks the calling thread until request/reply over JMS has received its reply.

false

boolean

temporaryQueueResolver (advanced)

A pluggable TemporaryQueueResolver that allows you to use your own resolver for creating temporary queues (some messaging systems has special requirements for creating temporary queues).

TemporaryQueueResolver

transferException (advanced)

Whether the consumer of request/reply (InOut) sends the exception of a failed exchange back as the reply, in a jakarta.jms.ObjectMessage, and the producer rethrows it; the exception may be wrapped, such as in org.apache.camel.RuntimeCamelException. This allows you to use Camel JMS as a bridge in your routing, for example with persistent queues for robust routing. Takes precedence over transferExchange. Must be enabled on both the producer and the consumer, requires objectMessageEnabled, and the exception must be serializable. Use it with caution: Java serialization couples the producers and the consumers to compatible classes.

false

boolean

transferExchange (advanced)

Whether to send the exchange instead of only the body and headers: the in and out body and headers, the exchange properties and variables, and the exception, as a Java serialized jakarta.jms.ObjectMessage. Values that are not serializable are left out and logged at WARN level. Must be enabled on both the producer and the consumer, and requires objectMessageEnabled. Use it with caution: Java serialization couples the producers and the consumers to compatible Camel versions.

false

boolean

useMessageIDAsCorrelationID (advanced)

Whether request/reply over JMS correlates the reply with the JMSMessageID of the request, instead of a JMSCorrelationID that the producer sets: the replier must set the JMSCorrelationID of the reply to the JMSMessageID of the request, which a consumer does when this option is enabled.

false

boolean

waitForProvisionCorrelationToBeUpdatedCounter (advanced)

The number of times to wait (each for waitForProvisionCorrelationToBeUpdatedThreadSleepingTime) for the provisional correlation id to be updated to the JMSMessageID of the request, when a reply arrives before that, with request/reply over JMS and useMessageIDAsCorrelationID enabled.

50

int

waitForProvisionCorrelationToBeUpdatedThreadSleepingTime (advanced)

The interval in milliseconds between the attempts of waitForProvisionCorrelationToBeUpdatedCounter.

100

long

waitForTemporaryReplyToToBeUpdatedCounter (advanced)

The number of times to wait (each for waitForTemporaryReplyToToBeUpdatedThreadSleepingTime) for the reply queue of request/reply over JMS (the temporary queue, or the replyTo queue) to be ready, before sending a request.

200

int

waitForTemporaryReplyToToBeUpdatedThreadSleepingTime (advanced)

The interval in milliseconds between the attempts of waitForTemporaryReplyToToBeUpdatedCounter.

100

long

headerFilterStrategy (filter)

To use a custom org.apache.camel.spi.HeaderFilterStrategy to filter header to and from Camel message.

HeaderFilterStrategy

errorHandlerLoggingLevel (logging)

The logging level at which the default errorHandler (used when no errorHandler is set) logs the uncaught exceptions thrown while processing a message.

Enum values:

  • TRACE

  • DEBUG

  • INFO

  • WARN

  • ERROR

  • OFF

WARN

LoggingLevel

errorHandlerLogStackTrace (logging)

Whether the default errorHandler (used when no errorHandler is set) logs the stack trace of the uncaught exceptions thrown while processing a message.

true

boolean

deserializationFilter (security)

Sets an ObjectInputFilter pattern (jdk.serialFilter syntax) applied as a defense-in-depth check on the class of the body returned by jakarta.jms.ObjectMessage.getObject(). The pattern is evaluated after the JMS provider has deserialized the payload, so this option alone does not prevent gadget-chain execution that happens inside the provider’s ObjectInputStream; to block such attacks, also configure the JMS provider’s own deserialization filter and/or the JVM-wide -Djdk.serialFilter. When this option is not set and no JVM-wide filter is configured, a conservative default filter denying java.net. and otherwise allowing java., javax. and org.apache.camel. is applied.

String

password (security)

Password to use with the ConnectionFactory. You can also configure username/password directly on the ConnectionFactory.

String

username (security)

Username to use with the ConnectionFactory. You can also configure username/password directly on the ConnectionFactory.

String

transacted (transaction)

Whether to use transacted JMS sessions: the consumer receives and processes each message in a transaction, which is rolled back when the processing fails, so that the JMS broker redelivers the message (see also transactionManager and lazyCreateTransactionManager), and the producer sends in a transacted session. The consumer then processes the messages synchronously. Not used by the producer of request/reply over JMS (see transactedInOut).

false

boolean

transactedInOut (transaction)

Whether the producer sends the requests of request/reply over JMS (InOut) in a transacted session (the sessionTransacted of Spring’s JmsTemplate): outside a transaction a short local JMS transaction, and within a Spring managed transaction (other than XA) a local JMS transaction that commits right after it. The reply consumer is never transacted.

false

boolean

lazyCreateTransactionManager (transaction (advanced))

Whether Camel creates a JmsTransactionManager for the consumer when transacted is enabled and no transactionManager is set. When disabled, the consumer uses locally transacted JMS sessions without a transaction manager.

true

boolean

transactionManager (transaction (advanced))

The Spring PlatformTransactionManager (such as a JmsTransactionManager or JtaTransactionManager) that the DefaultMessageListenerContainer of the consumer runs the receive and the processing of each message in. When not set and transacted is enabled, Camel creates a JmsTransactionManager (see lazyCreateTransactionManager).

PlatformTransactionManager

transactionName (transaction (advanced))

The name of the transactions of the consumer. Defaults to the name of the consumer thread, which includes the destination. Only used with a transaction manager and the DefaultMessageListenerContainer.

String

transactionTimeout (transaction (advanced))

The timeout in seconds of the transactions of the consumer. The default -1 uses the default timeout of the transaction manager. Only used with a transaction manager and the DefaultMessageListenerContainer.

-1

int

Endpoint Options

The JMS endpoint is configured using URI syntax:

jms:destinationType:destinationName

With the following path and query parameters:

Path Parameters

Name Description Default Type

destinationType (common)

The kind of destination: queue, topic, temp-queue (a temporary queue) or temp-topic (a temporary topic).

Enum values:

  • queue

  • topic

  • temp-queue

  • temp-topic

queue

String

destinationName (common)

Required Name of the queue or topic to use as destination.

String

Query Parameters

Name Description Default Type

clientId (common)

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 with JMS 1.1.

String

connectionFactory (common)

The jakarta.jms.ConnectionFactory that the consumers and producers create their JMS connections with. When none is configured, the component uses the single ConnectionFactory found in the registry (see allowAutoWiredConnectionFactory).

ConnectionFactory

disableReplyTo (common)

Whether to disable request/reply. A consumer then ignores the JMSReplyTo of the received messages and sends no reply, for example when another part of the application sends the reply, or when Camel routes the messages from one message broker to another. A producer sends the messages as InOnly and without JMSReplyTo, also when the exchange is InOut.

false

boolean

durableSubscriptionName (common)

The name of a durable topic subscription. Setting it makes the subscription durable, as subscriptionDurable together with subscriptionName does (subscriptionName takes precedence for the name). A durable subscription that is not shared also requires the clientId option.

String

jmsMessageType (common)

The JMS message type (Bytes, Map, Object, Stream or Text) of the messages that the producer sends (also the requests of request/reply) and of the replies that the consumer sends, instead of the type that Camel chooses from the message body. The CamelJmsMessageType header overrides it. Not used when receiving, as a received message keeps the type that its sender chose. Object requires objectMessageEnabled.

Enum values:

  • Bytes

  • Map

  • Object

  • Stream

  • Text

JmsMessageType

replyTo (common)

The reply destination. A producer doing request/reply over JMS sets it as JMSReplyTo of the request and receives the replies from it (see replyToType); without it, a temporary queue is used. A consumer sends its replies to it, instead of to the JMSReplyTo of the received message.

String

testConnectionOnStartup (common)

Whether the consumers and producers create (and close) a JMS connection when they start, so that Camel fails to start, with an exception, when the JMS broker cannot be reached, instead of starting with failed connections.

false

boolean

acknowledgementModeName (consumer)

The JMS acknowledgement mode of the sessions of the consumer: AUTO_ACKNOWLEDGE, CLIENT_ACKNOWLEDGE, DUPS_OK_ACKNOWLEDGE or SESSION_TRANSACTED. Not used when transacted is enabled, as the sessions are then transacted. With the DefaultMessageListenerContainer, AUTO_ACKNOWLEDGE acknowledges a message when it is received, before the route processes it, so a failed message is not redelivered. CLIENT_ACKNOWLEDGE acknowledges it after it has been processed successfully, and transacted also redelivers it when the processing fails.

Enum values:

  • SESSION_TRANSACTED

  • CLIENT_ACKNOWLEDGE

  • AUTO_ACKNOWLEDGE

  • DUPS_OK_ACKNOWLEDGE

AUTO_ACKNOWLEDGE

String

artemisConsumerPriority (consumer)

The consumer priority of the consumer on an Apache ActiveMQ Artemis broker, which Camel adds to the destination name as the consumer-priority parameter (0, the default, adds none). The broker delivers the messages to the consumers of the highest priority (round-robin between those of the same priority), and to consumers of a lower priority only when those have no credit or do not accept the message, for example because of their selector.

int

asyncConsumer (consumer)

Whether the JmsConsumer processes the Exchange asynchronously. If enabled then the JmsConsumer may pickup the next message from the JMS queue, while the previous message is being processed asynchronously (by the Asynchronous Routing Engine). This means that messages may be processed not 100% strictly in order. If disabled (as default) then the Exchange is fully processed before the JmsConsumer will pickup the next message from the JMS queue. Note if transacted has been enabled, then asyncConsumer=true does not run asynchronously, as transaction must be executed synchronously.

false

boolean

autoStartup (consumer)

Whether the consumer starts its listener container, and so receives messages, when the consumer starts. When disabled, the listener container is started when the consumer is resumed.

true

boolean

cacheLevel (consumer)

The cache level of the JMS resources of the DefaultMessageListenerContainer of the consumer, by number: 0 (CACHE_NONE), 1 (CACHE_CONNECTION), 2 (CACHE_SESSION), 3 (CACHE_CONSUMER) or 4 (CACHE_AUTO). Takes precedence over cacheLevelName, which describes the levels.

int

cacheLevelName (consumer)

The cache level of the JMS resources (connection, session and consumer) that the DefaultMessageListenerContainer of the consumer keeps between receives: CACHE_NONE, CACHE_CONNECTION, CACHE_SESSION, CACHE_CONSUMER or CACHE_AUTO. CACHE_AUTO uses CACHE_NONE when there is a transaction manager (including the JmsTransactionManager that Camel creates when transacted is enabled), and CACHE_CONSUMER otherwise. Not used by the SimpleMessageListenerContainer. See also cacheLevel.

Enum values:

  • CACHE_AUTO

  • CACHE_CONNECTION

  • CACHE_CONSUMER

  • CACHE_NONE

  • CACHE_SESSION

CACHE_AUTO

String

concurrentConsumers (consumer)

The number of concurrent consumers that consume from the destination: the minimum number with the DefaultMessageListenerContainer, which scales up to maxConcurrentConsumers. The SimpleMessageListenerContainer uses a fixed number, which is maxConcurrentConsumers when that is set. Not used by the reply consumer of request/reply over JMS (see replyToConcurrentConsumers). On a topic, each consumer has its own subscription and receives every message, unless subscriptionShared is enabled.

1

int

maxConcurrentConsumers (consumer)

The maximum number of concurrent consumers that consume from the destination: the DefaultMessageListenerContainer scales between concurrentConsumers and this number (see also maxMessagesPerTask, idleTaskExecutionLimit and idleConsumerLimit), and the SimpleMessageListenerContainer uses this fixed number of consumers. Must not be lower than concurrentConsumers. Not used by the reply consumer of request/reply over JMS (see replyToMaxConcurrentConsumers). On a topic, each consumer has its own subscription and receives every message, unless subscriptionShared is enabled.

int

replyToDeliveryPersistent (consumer)

Whether the consumer sends its replies of request/reply with persistent delivery (PERSISTENT) or not (NON_PERSISTENT). Takes effect only when the QoS options of the endpoint of the consumer are used (see explicitQosEnabled), not with preserveMessageQos.

true

boolean

selector (consumer)

The JMS message selector (an SQL-92 conditional expression on the JMS headers and properties of the messages, such as color = 'red') that the consumer uses to receive only the matching messages.

String

subscriptionDurable (consumer)

Whether the topic subscription is durable, so the JMS broker keeps its messages while the consumer is not connected. Its name is set with subscriptionName. Only for topics: Spring JMS switches the listener container to the publish-subscribe domain when it is enabled. A durable subscription that is not shared also requires the clientId option.

false

boolean

subscriptionName (consumer)

The name of the shared or durable topic subscription to create. It must be unique within the JMS client id of the connection. Defaults to the class name of the message listener (org.apache.camel.component.jms.EndpointMessageListener). A subscription that is not shared allows only one concurrent consumer.

String

subscriptionShared (consumer)

Whether the topic subscription is shared (JMS 2.0), so its consumers (the concurrent consumers, and those of other connections that use the same subscriptionName) share its messages, instead of each receiving every message. Can be combined with subscriptionDurable. Only for topics: Spring JMS switches the listener container to the publish-subscribe domain when it is enabled. Requires a JMS 2.0 message broker.

false

boolean

acceptMessagesWhileStopping (consumer (advanced))

Specifies whether the consumer accept messages while it is stopping. You may consider enabling this option, if you start and stop JMS routes at runtime, while there are still messages enqueued on the queue. If this option is false, and you stop the JMS route, then messages may be rejected, and the JMS broker would have to attempt redeliveries, which yet again may be rejected, and eventually the message may be moved at a dead letter queue on the JMS broker. To avoid this its recommended to enable this option.

false

boolean

allowReplyManagerQuickStop (consumer (advanced))

Whether the DefaultMessageListenerContainer of the reply consumer of request/reply over JMS stops receiving right away when the CamelContext is stopping and acceptMessagesWhileStopping is disabled, as the regular JMS consumers do. Disabled by default, so the reply consumer keeps receiving replies while the CamelContext is stopping.

false

boolean

consumerType (consumer (advanced))

The consumer type to use, which can be one of: Simple, Default, or Custom. The consumer type determines which Spring JMS listener to use. Default will use org.springframework.jms.listener.DefaultMessageListenerContainer, Simple will use org.springframework.jms.listener.SimpleMessageListenerContainer. When Custom is specified, the MessageListenerContainerFactory defined by the messageListenerContainerFactory option will determine what org.springframework.jms.listener.AbstractMessageListenerContainer to use.

Enum values:

  • Simple

  • Default

  • Custom

Default

ConsumerType

defaultTaskExecutorType (consumer (advanced))

Specifies what default TaskExecutor type to use in the DefaultMessageListenerContainer, for both consumer endpoints and the ReplyTo consumer of producer endpoints. Possible values: SimpleAsync (uses Spring’s SimpleAsyncTaskExecutor) or ThreadPool (uses Spring’s ThreadPoolTaskExecutor with optimal values - cached thread-pool-like). If not set, it defaults to the previous behaviour, which uses a cached thread pool for consumer endpoints and SimpleAsync for reply consumers. The use of ThreadPool is recommended to reduce thread trash in elastic configurations with dynamically increasing and decreasing concurrent consumers.

Enum values:

  • ThreadPool

  • SimpleAsync

DefaultTaskExecutorType

eagerLoadingOfProperties (consumer (advanced))

Whether the consumer reads the body and the properties of a JMS message as soon as it receives it, instead of when the route uses them. This is generally less efficient, but catches problems of the JMS provider with the message early. See also eagerPoisonBody.

false

boolean

eagerPoisonBody (consumer (advanced))

The text that replaces the message body when eagerLoadingOfProperties is enabled and the body or the properties of the JMS message cannot be read (a poison message), so the message can be processed; the cause is stored as the exception of the exchange, which is not redelivered. It can be a simple language expression. Set it to false to turn this off.

Poison JMS message payload: ${exception.message}

String

exceptionHandler (consumer (advanced))

To let the consumer use a custom ExceptionHandler. Notice if the option bridgeErrorHandler is enabled then this option is not in use. By default the consumer will deal with exceptions, that will be logged at WARN or ERROR level and ignored.

ExceptionHandler

exchangePattern (consumer (advanced))

Sets the exchange pattern when the consumer creates an exchange.

Enum values:

  • InOnly

  • InOut

ExchangePattern

exposeListenerSession (consumer (advanced))

Whether the listener container exposes the JMS session of the consumer to the Spring JmsTemplate calls on the same thread, so a producer in the route that uses the same connection factory reuses that session (and its local transaction). Disable it to use a new session of the same connection instead, which some JMS providers need. A session of a transaction manager is always exposed.

true

boolean

replyToConsumerType (consumer (advanced))

The consumer type of the reply consumer (when doing request/reply), which can be one of: Simple, Default, or Custom. The consumer type determines which Spring JMS listener to use. Default will use org.springframework.jms.listener.DefaultMessageListenerContainer, Simple will use org.springframework.jms.listener.SimpleMessageListenerContainer. When Custom is specified, the MessageListenerContainerFactory defined by the messageListenerContainerFactory option will determine what org.springframework.jms.listener.AbstractMessageListenerContainer to use.

Enum values:

  • Simple

  • Default

  • Custom

Default

ConsumerType

replyToSameDestinationAllowed (consumer (advanced))

Whether the consumer may send a reply to the destination it consumes from. Disabled by default, to prevent an endless loop of consuming and sending back the same message to itself.

false

boolean

taskExecutor (consumer (advanced))

A custom Spring TaskExecutor that the listener container of the consumer (and of the reply consumer of request/reply) runs its consumers with. When not set, see defaultTaskExecutorType.

TaskExecutor

deliveryDelay (producer)

The delivery delay in milliseconds of the messages sent: the JMS broker delivers a message no earlier than this delay after it was sent. The default -1 sets none. Requires a JMS 2.0 message broker.

-1

long

deliveryMode (producer)

The JMS delivery mode of the messages sent: 1 (NON_PERSISTENT) or 2 (PERSISTENT), as defined by jakarta.jms.DeliveryMode. Takes precedence over deliveryPersistent. Setting it enables explicitQosEnabled, unless that is configured.

Enum values:

  • 1

  • 2

Integer

deliveryPersistent (producer)

Whether the messages are sent with persistent delivery (PERSISTENT) or not (NON_PERSISTENT). Not used when deliveryMode is set. Setting it enables explicitQosEnabled, unless that is configured.

true

boolean

explicitQosEnabled (producer)

Whether the producer sends the messages with the deliveryMode (or deliveryPersistent), priority and timeToLive options of the endpoint (the explicitQosEnabled of Spring’s JmsTemplate); otherwise the defaults of the JMS provider apply. It is enabled automatically when one of these options is set, unless explicitQosEnabled is configured, and always for the requests of request/reply over JMS. In contrast, preserveMessageQos takes the values from the message headers. Also keeps the JMSReplyTo of a message sent as InOnly.

false

Boolean

formatDateHeadersToIso8601 (producer)

Whether the java.util.Date headers are sent as JMS string properties in the ISO 8601 format (in UTC), instead of the format of Date.toString().

false

boolean

preserveMessageQos (producer)

Whether the producer sends each message with the QoS values of the message instead of those of the endpoint: the JMSPriority, JMSDeliveryMode and JMSExpiration headers, of which you can set all or only some. JMSExpiration is the time in milliseconds at which the message expires, which is turned into the time to live. Without a JMSExpiration header the timeToLive of the endpoint (or the requestTimeout of request/reply) is used. Without a JMSDeliveryMode or JMSPriority header the values of the JMS message are used: PERSISTENT and the default priority of the JMS provider, or those of a received JMS message that is sent on. Also keeps the JMSReplyTo of a message sent as InOnly. In contrast, explicitQosEnabled uses the options of the endpoint.

false

boolean

priority (producer)

The JMS priority of the messages sent, from 0 (lowest) to 9 (highest). Setting it enables explicitQosEnabled, unless that is configured.

Enum values:

  • 0

  • 1

  • 2

  • 3

  • 4

  • 5

  • 6

  • 7

  • 8

  • 9

4

int

replyToConcurrentConsumers (producer)

The number of concurrent consumers of the reply consumer of request/reply over JMS: the minimum number with the DefaultMessageListenerContainer, which scales up to replyToMaxConcurrentConsumers.

1

int

replyToMaxConcurrentConsumers (producer)

The maximum number of concurrent consumers of the reply consumer of request/reply over JMS: the DefaultMessageListenerContainer scales between replyToConcurrentConsumers and this number. Not used with replyToConsumerType Simple.

int

replyToOnTimeoutMaxConcurrentConsumers (producer)

The maximum number of threads of the thread pool that continues routing the exchanges whose reply of request/reply over JMS did not arrive within requestTimeout. Must be at least 1.

1

int

replyToOverride (producer)

The destination to set as JMSReplyTo of the messages sent, instead of the reply queue (replyTo, or the temporary queue) that the producer receives the replies from. Useful when a remote system receives the message, and the reply reaches the reply queue of the producer in another way.

String

replyToType (producer)

The kind of reply queue of request/reply over JMS: Temporary (a temporary queue of the producer, the default without replyTo, and not allowed with replyTo), Shared (the replyTo queue, which others may use as well, so the reply consumer selects its replies with a JMS message selector; the default with replyTo, and slower than the others) or Exclusive (the replyTo queue, which only this producer uses, so no selector is needed). See the documentation about the implications in a clustered environment.

Enum values:

  • Temporary

  • Shared

  • Exclusive

ReplyToType

requestTimeout (producer)

The time in milliseconds that the producer waits for the reply with request/reply over JMS (InOut). The CamelJmsRequestTimeout header overrides it for a message. Also used as the time to live of the request, unless timeToLive is set or disableTimeToLive is enabled. See also requestTimeoutCheckerInterval.

20000

long

timeToLive (producer)

The time to live in milliseconds of the messages sent, after which the JMS broker discards them. The default -1 sets none, so the messages do not expire, except the requests of request/reply over JMS, which use requestTimeout instead (see disableTimeToLive). Setting it enables explicitQosEnabled, unless that is configured.

-1

long

allowAdditionalHeaders (producer (advanced))

This option is used to allow additional headers which may have values that are invalid according to JMS specification. For example, some message systems, such as WMQ, do this with header names using prefix JMS_IBM_MQMD_ containing values with byte array or other invalid types. You can specify multiple header names separated by comma, and use * as suffix for wildcard matching.

String

allowNullBody (producer (advanced))

Whether to allow sending messages with no body. If this option is false and the message body is null, then an JMSException is thrown.

true

boolean

alwaysCopyMessage (producer (advanced))

Whether the producer always creates a new JMS message from the Camel message, instead of sending a received JMS message as it is (when the route did not change it). Camel enables it when replyToDestinationSelectorName is set.

false

boolean

correlationProperty (producer (advanced))

The name of the JMS property that request/reply over JMS (InOut) correlates the request and the reply with, instead of JMSCorrelationID. The producer generates its value, unless the message has a header with that name, and the reply must carry it. JMSCorrelationID is then not used, nor set by Camel.

String

disableTimeToLive (producer (advanced))

Whether to send the messages without a time to live, so they do not expire, also when timeToLive is set. By default request/reply over JMS sends the request with requestTimeout as time to live, which requires the clocks of the sending and the receiving systems to be in sync; enable this option to avoid that.

false

boolean

forceSendOriginalMessage (producer (advanced))

When using mapJmsMessage=false 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 true to force Camel to send the original JMS message that was received.

false

boolean

includeSentJMSMessageID (producer (advanced))

Whether the producer sets the JMSMessageID header to the JMSMessageID that the JMS provider assigned to the message sent. Only for messages sent as InOnly (fire and forget).

false

boolean

lazyStartProducer (producer (advanced))

Whether the producer should be started lazy (on the first message). By starting lazy you can use this to allow CamelContext and routes to startup in situations where a producer may otherwise fail during starting and cause the route to fail being started. By deferring this startup to be lazy then the startup failure can be handled during routing messages via Camel’s routing error handlers. Beware that when the first message is processed then creating and starting the producer may take a little time and prolong the total processing time of the processing.

false

boolean

replyCorrelationProperty (producer (advanced))

The name of the JMS property of the reply that holds the correlation id, for a Shared reply queue without replyToDestinationSelectorName: the JMS message selector of the reply consumer then matches this property instead of JMSCorrelationID. In contrast, correlationProperty names the property of the request, and does not change the selector.

String

replyToCacheLevelName (producer (advanced))

The cache level of the DefaultMessageListenerContainer of the reply consumer of request/reply over JMS. By default Camel uses CACHE_CONSUMER for a temporary or Exclusive reply queue, and for a Shared reply queue with replyToDestinationSelectorName, and CACHE_SESSION for a Shared reply queue without it (whose message selector changes with the requests). Some JMS brokers, such as IBM WebSphere, may require CACHE_NONE, which is not allowed with temporary reply queues.

Enum values:

  • CACHE_AUTO

  • CACHE_CONNECTION

  • CACHE_CONSUMER

  • CACHE_NONE

  • CACHE_SESSION

String

replyToDestinationSelectorName (producer (advanced))

The name of a JMS property that the producer sets on each request to a value unique to the producer, and that its reply consumer selects the replies on (a fixed JMS message selector), so the producer receives only its own replies from a Shared reply queue. The reply must carry the property with the same value. Enables alwaysCopyMessage.

String

streamMessageTypeEnabled (producer (advanced))

Sets whether StreamMessage type is enabled or not. Message payloads of streaming kind such as files, InputStream, etc will either by sent as BytesMessage or StreamMessage. This option controls which kind will be used. By default BytesMessage is used which enforces the entire message payload to be read into memory. By enabling this option the message payload is read into memory in chunks and each chunk is then written to the StreamMessage until no more data.

false

boolean

allowSerializedHeaders (advanced)

Whether transferExchange also sends the headers (and exchange properties and variables) whose values are other serializable objects; otherwise only the values of the types String, Number, Character, Boolean and Date are sent, and the others are left out and logged at WARN level. Applies only when transferExchange is enabled.

false

boolean

artemisStreamingEnabled (advanced)

Whether to use the large message streaming of Apache ActiveMQ Artemis: the producer streams the body into a BytesMessage (instead of a StreamMessage) with the JMS_AMQ_InputStream property, and the consumer streams a large BytesMessage into a stream cache with the JMS_AMQ_SaveStream property, instead of reading the whole body into memory. Only enable it with Apache ActiveMQ Artemis.

false

boolean

asyncStartListener (advanced)

Whether to startup the JmsConsumer message listener asynchronously, when starting a route. For example if a JmsConsumer cannot get a connection to a remote JMS broker, then it may block while retrying and/or fail-over. This will cause Camel to block while starting routes. By setting this option to true, you will let routes startup, while the JmsConsumer connects to the JMS broker using a dedicated thread in asynchronous mode. If this option is used, then beware that if the connection could not be established, then an exception is logged at WARN level, and the consumer will not be able to receive messages; You can then restart the route to retry.

false

boolean

asyncStopListener (advanced)

Whether to stop the JmsConsumer message listener asynchronously, when stopping a route.

false

boolean

browseLimit (advanced)

The maximum number of messages that browsing the queue of the endpoint (with a JMS QueueBrowser) reads into memory and returns. Use 0 for unlimited.

100

int

destinationResolver (advanced)

A pluggable org.springframework.jms.support.destination.DestinationResolver that allows you to use your own resolver (for example, to lookup the real destination in a JNDI registry).

DestinationResolver

errorHandler (advanced)

A Spring org.springframework.util.ErrorHandler that the listener container invokes for the uncaught exceptions thrown while processing a message, such as a failed exchange that the route did not handle. When not set, Camel logs these exceptions at the level of errorHandlerLoggingLevel, with a stack trace unless errorHandlerLogStackTrace is disabled.

ErrorHandler

exceptionListener (advanced)

A jakarta.jms.ExceptionListener that the listener container of the consumer (and of the reply consumer of request/reply) notifies of the JMSExceptions it gets, such as when it cannot connect to the JMS broker.

ExceptionListener

headerFilterStrategy (advanced)

To use a custom HeaderFilterStrategy to filter header to and from Camel message.

HeaderFilterStrategy

idleConsumerLimit (advanced)

The maximum number of consumers of the DefaultMessageListenerContainer that may be idle at any time: a new consumer is only scheduled when fewer consumers are idle. Raising it scales up faster. Also used by the reply consumer of request/reply.

1

int

idleReceivesPerTaskLimit (advanced)

The number of consecutive receives without a message after which a consumer task of the DefaultMessageListenerContainer is marked idle and released. Each receive waits up to receiveTimeout. Also used by the reply consumer of request/reply. Unlike maxMessagesPerTask, which releases a task after a number of receives whether they got a message or not, this option releases the task only once there are no more messages. idleTaskExecutionLimit then decides after how many idle executions the consumer is shut down. On its own it applies only to the surplus consumers above concurrentConsumers. For example, with receiveTimeout 1000 and idleReceivesPerTaskLimit 60, a task is released after 60 seconds without messages. When not set, Spring JMS uses 10 for the surplus consumers, unless the task executor prefers short-lived tasks.

int

idleTaskExecutionLimit (advanced)

The number of consecutive executions without a message after which a consumer task of the DefaultMessageListenerContainer shuts down when the container scales dynamically (see maxConcurrentConsumers); the concurrentConsumers consumers are kept. Also used by the reply consumer of request/reply. Raise it if the consumers scale up and down too often.

1

int

includeAllJMSXProperties (advanced)

Whether the JMSX headers defined by the JMS specification that the JMS provider sets (JMSXUserID, JMSXAppID, JMSXDeliveryCount, JMSXProducerTXID, JMSXConsumerTXID, JMSXRcvTimestamp and JMSXState) are also sent as JMS properties when sending a message; by default they are left out. Not used with a custom headerFilterStrategy.

false

boolean

jmsKeyFormatStrategy (advanced)

The strategy that encodes the names of the Camel headers into valid JMS property names when sending, and decodes them back when receiving: default replaces a dot with DOT and a hyphen with HYPHEN, and passthrough keeps the names as they are (for JMS brokers that accept such names). You can also refer to your own implementation of org.apache.camel.component.jms.JmsKeyFormatStrategy with the # notation.

Enum values:

  • default

  • passthrough

JmsKeyFormatStrategy

mapJmsMessage (advanced)

Whether the body of a received JMS message is mapped to a Java type: a TextMessage to String, a BytesMessage to byte[], a MapMessage to Map, a StreamMessage to InputStream and an ObjectMessage to its object (see objectMessageEnabled). When disabled, the body is the jakarta.jms.Message itself. Not used when messageConverter is set.

true

boolean

maxMessagesPerTask (advanced)

The maximum number of receive attempts (including those that time out without a message, see receiveTimeout) that a consumer task of the DefaultMessageListenerContainer makes before it is released and scheduled again; also used by the reply consumer of request/reply. With a range of concurrent consumers (maxConcurrentConsumers higher than concurrentConsumers), a value such as 100 controls how fast the surplus consumers shrink when less work is required. The default -1 leaves it to Spring JMS: unlimited, or 10 when the task executor prefers short-lived tasks (such as with defaultTaskExecutorType ThreadPool).

-1

int

messageConverter (advanced)

A custom Spring org.springframework.jms.support.converter.MessageConverter that converts the message body to a jakarta.jms.Message when sending, and a received jakarta.jms.Message to the message body. It replaces the body mapping of Camel (mapJmsMessage and jmsMessageType); the headers are still mapped by Camel.

MessageConverter

messageCreatedStrategy (advanced)

A MessageCreatedStrategy that Camel invokes each time it creates a jakarta.jms.Message to send, so the message can be customized.

MessageCreatedStrategy

messageIdEnabled (advanced)

When sending, specifies whether message IDs should be added. This is just an hint to the JMS broker. If the JMS provider accepts this hint, these messages must have the message ID set to null; if the provider ignores the hint, the message ID must be set to its normal unique value.

true

boolean

messageListenerContainerFactory (advanced)

The MessageListenerContainerFactory that creates the org.springframework.jms.listener.AbstractMessageListenerContainer of the consumer (and of the reply consumer when replyToConsumerType is Custom). Setting it sets consumerType to Custom.

MessageListenerContainerFactory

messageTimestampEnabled (advanced)

Specifies whether timestamps should be enabled by default on sending messages. This is just an hint to the JMS broker. If the JMS provider accepts this hint, these messages must have the timestamp set to zero; if the provider ignores the hint the timestamp must be set to its normal value.

true

boolean

objectMessageEnabled (advanced)

Whether to enable sending and receiving JMS ObjectMessage. By default this is disabled because Java object serialization is a known source of security vulnerabilities. Enable this option only if you trust the source of the messages and need to send or receive Java serialized objects via JMS. When disabled, Camel will refuse to create or read JMS ObjectMessage instances. Options that rely on ObjectMessage internally (such as transferExchange and transferException) require this option to be enabled.

false

boolean

pubSubNoLocal (advanced)

Specifies whether to inhibit the delivery of messages published by its own connection.

false

boolean

receiveTimeout (advanced)

The time in milliseconds that a consumer of the DefaultMessageListenerContainer (also of the reply consumer of request/reply) waits for a message in each receive call. 0 waits without a timeout, which prevents the consumer from stopping cleanly. With a transaction manager it must be shorter than the transaction timeout. Not used by the SimpleMessageListenerContainer.

1000

long

recoveryInterval (advanced)

The interval in milliseconds between the attempts of the DefaultMessageListenerContainer of the consumer (and of the reply consumer of request/reply) to recover, such as to connect again after the connection to the JMS broker failed.

5000

long

requestTimeoutCheckerInterval (advanced)

Configures how often Camel should check for timed out Exchanges when doing request/reply over JMS. By default Camel checks once per second. But if you must react faster when a timeout occurs, then you can lower this interval, to check more frequently. The timeout is determined by the option requestTimeout.

1000

long

synchronous (advanced)

Whether to process strictly synchronously: the consumer processes each message in the thread that received it (also when asyncConsumer is enabled), and the producer blocks the calling thread until request/reply over JMS has received its reply.

false

boolean

temporaryQueueResolver (advanced)

A pluggable TemporaryQueueResolver that allows you to use your own resolver for creating temporary queues (some messaging systems has special requirements for creating temporary queues).

TemporaryQueueResolver

transferException (advanced)

Whether the consumer of request/reply (InOut) sends the exception of a failed exchange back as the reply, in a jakarta.jms.ObjectMessage, and the producer rethrows it; the exception may be wrapped, such as in org.apache.camel.RuntimeCamelException. This allows you to use Camel JMS as a bridge in your routing, for example with persistent queues for robust routing. Takes precedence over transferExchange. Must be enabled on both the producer and the consumer, requires objectMessageEnabled, and the exception must be serializable. Use it with caution: Java serialization couples the producers and the consumers to compatible classes.

false

boolean

transferExchange (advanced)

Whether to send the exchange instead of only the body and headers: the in and out body and headers, the exchange properties and variables, and the exception, as a Java serialized jakarta.jms.ObjectMessage. Values that are not serializable are left out and logged at WARN level. Must be enabled on both the producer and the consumer, and requires objectMessageEnabled. Use it with caution: Java serialization couples the producers and the consumers to compatible Camel versions.

false

boolean

useMessageIDAsCorrelationID (advanced)

Whether request/reply over JMS correlates the reply with the JMSMessageID of the request, instead of a JMSCorrelationID that the producer sets: the replier must set the JMSCorrelationID of the reply to the JMSMessageID of the request, which a consumer does when this option is enabled.

false

boolean

waitForProvisionCorrelationToBeUpdatedCounter (advanced)

The number of times to wait (each for waitForProvisionCorrelationToBeUpdatedThreadSleepingTime) for the provisional correlation id to be updated to the JMSMessageID of the request, when a reply arrives before that, with request/reply over JMS and useMessageIDAsCorrelationID enabled.

50

int

waitForProvisionCorrelationToBeUpdatedThreadSleepingTime (advanced)

The interval in milliseconds between the attempts of waitForProvisionCorrelationToBeUpdatedCounter.

100

long

waitForTemporaryReplyToToBeUpdatedCounter (advanced)

The number of times to wait (each for waitForTemporaryReplyToToBeUpdatedThreadSleepingTime) for the reply queue of request/reply over JMS (the temporary queue, or the replyTo queue) to be ready, before sending a request.

200

int

waitForTemporaryReplyToToBeUpdatedThreadSleepingTime (advanced)

The interval in milliseconds between the attempts of waitForTemporaryReplyToToBeUpdatedCounter.

100

long

errorHandlerLoggingLevel (logging)

The logging level at which the default errorHandler (used when no errorHandler is set) logs the uncaught exceptions thrown while processing a message.

Enum values:

  • TRACE

  • DEBUG

  • INFO

  • WARN

  • ERROR

  • OFF

WARN

LoggingLevel

errorHandlerLogStackTrace (logging)

Whether the default errorHandler (used when no errorHandler is set) logs the stack trace of the uncaught exceptions thrown while processing a message.

true

boolean

deserializationFilter (security)

Sets an ObjectInputFilter pattern (jdk.serialFilter syntax) applied as a defense-in-depth check on the class of the body returned by jakarta.jms.ObjectMessage.getObject(). The pattern is evaluated after the JMS provider has deserialized the payload, so this option alone does not prevent gadget-chain execution that happens inside the provider’s ObjectInputStream; to block such attacks, also configure the JMS provider’s own deserialization filter and/or the JVM-wide -Djdk.serialFilter. When this option is not set and no JVM-wide filter is configured, a conservative default filter denying java.net. and otherwise allowing java., javax. and org.apache.camel. is applied.

String

password (security)

Password to use with the ConnectionFactory. You can also configure username/password directly on the ConnectionFactory.

String

username (security)

Username to use with the ConnectionFactory. You can also configure username/password directly on the ConnectionFactory.

String

transacted (transaction)

Whether to use transacted JMS sessions: the consumer receives and processes each message in a transaction, which is rolled back when the processing fails, so that the JMS broker redelivers the message (see also transactionManager and lazyCreateTransactionManager), and the producer sends in a transacted session. The consumer then processes the messages synchronously. Not used by the producer of request/reply over JMS (see transactedInOut).

false

boolean

transactedInOut (transaction)

Whether the producer sends the requests of request/reply over JMS (InOut) in a transacted session (the sessionTransacted of Spring’s JmsTemplate): outside a transaction a short local JMS transaction, and within a Spring managed transaction (other than XA) a local JMS transaction that commits right after it. The reply consumer is never transacted.

false

boolean

lazyCreateTransactionManager (transaction (advanced))

Whether Camel creates a JmsTransactionManager for the consumer when transacted is enabled and no transactionManager is set. When disabled, the consumer uses locally transacted JMS sessions without a transaction manager.

true

boolean

transactionManager (transaction (advanced))

The Spring PlatformTransactionManager (such as a JmsTransactionManager or JtaTransactionManager) that the DefaultMessageListenerContainer of the consumer runs the receive and the processing of each message in. When not set and transacted is enabled, Camel creates a JmsTransactionManager (see lazyCreateTransactionManager).

PlatformTransactionManager

transactionName (transaction (advanced))

The name of the transactions of the consumer. Defaults to the name of the consumer thread, which includes the destination. Only used with a transaction manager and the DefaultMessageListenerContainer.

String

transactionTimeout (transaction (advanced))

The timeout in seconds of the transactions of the consumer. The default -1 uses the default timeout of the transaction manager. Only used with a transaction manager and the DefaultMessageListenerContainer.

-1

int

Message Headers

The JMS component supports the following message header(s), which is/are listed below:

Name Description Default Type

CamelJmsDestination (producer)

Constant: JMS_DESTINATION

The destination to send the message to, instead of the destination of the endpoint. Takes precedence over CamelJmsDestinationName. The producer removes the header.

Destination

CamelJmsDestinationName (producer)

Constant: JMS_DESTINATION_NAME

The name of the queue or topic to send the message to, instead of the destination of the endpoint. The producer removes the header.

String

CamelJMSDestinationProduced (common)

Constant: JMS_DESTINATION_NAME_PRODUCED

The name of the queue or topic the message was sent to.

String

JMSXGroupID (common)

Constant: JMS_X_GROUP_ID

The JMSXGroupID property of the message: the identity of the message group it is part of.

String

JMSMessageID (common)

Constant: JMS_HEADER_MESSAGE_ID

The JMSMessageID of the message: a unique id that the JMS provider assigns when the message is sent.

String

JMSCorrelationID (common)

Constant: JMS_HEADER_CORRELATION_ID

The JMSCorrelationID of the message, which links it with another message, such as a reply with its request.

String

JMSCorrelationIDAsBytes (common)

Constant: JMS_HEADER_CORRELATION_ID_AS_BYTES

The JMSCorrelationID of a received message as a byte array (see the includeCorrelationIDAsBytes option of the component).

byte[]

JMSDeliveryMode (common)

Constant: JMS_HEADER_DELIVERY_MODE

The JMSDeliveryMode of the message: 1 (NON_PERSISTENT) or 2 (PERSISTENT); when sending, also the names PERSISTENT and NON_PERSISTENT. When sending, it is only used with preserveMessageQos.

int

JMSDestination (common)

Constant: JMS_HEADER_DESTINATION

The JMSDestination of a received message: the queue or topic it was sent to. Not used when sending.

Destination

JMSExpiration (common)

Constant: JMS_HEADER_EXPIRATION

The JMSExpiration of the message: the time in milliseconds since the epoch at which it expires, or 0 if it does not expire. When sending, it is only used with preserveMessageQos.

long

JMSPriority (common)

Constant: JMS_HEADER_PRIORITY

The JMSPriority of the message, from 0 (lowest) to 9 (highest). When sending, it is only used with preserveMessageQos.

int

JMSRedelivered (common)

Constant: JMS_HEADER_REDELIVERED

Whether a received message is a redelivery of a message that was delivered before but not acknowledged (JMSRedelivered).

boolean

JMSTimestamp (common)

Constant: JMS_HEADER_TIMESTAMP

The JMSTimestamp of a received message: the time in milliseconds since the epoch at which it was handed to the JMS provider to be sent. Not used when sending.

long

JMSReplyTo (common)

Constant: JMS_HEADER_REPLY_TO

The JMS reply-to destination. On an incoming message this is the jakarta.jms.Destination of the JMS message. When set on an outgoing message it may also be a String holding the destination name, which is normalized and converted to a jakarta.jms.Destination.

Destination or String

JMSType (common)

Constant: JMS_HEADER_TYPE

The JMSType of the message: a message type identifier that the sending application sets.

String

JMSXUserID (common)

Constant: JMS_HEADER_XUSER_ID

The JMSXUserID property of a received message: the identity of the user that sent it, as set by the JMS provider. It is only sent as a JMS property when includeAllJMSXProperties is enabled.

String

CamelJmsMessageType (common)

Constant: JMS_MESSAGE_TYPE

The JMS message type (Bytes, Map, Object, Stream or Text) to send the message as, instead of the jmsMessageType option or the type that Camel chooses from the message body.

Enum values:

  • Bytes

  • Map

  • Object

  • Stream

  • Text

  • Blob

JmsMessageType

CamelJmsRequestTimeout (producer)

Constant: JMS_REQUEST_TIMEOUT

The time in milliseconds to wait for the reply of this message with request/reply over JMS (InOut), instead of the requestTimeout option.

20000

long

CamelMessageTimestamp (consumer)

Constant: MESSAGE_TIMESTAMP

The JMSTimestamp of a received message, as the timestamp of the Camel message: the time in milliseconds since the epoch at which it was handed to the JMS provider to be sent.

long

Message Body

The message body at each side of the JMS component: Consumer is the body of the messages the consumer creates, Consumer reply the bodies a consumer that answers its caller can reply with, Producer input the bodies the producer can send or write, and Producer output the body after the producer.

Side Body Description

Consumer

text, bytes, map, stream or null

By the JMS message received: a String for a TextMessage, a byte array for a BytesMessage, a Map for a MapMessage, a stream for a StreamMessage; an ObjectMessage only with objectMessageEnabled.

  • With mapJmsMessage=false: pojo (jakarta.jms.Message)

  • With objectMessageEnabled=true: text, bytes, map, stream, pojo or null

Not known when messageConverter or transferExchange is set.

Consumer reply

text, bytes, stream, file or map

The reply, sent as the producer sends a message.

  • With objectMessageEnabled=true: text, bytes, stream, file, map or pojo

Not known when jmsMessageType or messageConverter or transferExchange is set.

Producer input

text, bytes, stream, file or map

Text is sent as a TextMessage; bytes, a stream or a file as a BytesMessage; a Map as a MapMessage. Another Serializable object fails unless objectMessageEnabled.

  • With objectMessageEnabled=true: text, bytes, stream, file, map or pojo

Not known when jmsMessageType or messageConverter or transferExchange is set.

Producer output

unknown

Unchanged for a message that expects no reply (InOnly). A message that expects one (InOut) gets the body of the reply, as the consumer gives it.

  • With exchangePattern=InOnly: unchanged

  • With disableReplyTo=true: unchanged

The bodies are the ones with the default options. A side that is not listed is not known, and tooling does not guess it. The carriers, the sides and the tools that use them are described in Message Body Types.

Examples

JMS is used in many examples for other components as well. But we provide a few samples below to get started.

Receiving from JMS

In the following sample, we configure a route that receives JMS messages and routes the message to a POJO:

  • Java

  • XML

  • YAML

from("jms:queue:foo")
  .to("bean:myBusinessLogic");
<route>
  <from uri="jms:queue:foo"/>
  <to uri="bean:myBusinessLogic"/>
</route>
- route:
    from:
      uri: jms:queue:foo
      steps:
        - to:
            uri: bean:myBusinessLogic

Sending a request and waiting for the reply

To send a request and wait for its reply, the caller sends with the InOut exchange pattern, and the service is a route that consumes the queue: the body at the end of its route is the reply. You do not need to set replyTo or a JMSReplyTo header: Camel uses a temporary reply queue by default and sets JMSReplyTo itself. Set replyTo for a fixed (shared or exclusive) reply queue, see Request-reply over JMS. With variableReceive, the reply goes into a variable, and the body is kept:

  • Java

  • XML

  • YAML

from("timer:order?repeatCount=1")
  .setBody(constant("{\"orderId\": \"ORD-1001\", \"sku\": \"CAMEL-MUG\"}"))
  .setExchangePattern(ExchangePattern.InOut)
  .toV("jms:queue:stock", null, "stockReply")
  .log("Order ${body} got the reply ${variable.stockReply}");

from("jms:queue:stock")
  .log("Stock service got ${body}")
  .setBody(constant("{\"reserved\": true}"));
<route>
  <from uri="timer:order?repeatCount=1"/>
  <setBody>
    <constant>{"orderId": "ORD-1001", "sku": "CAMEL-MUG"}</constant>
  </setBody>
  <to uri="jms:queue:stock" pattern="InOut" variableReceive="stockReply"/>
  <log message="Order ${body} got the reply ${variable.stockReply}"/>
</route>
<route>
  <from uri="jms:queue:stock"/>
  <log message="Stock service got ${body}"/>
  <setBody>
    <constant>{"reserved": true}</constant>
  </setBody>
</route>
- route:
    from:
      uri: timer:order
      parameters:
        repeatCount: 1
      steps:
        - setBody:
            expression:
              constant:
                expression: '{"orderId": "ORD-1001", "sku": "CAMEL-MUG"}'
        - to:
            uri: jms:queue:stock
            pattern: InOut
            variableReceive: stockReply
        - log:
            message: "Order ${body} got the reply ${variable.stockReply}"
- route:
    from:
      uri: jms:queue:stock
      steps:
        - log:
            message: "Stock service got ${body}"
        - setBody:
            expression:
              constant:
                expression: '{"reserved": true}'
In Java, setExchangePattern(ExchangePattern.InOut) keeps the exchange InOut for the rest of the route, while pattern on the XML and YAML to applies to that send only. Here it makes no difference, as only a log follows; with another to("jms:…​") later in the route, set the pattern back with setExchangePattern(ExchangePattern.InOnly), or use to(ExchangePattern.InOut, "jms:…​"), which applies to that send only.

The reply queue can also be shared or exclusive: see Request-reply over JMS below.

Routing JMS messages

You can 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:

  • Java

  • XML

  • YAML

from("jms:topic:OrdersTopic")
  .filter().method("myBean", "isGoldCustomer")
  .to("jms:queue:BigSpendersQueue");
<route>
  <from uri="jms:topic:OrdersTopic"/>
  <filter>
    <method ref="myBean" method="isGoldCustomer"/>
    <to uri="jms:queue:BigSpendersQueue"/>
  </filter>
</route>
- route:
    from:
      uri: jms:topic:OrdersTopic
      steps:
        - filter:
            method:
              ref: myBean
              method: isGoldCustomer
            steps:
              - to:
                  uri: jms:queue:BigSpendersQueue

Sending to JMS

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:

  • Java

  • XML

  • YAML

from("file://orders")
  .convertBodyTo(String.class)
  .to("jms:topic:OrdersTopic");
<route>
  <from uri="file://orders"/>
  <convertBodyTo type="String"/>
  <to uri="jms:topic:OrdersTopic"/>
</route>
- route:
    from:
      uri: file://orders
      steps:
        - convertBodyTo:
            type: String
        - to:
            uri: jms:topic:OrdersTopic

Using Annotations

Camel also has annotations, so you can use POJO Consuming and POJO Producing.

Other Examples

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.

Using JMS as a Dead Letter Queue storing Exchange

Normally, when using JMS as the transport, it only transfers the body and headers as the payload. If you want to use JMS with a Dead Letter Channel, 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 transferExchange option on the JMS dead letter queue to instruct Camel to store the entire Exchange in the queue as a jakarta.jms.ObjectMessage that holds a org.apache.camel.support.DefaultExchangeHolder. This allows you to consume from the Dead Letter Queue and retrieve the caused exception from the Exchange property with the key Exchange.EXCEPTION_CAUGHT. The demo below illustrates this:

Java-only: errorHandler configuration is Java DSL specific
// setup error handler to use JMS as queue and store the entire Exchange
errorHandler(deadLetterChannel("jms:queue:dead?transferExchange=true"));

Then you can consume from the JMS queue and analyze the problem:

  • Java

  • XML

  • YAML

from("jms:queue:dead").to("bean:myErrorAnalyzer");
<route>
  <from uri="jms:queue:dead"/>
  <to uri="bean:myErrorAnalyzer"/>
</route>
- route:
    from:
      uri: jms:queue:dead
      steps:
        - to:
            uri: bean:myErrorAnalyzer

And in the myErrorAnalyzer bean:

Java-only: programmatic access to exchange properties and exception
String body = exchange.getIn().getBody();
Exception cause = exchange.getProperty(Exchange.EXCEPTION_CAUGHT, Exception.class);
// the cause message is
String problem = cause.getMessage();

Using JMS as a Dead Letter Channel storing error only

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 Message Translator EIP to do a transformation on the failed exchange before it is moved to the JMS dead letter queue:

Java-only: errorHandler and exceptionMessage() are Java DSL specific
// 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");

Here we only store the original cause error message in the transform. You can, however, use any Expression to send whatever you like. For example, you can invoke a method on a Bean or use a custom processor.

Usage

Message Mapping between JMS and Camel

Camel automatically maps messages between jakarta.jms.Message and org.apache.camel.Message.

When sending a JMS message, Camel converts the message body to the following JMS message types:

Body Type JMS Message Comment

String

jakarta.jms.TextMessage

CharSequence

jakarta.jms.TextMessage

Other text, such as a StringBuilder or a Groovy GString, is converted to String.

org.w3c.dom.Node

jakarta.jms.TextMessage

The DOM will be converted to String.

Map

jakarta.jms.MapMessage

java.io.Serializable

jakarta.jms.ObjectMessage

Only with objectMessageEnabled=true. Otherwise sending fails, and the error names the class of the body.

byte[]

jakarta.jms.BytesMessage

java.io.File

jakarta.jms.BytesMessage

java.io.Reader

jakarta.jms.BytesMessage

java.io.InputStream

jakarta.jms.BytesMessage

org.apache.camel.WrappedFile

jakarta.jms.BytesMessage

org.apache.camel.StreamCache

jakarta.jms.BytesMessage

java.nio.ByteBuffer

jakarta.jms.BytesMessage

null

jakarta.jms.Message

A message without a body.

A body of any other type is first converted to a java.io.File or java.io.InputStream and sent as a jakarta.jms.BytesMessage. When no conversion fits (for example a POJO that is not Serializable), sending fails with a jakarta.jms.MessageFormatException that names the class of the body, so the body is not lost. Implement java.io.Serializable (and enable objectMessageEnabled), force a type with the jmsMessageType option, or marshal the body (for example to JSON) before sending it.

When the streamMessageTypeEnabled option is enabled, bodies of type java.io.File, java.io.Reader, java.io.InputStream, org.apache.camel.WrappedFile and org.apache.camel.StreamCache are sent as jakarta.jms.StreamMessage instead of jakarta.jms.BytesMessage. When artemisStreamingEnabled is in effect, Camel enforces jakarta.jms.BytesMessage even then, because ActiveMQ Artemis has an optimised streaming mode that requires bytes messages.

When receiving a JMS message, Camel converts the JMS message to the following body type:

JMS Message Body Type

jakarta.jms.TextMessage

String

jakarta.jms.BytesMessage

byte[]

jakarta.jms.MapMessage

Map<String, Object>

jakarta.jms.ObjectMessage

Object

jakarta.jms.StreamMessage

java.io.InputStream

Disabling auto-mapping of JMS messages

You can use the mapJmsMessage 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 jakarta.jms.ObjectMessage JMS messages with classes you do not have on the classpath.

Using a custom MessageConverter

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

For example, in the route below, we use a custom message converter when sending a message to the JMS order queue:

  • Java

  • XML

  • YAML

from("file://inbox/order").to("jms:queue:order?messageConverter=#myMessageConverter");
<route>
  <from uri="file://inbox/order"/>
  <to uri="jms:queue:order?messageConverter=#myMessageConverter"/>
</route>
- route:
    from:
      uri: file://inbox/order
      steps:
        - to:
            uri: jms:queue:order
            parameters:
              messageConverter: "#myMessageConverter"

You can also use a custom message converter when consuming from a JMS destination.

Controlling the mapping strategy selected

You can use the jmsMessageType option on the endpoint URL to force a specific message type for all messages.

In the route below, we poll files from a folder and send them as jakarta.jms.TextMessage as we have forced the JMS producer endpoint to use text messages:

  • Java

  • XML

  • YAML

from("file://inbox/order").to("jms:queue:order?jmsMessageType=Text");
<route>
  <from uri="file://inbox/order"/>
  <to uri="jms:queue:order?jmsMessageType=Text"/>
</route>
- route:
    from:
      uri: file://inbox/order
      steps:
        - to:
            uri: jms:queue:order
            parameters:
              jmsMessageType: Text

You can also specify the message type to use for each message by setting the header with the key CamelJmsMessageType. For example:

Java-only: uses the JmsMessageType enum which requires Java code
from("file://inbox/order").setHeader("CamelJmsMessageType", JmsMessageType.Text).to("jms:queue:order");

The possible values are defined in the enum class, org.apache.camel.jms.JmsMessageType.

Message format when sending

The exchange sent over the JMS wire must conform to the JMS Message spec.

For the exchange.in.header the following rules apply for the header keys:

  • Keys starting with JMSX are sent as properties, except those that the JMS provider sets, such as JMSXDeliveryCount or JMSXUserID.

  • Keys starting with JMS_ and a vendor name, such as JMS_IBM_Character_Set, are sent as vendor-specific properties. See Vendor-specific properties.

  • Other keys starting with JMS and a letter, such as JMSType or JMSCorrelationID, are reserved for the standard JMS headers: Camel sets the ones it supports on the message and drops the others.

  • exchange.in.headers keys must be literals and all be valid Java identifiers (do not use dots in the key name).

  • Camel replaces dots & hyphens and the reverse when consuming JMS messages:
    . is replaced by DOT and the reverse replacement when Camel consumes the message.
    - is replaced by HYPHEN and the reverse replacement when Camel consumes the message.

  • See also the option jmsKeyFormatStrategy, which allows use of your own custom strategy for formatting keys.

For the exchange.in.header, the following rules apply for the header values:

  • The values must be primitives or their counter-objects (such as Integer, Long, Character). The types, String, CharSequence, Date, BigDecimal and BigInteger are all converted to their toString() representation. All other types are dropped.

Camel will log with category org.apache.camel.component.jms.JmsBinding at DEBUG level if it drops a given header value. For example:

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}

Vendor-specific properties

The JMS specification keeps the JMS_<vendor>_ prefix for the properties of a JMS provider, such as JMS_IBM_Character_Set of IBM MQ. Set them as message headers: Camel sends such a header as a property of the JMS message, while it does not send exchange properties.

Since Camel 4.22, when the JMS provider refuses a vendor-specific property, for example because it is read-only, Camel logs a WARN and sends the message without it.

A JMS property holds only primitives and strings, so Camel drops a header whose value is a byte[], such as the IBM MQ message descriptor field JMS_IBM_MQMD_MsgId, unless the allowAdditionalHeaders option names it, for example allowAdditionalHeaders=JMS_IBM_MQMD_*. IBM MQ also writes the JMS_IBM_MQMD_* fields only to a destination with its WMQ_MQMD_WRITE_ENABLED property set to true, see Setting JMS provider options on the destination.

Message format when receiving

Camel adds the following properties to the Exchange when it receives a message:

Property Type Description

org.apache.camel.jms.replyDestination

jakarta.jms.Destination

The reply destination.

Camel adds the following JMS properties to the In message headers when it receives a JMS message:

Header Type Description

JMSCorrelationID

String

The JMS correlation ID.

JMSDeliveryMode

int

The JMS delivery mode.

JMSDestination

jakarta.jms.Destination

The JMS destination.

JMSExpiration

long

The JMS expiration.

JMSMessageID

String

The JMS unique message ID.

JMSPriority

int

The JMS priority (with 0 as the lowest priority and 9 as the highest).

JMSRedelivered

boolean

Whether the JMS message is redelivered.

JMSReplyTo

jakarta.jms.Destination

The JMS reply-to destination.

JMSTimestamp

long

The JMS timestamp.

JMSType

String

The JMS type.

JMSXGroupID

String

The JMS group ID.

As all the above information is standard JMS, you can check the JMS documentation for further details.

When pollEnrich or a ConsumerTemplate receives a message from a JMS endpoint, Camel reads the body and the headers of the message before it closes the JMS consumer and session, as a JMS client may not read the message after that (the ActiveMQ Artemis client streams the body of a large message through the consumer). The whole body is read at once (with artemisStreamingEnabled, into a stream cache). If the body cannot be read, the receive fails, and the message is rolled back with transacted=true, or recovered with CLIENT_ACKNOWLEDGE, so that it is delivered again. The body is not read at receive time with mapJmsMessage=false (the body is the jakarta.jms.Message itself), for a StreamMessage (the body is an InputStream that reads the message when it is used), and with a custom jmsOperations that is not a CamelJmsTemplate (the message is read after the session is closed, as before).

About using Camel to send and receive messages and JMSReplyTo

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 areas/pitfalls to look for.

When Camel sends a message using its JMSProducer, it checks the following conditions:

  • The message exchange pattern.

  • Whether a JMSReplyTo was set in the endpoint or in the message headers.

  • Whether any of the following options have been set on the JMS endpoint: disableReplyTo, preserveMessageQos, explicitQosEnabled.

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

JmsProducer

The JmsProducer behaves as follows, depending on configuration:

Exchange Pattern Other options Description

InOut

-

Camel will expect a reply, set a temporary JMSReplyTo, and after sending the message, it will start to listen for the reply message on the temporary queue.

InOut

JMSReplyTo is set

Camel will expect a reply and, after sending the message, it will start to listen for the reply message on the specified JMSReplyTo queue.

InOnly

-

Camel will send the message and not expect a reply.

InOnly

JMSReplyTo is set

By default, Camel discards the JMSReplyTo destination and clears the JMSReplyTo header before sending the message. Camel then sends the message and does not expect a reply. Camel logs this in the log at DEBUG level. You can use preserveMessageQos=true to instruct Camel to keep the JMSReplyTo. In all situations the JmsProducer does not expect any reply and thus continue after sending the message.

JmsConsumer

The JmsConsumer behaves as follows, depending on configuration:

Exchange Pattern Other options Description

InOut

-

Camel will send the reply back to the JMSReplyTo queue.

InOnly

-

Camel will not send a reply back, as the pattern is InOnly.

-

disableReplyTo=true

This option suppress replies.

So pay attention to the message exchange pattern set on your exchanges.

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 Request Reply.
This is useful if you want to send an InOnly message to a JMS topic:

  • Java

  • XML

  • YAML

from("activemq:queue:in")
   .to("bean:validateOrder")
   .to(ExchangePattern.InOnly, "activemq:topic:order")
   .to("bean:handleOrder");
<route>
  <from uri="activemq:queue:in"/>
  <to uri="bean:validateOrder"/>
  <to uri="activemq:topic:order" pattern="InOnly"/>
  <to uri="bean:handleOrder"/>
</route>
- route:
    from:
      uri: activemq:queue:in
      steps:
        - to:
            uri: bean:validateOrder
        - to:
            uri: activemq:topic:order
            pattern: InOnly
        - to:
            uri: bean:handleOrder

Reuse endpoint and send to different destinations computed at runtime

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.

You can specify the destination in the following headers:

Header Type Description

CamelJmsDestination

jakarta.jms.Destination

A destination object.

CamelJmsDestinationName

String

The destination name.

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:

  • Java

  • XML

  • YAML

from("file://inbox")
  .to("bean:computeDestination")
  .to("activemq:queue:dummy");
<route>
  <from uri="file://inbox"/>
  <to uri="bean:computeDestination"/>
  <to uri="activemq:queue:dummy"/>
</route>
- route:
    from:
      uri: file://inbox
      steps:
        - to:
            uri: bean:computeDestination
        - to:
            uri: activemq:queue:dummy

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

In the computeDestination bean, specify the real destination by setting the CamelJmsDestinationName header as follows:

Java-only: bean method that sets the destination header programmatically
public void setJmsHeader(Exchange exchange) {
   String id = ....
   exchange.getIn().setHeader("CamelJmsDestinationName", "order:" + id);
}

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 activemq:queue:order:2, assuming the id value was 2.

If both the CamelJmsDestination and the CamelJmsDestinationName headers are set, CamelJmsDestination takes priority. Keep in mind that the JMS producer removes both CamelJmsDestination and CamelJmsDestinationName headers from the exchange and do not propagate them to the created JMS message to avoid the accidental loops in the routes (in scenarios when the message will be forwarded to another JMS endpoint).

Configuring different JMS providers

You can configure as many JMS component instances as you wish, each with its own connection factory, and give each a unique name. For example, a component named artemis, with the pooledCF connection factory from Connecting to a broker above:

  • Application properties

  • Spring XML

camel.beans.artemis = #class:org.apache.camel.component.jms.JmsComponent
camel.beans.artemis.connectionFactory = #bean:pooledCF
<bean id="artemis" class="org.apache.camel.component.jms.JmsComponent">
  <property name="connectionFactory" ref="pooledCF"/>
</bean>

Once you have a named JMS component, you can refer to destinations of that component with its name as the scheme, for example artemis:[queue:|topic:]destinationName. Camel looks up the component by that name in the registry. You can do the same for other JMS providers, such as IBM MQ or TIBCO EMS.

Using JNDI to find the ConnectionFactory

If you are using a J2EE container, you might need to look up JNDI to find the JMS ConnectionFactory rather than use the usual <bean> mechanism in Spring. You can do this using Spring’s factory bean or the new Spring XML namespace. For example:

<bean id="weblogic" class="org.apache.camel.component.jms.JmsComponent">
  <property name="connectionFactory" ref="myConnectionFactory"/>
</bean>

<jee:jndi-lookup id="myConnectionFactory" jndi-name="jms/connectionFactory"/>

See The jee schema in the Spring reference documentation for more details about JNDI lookup.

Connection errors of the consumer

A consumer that cannot connect to the broker, or loses its connection, does not stop its route: it tries again every recoveryInterval (5 seconds by default), and logs each failure. With testConnectionOnStartup=true, the route fails to start when the consumer cannot connect.

To act on these errors, set an option on the consumer:

  • exceptionListener: a jakarta.jms.ExceptionListener, which gets each JMSException.

  • exceptionHandler: an org.apache.camel.spi.ExceptionHandler, which gets the same exceptions, after the exceptionListener if both are set.

The bridgeErrorHandler option is not supported: a message that fails already goes to the error handler of the route.

Suspending or stopping a consumer when the broker does not answer

Suspending or stopping a consumer (for example, when its route or the CamelContext is stopped) stops its listener container, which stops its JMS connection. When the broker does not answer, the JMS client may only return from that call once a timeout of its own elapses (the callTimeout of ActiveMQ Artemis, 30 seconds by default), and does not react to an interrupt. The consumer waits for its listener container to stop up to the shutdownAwaitTermination of the ExecutorServiceManager (10 seconds by default, at least 100 milliseconds), or until the thread that waits is interrupted (as the graceful shutdown does when its timeout elapses: then it waits at most 100 milliseconds more). It then logs a WARN and no longer uses that listener container: the listener container is stopped and destroyed in the background, once the call returns, and the consumer creates a new one when it is resumed or started again. A listener container that is destroyed ends its non-durable topic subscriptions: the messages published to the topic until the new listener container subscribes do not reach the consumer. Use a durable subscription when they must.

A JMS client also stops a connection only once the message listeners that it is calling return. With consumerType=Simple and Spring’s SyncTaskExecutor as taskExecutor, the JMS client calls the route itself: the consumer then waits as long as the route processes messages, and the time above after the last one. With a thread pool (the one that Camel creates by default, or one of your own), the route processes the messages on its threads, which the JMS client does not wait for.

With asyncStopListener=true, stopping the consumer does not wait for its listener container. Stopping a route or the CamelContext suspends the consumer first, though (unless the route has shutdownRoute set to Defer), and the suspend waits as described above. A suspend from the thread that processes a message of the consumer, such as by a route policy when an exchange is done, stops the listener container on that thread, without this time limit, and so does a stop from that thread, unless asyncStopListener=true.

Concurrent Consuming

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

  • Java

  • XML

  • YAML

from("jms:SomeQueue?concurrentConsumers=20")
  .bean(MyClass.class);
<route>
  <from uri="jms:SomeQueue?concurrentConsumers=20"/>
  <to uri="bean:MyClass"/>
</route>
- route:
    from:
      uri: jms:SomeQueue
      parameters:
        concurrentConsumers: 20
      steps:
        - to:
            uri: bean:MyClass

You can configure this option in one of the following ways:

  • On the JmsComponent,

  • On the endpoint URI or,

  • By invoking setConcurrentConsumers() directly on the JmsEndpoint.

Concurrent Consuming from a topic

On a topic, each concurrent consumer is a subscriber of its own and receives every message. With concurrentConsumers=3 on a topic, each message is processed three times. This is also the case when concurrentConsumers or maxConcurrentConsumers is set on the component (for its queues) and a route of that component consumes from a topic. Camel logs a WARN when such a consumer starts.

To have several consumers share the messages of a topic, so each message is processed once, use a shared subscription (requires a JMS 2.0 broker) with subscriptionShared=true and a subscriptionName. Add subscriptionDurable=true to keep the messages sent while no consumer is connected:

  • Java

  • XML

  • YAML

from("jms:topic:SomeTopic?concurrentConsumers=5&subscriptionShared=true&subscriptionName=myApp")
  .bean(MyClass.class);
<route>
  <from uri="jms:topic:SomeTopic?concurrentConsumers=5&amp;subscriptionShared=true&amp;subscriptionName=myApp"/>
  <to uri="bean:MyClass"/>
</route>
- route:
    from:
      uri: jms:topic:SomeTopic
      parameters:
        concurrentConsumers: 5
        subscriptionShared: true
        subscriptionName: myApp
      steps:
        - to:
            uri: bean:MyClass

Concurrent Consuming with async consumer

Notice that each concurrent consumer will only pick up the next available message from the JMS broker, when the current message has been fully processed. You can set the option asyncConsumer=true to let the consumer pick up the next message from the JMS queue, while the previous message is being processed asynchronously (by the Asynchronous Routing Engine). See more details in the table on top of the page about the asyncConsumer option.

  • Java

  • XML

  • YAML

from("jms:SomeQueue?concurrentConsumers=20&asyncConsumer=true")
  .bean(MyClass.class);
<route>
  <from uri="jms:SomeQueue?concurrentConsumers=20&amp;asyncConsumer=true"/>
  <to uri="bean:MyClass"/>
</route>
- route:
    from:
      uri: jms:SomeQueue
      parameters:
        concurrentConsumers: 20
        asyncConsumer: true
      steps:
        - to:
            uri: bean:MyClass

Request-reply over JMS

Camel supports Request Reply over JMS. In essence the MEP of the Exchange should be InOut when you send a message to a JMS queue. The example in Sending a request and waiting for the reply shows the caller and the service. Camel sets the JMSReplyTo header and waits for the reply. You do not need to set replyTo or a JMSReplyTo header: Camel uses a temporary reply queue by default. Set replyTo for a fixed (shared or exclusive) reply queue, see below.

Camel offers a number of options to configure request/reply over JMS that influence performance and clustered environments. The table below summaries the options.

Option Performance Cluster Description

Temporary

Fast

Yes

A temporary queue is used as reply queue, and automatic created by Camel. To use this, do not specify a replyTo queue name. And you can optionally configure replyToType=Temporary to make it stand out that temporary queues are in use.

Shared

Slow

Yes

A shared persistent queue is used as reply queue. The queue must be created beforehand, although some brokers can create them on the fly, such as Apache ActiveMQ. To use this, you must specify the replyTo queue name. And you can optionally configure replyToType=Shared to make it stand out that shared queues are in use. A shared queue can be used in a clustered environment with multiple nodes running this Camel application at the same time. All of them using the same shared reply queue. This is possible because JMS Message selectors are used to correlate expected reply messages; this impacts performance though. JMS Message selectors are slower, and therefore not as fast as Temporary or Exclusive queues. See further below how to tweak this for better performance.

Exclusive

Fast

No (*Yes)

An exclusive persistent queue is used as reply queue. The queue must be created beforehand, although some brokers can create them on the fly, such as Apache ActiveMQ. To use this, you must specify the replyTo queue name. And you must configure replyToType=Exclusive to instruct Camel to use exclusive queues, as Shared is used by default, if a replyTo queue name was configured. When using exclusive reply queues, then JMS Message selectors are not in use, and therefore other applications must not use this queue as well. An exclusive queue cannot be used in a clustered environment with multiple nodes running this Camel application at the same time; as we do not have control if the reply queue comes back to the same node that sent the request message; that is why shared queues use JMS Message selectors to make sure of this. Though if you configure each Exclusive reply queue with a unique name per node, then you can run this in a clustered environment. As then the reply message will be sent back to that queue for the given node that awaits the reply message.

concurrentConsumers

Fast

Yes

Allows processing reply messages concurrently using concurrent message listeners in use. You can specify a range using the concurrentConsumers and maxConcurrentConsumers options. Notice: That using Shared reply queues may not work as well with concurrent listeners, so use this option with care.

maxConcurrentConsumers

Fast

Yes

Allows processing reply messages concurrently using concurrent message listeners in use. You can specify a range using the concurrentConsumers and maxConcurrentConsumers options. Notice: That using Shared reply queues may not work as well with concurrent listeners, so use this option with care.

The JmsProducer detects the InOut and provides a JMSReplyTo header with the reply destination to be used. By default, Camel uses a temporary queue, but you can use the replyTo option on the endpoint to specify a fixed reply queue (see more below about fixed reply queue).

Camel will automatically set up a consumer that listens to on the reply queue, so you should not do anything.
This consumer is a Spring DefaultMessageListenerContainer which listen for replies. However, it’s fixed to one concurrent consumer.
That means replies will be processed in sequence as there is only one thread to process the replies. You can configure the listener to use concurrent threads using the concurrentConsumers and maxConcurrentConsumers options. This allows you to easier configure this in Camel as shown below:

Java-only: uses to(ExchangePattern.InOut, …​) for the request-reply pattern
from(xxx)
.to(ExchangePattern.InOut, "activemq:queue:foo?concurrentConsumers=5")
.to(yyy)
.to(zzz);

In this route, we instruct Camel to route replies asynchronously using a thread pool with five threads.

Request-reply over JMS and using a shared fixed reply queue

If you use a fixed reply queue when doing Request Reply over JMS as shown in the example below, then pay attention.

Java-only: uses to(ExchangePattern.InOut, …​) for the request-reply pattern
from(xxx)
.to(ExchangePattern.InOut, "activemq:queue:foo?replyTo=bar")
.to(yyy)

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 JMSSelector to only pick up the expected reply messages (e.g., based on the JMSCorrelationID). See the next section for exclusive fixed reply queues. That means it’s not as fast as temporary queues. You can speed up how often Camel will pull for reply messages using the receiveTimeout option. By default, its 1000 milliseconds. So to make it faster, you can set it to 250 millis to pull 4 times per second as shown:

Java-only: uses to(ExchangePattern.InOut, …​) for the request-reply pattern
from(xxx)
.to(ExchangePattern.InOut, "activemq:queue:foo?replyTo=bar&receiveTimeout=250")
.to(yyy)

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

Request-reply over JMS and using an exclusive fixed reply queue

In the previous example, Camel would anticipate the fixed reply queue named "bar" was shared, and thus it uses a JMSSelector to only consume reply messages which it expects. However, there is a drawback to doing this as the JMS selector 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 receiveTimeout 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. There is the ReplyToType option which you can configure to Exclusive
to tell Camel that the reply queue is exclusive as shown in the example below:

Java-only: uses to(ExchangePattern.InOut, …​) for the request-reply pattern
from(xxx)
.to(ExchangePattern.InOut, "activemq:queue:foo?replyTo=bar&replyToType=Exclusive")
.to(yyy)

Mind that the queue must be exclusive to each and every endpoint. So if you have two routes, then they each need a unique reply queue as shown in the next example:

Java-only: uses to(ExchangePattern.InOut, …​) for the request-reply pattern
from(xxx)
.to(ExchangePattern.InOut, "activemq:queue:foo?replyTo=bar&replyToType=Exclusive")
.to(yyy)

from(aaa)
.to(ExchangePattern.InOut, "activemq:queue:order?replyTo=order.reply&replyToType=Exclusive")
.to(bbb)

The same applies if you run in a clustered environment. Then each node in the cluster must use a unique reply queue name. As otherwise, each node in the cluster may pick up messages intended as a reply on another node. For clustered environments, it’s recommended to use shared reply queues instead.

Synchronizing clocks between senders and receivers

When doing messaging between systems, it is desirable that the systems have synchronized clocks. For example, when sending a JMS 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 ActiveMQ, then you can use the timestamp plugin to synchronize clocks.

About time to live

Read first above about synchronized clocks.

When you do request/reply (InOut) over JMS with Camel, then Camel uses a timeout on the sender side, which is default 20 seconds from the requestTimeout option. You can control this by setting a higher/lower value. However, the time to live value is still set on the JMS message being sent. 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 disableTimeToLive option from Camel 2.8 onwards. So if you set this option to disableTimeToLive=true, then Camel does not set any time to live value when sending JMS messages. But the request timeout is still active. So for example, if you do request/reply over JMS and have disabled time to live, then Camel will still use a timeout by 20 seconds (the requestTimeout option). That option can also be configured. So the two options requestTimeout and disableTimeToLive gives you Fine-grained control when doing request/reply.

You can provide a header in the message to override and use as the request timeout value instead of the endpoint configured value. For example:

  • Java

  • XML

  • YAML

from("direct:someWhere")
  .to("jms:queue:foo?replyTo=bar&requestTimeout=30s")
  .to("bean:processReply");
<route>
  <from uri="direct:someWhere"/>
  <to uri="jms:queue:foo?replyTo=bar&amp;requestTimeout=30s"/>
  <to uri="bean:processReply"/>
</route>
- route:
    from:
      uri: direct:someWhere
      steps:
        - to:
            uri: jms:queue:foo
            parameters:
              replyTo: bar
              requestTimeout: 30s
        - to:
            uri: bean:processReply

In the route above we have an endpoint configured requestTimeout of 30 seconds. So Camel will wait up till 30 seconds for that reply message to come back on the bar queue. If no reply message is received then a org.apache.camel.ExchangeTimedOutException is set on the Exchange, and Camel continues routing the message, which would then fail due the exception, and Camel’s error handler reacts.

If you want to use a per message timeout value, you can set the header CamelJmsRequestTimeout with a timeout value as a long type.

The header name is CamelJmsRequestTimeout.

For example, we can use a bean to compute the timeout value per individual message, such as calling the "whatIsTheTimeout" method on the service bean as shown below:

  • Java

  • XML

  • YAML

from("direct:someWhere")
  .setHeader("CamelJmsRequestTimeout", method(ServiceBean.class, "whatIsTheTimeout"))
  .to("jms:queue:foo?replyTo=bar&requestTimeout=30s")
  .to("bean:processReply");
<route>
  <from uri="direct:someWhere"/>
  <setHeader name="CamelJmsRequestTimeout">
    <method ref="serviceBean" method="whatIsTheTimeout"/>
  </setHeader>
  <to uri="jms:queue:foo?replyTo=bar&amp;requestTimeout=30s"/>
  <to uri="bean:processReply"/>
</route>
- route:
    from:
      uri: direct:someWhere
      steps:
        - setHeader:
            name: CamelJmsRequestTimeout
            method:
              ref: serviceBean
              method: whatIsTheTimeout
        - to:
            uri: jms:queue:foo
            parameters:
              replyTo: bar
              requestTimeout: 30s
        - to:
            uri: bean:processReply

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

Enabling Transacted Consumption

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:

  • transacted = true

  • transactionManager = a Transsaction Manager - typically the JmsTransactionManager

See the Transactional Client EIP pattern for further details.

A message that the route sends with the JMS component is part of the transaction of the consumer when the producer endpoint uses the same connection factory as the consumer endpoint. This is the case for the connection factory of the component, also when username and password are set on the component, or set to the same values on both endpoints. A producer endpoint with its own connectionFactory, or with other credentials, sends outside the transaction of the consumer.

Transactions and [Request Reply] over JMS

When using Request Reply 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 Request Reply, you must commit a transaction after sending the request and then use a separate transaction for receiving the response.

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

The transacted property applies only to the InOnly message Exchange Pattern (MEP).

You can leverage the DMLC transacted session API using the following properties on component/endpoint:

  • transacted = true

  • lazyCreateTransactionManager = false

The benefit of doing so is that the cacheLevel setting will be honored when using local transactions without a configured TransactionManager. When a TransactionManager is configured, no caching happens at DMLC level, and it is necessary to rely on a pooled connection factory. For more details about this kind of setup, see here and here.

Using JMSReplyTo for late replies

When using Camel as a JMS listener, it sets an Exchange property with the value of the ReplyTo jakarta.jms.Destination object, having the key ReplyTo. You can obtain this Destination as follows:

Java-only: uses JMS Destination object and Camel Java API
Destination replyDestination = exchange.getIn().getHeader("JMSReplyTo", Destination.class);

And then later use it to send a reply using regular JMS or Camel.

Java-only: uses JmsEndpoint and ProducerTemplate Java API
// 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.");

A different solution to sending a reply is to provide the replyDestination 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:

Java-only: uses ProducerTemplate and Processor to set the JMS destination object programmatically
// we pretend to send it to some non-existing dummy queue
template.send("activemq:queue:dummy", exchange -> {
      // and here we override the destination with the ReplyTo destination object so the message is sent to there instead of dummy
      exchange.getIn().setHeader("CamelJmsDestination", replyDestination);
      exchange.getIn().setBody("Here is the late reply.");
});

Using a request timeout

A producer that sends an InOut exchange waits for the reply up to requestTimeout (20 seconds by default), and then fails the exchange with an ExchangeTimedOutException. The CamelJmsRequestTimeout header sets the timeout of one message.

An exchange is InOut when the consumer of the route answers its caller, such as an HTTP, REST or platform-http consumer, or a JMS consumer that receives a message with a JMSReplyTo, or when it comes from a request method of a ProducerTemplate. Then a to("jms:queue:orders") sends the message as a request and waits for a reply, also when no consumer of orders sends one. When no reply is expected, send the message InOnly, with the exchangePattern option:

  • Java

  • YAML

from("platform-http:/orders")
  .to("jms:queue:orders?exchangePattern=InOnly")
  .setBody(constant("Accepted"));
- route:
    from:
      uri: platform-http:/orders
      steps:
        - to:
            uri: jms:queue:orders
            parameters:
              exchangePattern: InOnly
        - setBody:
            constant: Accepted

The option disableReplyTo=true also sends the message without waiting for a reply.

Sending an InOnly message and keeping the JMSReplyTo header

When sending to a JMS destination using camel-jms, the producer will use the MEP to detect if it is InOnly or InOut messaging. However, there can be times when 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.

For example, to send an InOnly message to the foo queue, but with a JMSReplyTo with bar queue you can do as follows:

Java-only: uses ProducerTemplate test API to send with custom JMS headers
template.send("activemq:queue:foo?preserveMessageQos=true", exchange -> {
      exchange.getIn().setBody("World");
      exchange.getIn().setHeader("JMSReplyTo", "bar");
});

Notice we use preserveMessageQos=true to instruct Camel to keep the JMSReplyTo header.

Setting JMS provider options on the destination

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:

  • Java

  • XML

  • YAML

// ...
.setHeader("CamelJmsDestinationName", constant("queue:///MY_QUEUE?targetClient=1"))
.to("wmq:queue:MY_QUEUE?useMessageIDAsCorrelationID=true");
<!-- ... -->
<setHeader name="CamelJmsDestinationName">
  <constant>queue:///MY_QUEUE?targetClient=1</constant>
</setHeader>
<to uri="wmq:queue:MY_QUEUE?useMessageIDAsCorrelationID=true"/>
# ...
- setHeader:
    name: CamelJmsDestinationName
    constant: "queue:///MY_QUEUE?targetClient=1"
- to:
    uri: wmq:queue:MY_QUEUE
    parameters:
      useMessageIDAsCorrelationID: true

Some versions of WMQ won’t accept this option on the destination name, and you will get an exception like:

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

A workaround is to use a custom DestinationResolver:

Java-only: programmatic JMS component configuration with custom `DestinationResolver`
JmsComponent wmq = new JmsComponent(connectionFactory);

wmq.setDestinationResolver((session, destinationName, pubSubDomain) -> {
    MQQueueSession wmqSession = (MQQueueSession) session;
    return wmqSession.createQueue("queue:///" + destinationName + "?targetClient=1");
});