JMS Component

The JMS component allows messages to be sent to a JMS Queue or Topic; or messages to be consumed from a JMS Queue or Topic. The implementation of the JMS Component uses Spring's JMS support for declarative transactions, using Spring's JmsTemplate for sending and a MessageListenerContainer for consuming.

URI format

jms:[topic:]destinationName?properties

So for example to send to queue FOO.BAR you would use

jms:FOO.BAR

You can be completely specific if you wish via

jms:queue:FOO.BAR

If you want to send to a topic called Stocks.Prices then you would use

jms:topic:Stocks.Prices

Notes

If you wish to use durable topic subscriptions, you need to specify both clientId and durableSubscriberName. Note that the value of the clientId must be unique and can only be used by a single JMS connection instance in your entire network. You may prefer to use Virtual Topics instead to avoid this limitation. More background on durable messaging here.

If you are using ActiveMQ

Note that the JMS component reuses Spring 2's JmsTemplate for sending messages. This is not ideal for use in a non-J2EE container and typically requires some caching JMS provider to avoid performance being lousy.

So if you intent to use Apache ActiveMQ as your Message Broker - which is a good choice as ActiveMQ rocks , then we recommend that you either

  • use the ActiveMQ component which is already configured to use ActiveMQ efficiently

  • use the PoolingConnectionFactory in ActiveMQ

Properties

You can configure lots of different properties on the JMS endpoint which map to properties on the JMSConfiguration POJO.

PropertyDefault ValueDescription
acceptMessagesWhileStoppingfalseShould the consumer accept messages while it is stopping
acknowledgementModeName"AUTO_ACKNOWLEDGE"The JMS acknowledgement name which is one of: TRANSACTED, CLIENT_ACKNOWLEDGE, AUTO_ACKNOWLEDGE, DUPS_OK_ACKNOWLEDGE
autoStartuptrueShould the consumer container auto-startup
cacheLevelName"CACHE_CONSUMER"Sets the cache level name for the underlying JMS resources
clientIdnullSets the JMS client ID to use. Note that this value if specified must be unique and can only be used by a single JMS connection instance. Its typically only required for durable topic subscriptions. You may prefer to use Virtual Topics instead
concurrentConsumers1Specifies the default number of concurrent consumers
connectionFactorynullThe default JMS connection factory to use for the listenerConnectionFactory and templateConnectionFactory if neither are specified
deliveryPersistenttrueIs persistent delivery used by default?
durableSubscriptionNamenullThe durable subscriber name for specifying durable topic subscriptions
exceptionListenernullThe JMS Exception Listener used to be notified of any underlying JMS exceptions
explicitQosEnabledfalseSet if the deliveryMode, priority or timeToLive should be used when sending messages
exposeListenerSessiontrueSet if the listener session should be exposed when consuming messages
idleTaskExecutionLimit1Specify the limit for idle executions of a receive task, not having received any message within its execution. If this limit is reached, the task will shut down and leave receiving to other executing tasks (in case of dynamic scheduling; see the "maxConcurrentConsumers" setting).
listenerConnectionFactorynullThe JMS connection factory used for consuming messages
maxConcurrentConsumers1Specifies the maximum number of concurrent consumers
maxMessagesPerTask1The number of messages per task
messageConverternullThe Spring Message Converter
messageIdEnabledtrueWhen sending, should message IDs be added
messageTimestampEnabledtrueShould timestamps be enabled by default on sending messages
priority-1Values of > 1 specify the message priority when sending, if the explicitQosEnabled property is specified
receiveTimeoutnoneThe timeout when receiving messages
recoveryIntervalnoneThe recovery interval
serverSessionFactorynullThe JMS ServerSessionFactory if you wish to use ServerSessionFactory for consumption
subscriptionDurablefalseEnabled by default if you specify a durableSubscriberName and a clientId
taskExecutornullAllows you to specify a custom task executor for consuming messages
templateConnectionFactorynullThe JMS connection factory used for sending messages
timeToLivenullIs a time to live specified when sending messages
transactedfalseIs transacted mode used for sending/receiving messages?
transactionManagernullThe Spring transaction manager to use
transactionNamenullThe name of the transaction to use
transactionTimeoutnullThe timeout value of the transaction if using transacted mode
useVersion102falseShould the old JMS API be used

See Also