1、开发环境: eclipse3.2+jdk1.5+jboss4.2.2
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>
分享到:
相关推荐
Spring发送接收JMS消息 文档+例子
activemq消息中间件的使用demo,以及spring集合jms实现消息发送和处理。
基于Spring+JMS+ActiveMQ+Tomcat,我使用的版本情况如下所示:Spring 3.2.0,ActiveMQ 5.4.3,Tomcat 6.0.43。本例通过详细的说明和注释,实现消息服务的基本功能:发送与接收。Spring对JMS提供了很好的支持,可以...
spring-jmsspring-jmsspring-jmsspring-jmsspring-jmsspring-jms
赠送jar包:spring-jms-4.3.12.RELEASE.jar; 赠送原API文档:spring-jms-4.3.12.RELEASE-javadoc.jar; 赠送源代码:spring-jms-4.3.12.RELEASE-sources.jar; 赠送Maven依赖信息文件:spring-jms-4.3.12.RELEASE....
使用Spring JMS轻松实现异步消息传递.docx使用Spring JMS轻松实现异步消息传递.docx
使用Spring JMS轻松实现异步消息传递.pdf使用Spring JMS轻松实现异步消息传递.pdf
Spring整合JMS,基于ActiveMQ实现收发消息
赠送jar包:spring-jms-4.3.20.RELEASE.jar; 赠送原API文档:spring-jms-4.3.20.RELEASE-javadoc.jar; 赠送源代码:spring-jms-4.3.20.RELEASE-sources.jar; 包含翻译后的API文档:spring-jms-4.3.20.RELEASE-...
Spring+JMS+消息处理
赠送jar包:spring-jms-4.3.20.RELEASE.jar 赠送原API文档:spring-jms-4.3.20.RELEASE-javadoc.jar 赠送源代码:spring-jms-4.3.20.RELEASE-sources.jar 包含翻译后的API文档:spring-jms-4.3.20.RELEASE-...
Spring-JMS把企业消息处理变容易.doc
spring-jms-4.1.4,Spring提供的JMS工具类,它发送、接收消息
spring_jms是基于Maven+Spring+JMS+Active入门级实例.
spring-jms-4.0.0.RELEASE.jar spring-jms-4.0.0.RELEASE.jar spring-jms-4.0.0.RELEASE.jar spring-jms-4.0.0.RELEASE.jar
spring+jms+jta事务的消息发送和消息消费。 完整可正常运行例子,对JTA分布式事务的配置。 本例可以直接作为处理消息的项目,在此之上直接继续开发。
NULL 博文链接:https://a3mao.iteye.com/blog/313531
activemq与spring整合发送jms消息入门实例 jar 包和实例代码都在压缩包里了
spring-jms-5.0.4.RELEASE.jar ;spring-jms-5.0.4.RELEASE.jar
在 Spring 2.5 中,可以使用 Spring 的事务管理器来实现分布式事务管理。事务管理器可以与多个资源管理器集成,以便提供分布式事务管理的支持。 抽象的 DAO: 抽象的 DAO 是指提供了基本的 CRUD 操作的接口,它...