Java Reference
In-Depth Information
Managing JMS Transactions
As mentioned before,
SimpleMessageListenerContainer
doesn't support transactions. So,
if you need transaction management for your message listener method, you have to use
DefaultMessageListenerContainer
instead. For local JMS transactions, you can simply enable its
sessionTransacted
property, and your listener method will run within a local JMS transaction (as
opposed to XA transactions).
<bean
class="org.springframework.jms.listener.DefaultMessageListenerContainer">
<property name="connectionFactory" ref="connectionFactory" />
<property name="destinationName" value="mail.queue" />
<property name="messageListener" ref="mailListenerAdapter" />
<property name="sessionTransacted" value="true" />
</bean>
However, if you want your listener to participate in a JTA transaction, you need to declare a
JtaTransactionManager
instance and inject it into your listener container.
Using Spring's JMS Schema
Spring, from 2.5 and onward, offers a new JMS schema to simplify your JMS listener and listener
container configuration. You must add the
jms
schema definition to the
<beans>
root element
beforehand.
<beans xmlns="
http://www.springframework.org/schema/beans"
xmlns:xsi="
http://www.w3.org/2001/XMLSchema-instance"
xmlns:jms="
http://www.springframework.org/schema/jms"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
<bean id="connectionFactory"
class="org.apache.activemq.ActiveMQConnectionFactory">
<property name="brokerURL" value="
tcp://localhost:61616"
/>
</bean>
<bean id="transactionManager"
class="org.springframework.jms.connection.JmsTransactionManager">
<property name="connectionFactory">
<ref bean="connectionFactory" />
</property>
</bean>
<bean id="mailMessageConverter"
class="com.apress.springenterpriserecipes.post.MailMessageConverter" />
Search WWH ::
Custom Search