浏览 2703 次
精华帖 (0) :: 良好帖 (0) :: 新手帖 (0) :: 隐藏帖 (0)
|
|
---|---|
作者 | 正文 |
发表时间:2008-01-20
2、使用XA实现事务。 消息接收器代码: public class ReceiverListener implements SessionAwareMessageListener { public void onMessage(Message message, Session session) throws JMSException { if (message instanceof TextMessage) { try { System.out.println("New Receive Message: " + ((TextMessage) message).getText()); } catch (JMSException ex) { throw new RuntimeException(ex); } } else { throw new IllegalArgumentException( "Message must be of type TextMessage"); } } } Spring配置: <bean id="userJmsUtil" class="com.hc360.mmt.common.UserJmsTransactionUtil"> <property name="destinationJndi" value="queue/A"></property> <property name="connectionFactoryJndi" value="java:JmsXA"></property> <property name="factoryInitial" value="org.jnp.interfaces.NamingContextFactory"></property> <property name="providerUrl" value="localhost"></property> <property name="factoryUrlPkgs" value="org.jboss.naming:org.jnp.interfaces"></property> </bean> <bean id="jmsQueueConnectionFactory" class="org.springframework.beans.factory.config.MethodInvokingFactoryBean"> <property name="targetObject" ref="userJmsUtil"></property> <property name="targetMethod" value="getConnectionFactory"></property> </bean> <bean id="destination" class="org.springframework.beans.factory.config.MethodInvokingFactoryBean"> <property name="targetObject" ref="userJmsUtil"></property> <property name="targetMethod" value="getDestination"></property> </bean> <!-- this is the Message Driven POJO (MDP) --> <bean id="messageListener" class="com.hc360.jms.ReceiverListener" /> <!-- and this is the attendant message listener container --> <bean id="listenerContainer1" class="org.springframework.jms.listener.DefaultMessageListenerContainer"> <property name="concurrentConsumers" value="1"/> <property name="connectionFactory" ref="jmsQueueConnectionFactory" /> <property name="destination" ref="destination" /> <property name="messageListener" ref="messageListener" /> <property name="transactionManager" ref="transactionManagerJTA" /> </bean> <bean id="transactionManagerJTA" class="org.springframework.transaction.jta.JtaTransactionManager"> <property name="userTransactionName"> <value>UserTransaction</value> </property> </bean> 声明:ITeye文章版权属于作者,受法律保护。没有作者书面许可不得转载。
推荐链接
|
|
返回顶楼 | |