我使用JMS和JDBC进行简单的XA测试设置。我使用Atomikos 3.9.3,ActiveMQ 5.10.1和DB2,以及它们正确的XA驱动程序。
发送消息正常,它是事务性的。但是消费案例并没有 - 尽管抛出了异常,但JMS消息被消耗了。
奇怪的是它似乎与时间相关 - 通常是第一次回滚事务,并且消息仍在那里 - 但是后续尝试从队列中消费消息是成功的。
这是我用于消费消息的弹簧配置:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx" xmlns:jms="http://www.springframework.org/schema/jms"
xsi:schemaLocation=" http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.0.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.0.xsd http://www.springframework.org/schema/jms http://www.springframework.org/schema/jms/spring-jms.xsd">
<bean id="xaConnectionFactory" class="org.apache.activemq.ActiveMQXAConnectionFactory">
<constructor-arg value="mulejms" />
<constructor-arg value="mulejms" />
<constructor-arg value="tcp://localhost:61616" />
</bean>
<bean id="atomikosConnectionFactoryBean" class="com.atomikos.jms.AtomikosConnectionFactoryBean"
init-method="init" destroy-method="close">
<property name="uniqueResourceName" value="amq1" />
<property name="xaConnectionFactory" ref="xaConnectionFactory" />
</bean>
<bean id="msgHandler" class="com.findonnet.messaging.MessageHandlerImpl">
<property name="sequenceDAO" ref="sequenceDAO" />
</bean>
<!-- End Messaging related beans -->
<bean id="dataSource" class="com.atomikos.jdbc.AtomikosDataSourceBean"
init-method="init" destroy-method="close">
<property name="uniqueResourceName" value="DB2" />
<property name="xaDataSource" ref="db2DataSource" />
</bean>
<bean id="db2DataSource" class="com.ibm.db2.jcc.DB2XADataSource">
<property name="serverName" value="localhost" />
<property name="portNumber" value="50000" />
<property name="databaseName" value="HWEXT" />
<property name="driverType" value="4" />
<property name="user" value="hwextdev" />
<property name="password" value="hwextdev" />
</bean>
<!-- ===================================================== -->
<!-- ==== TRANSACTION MANAGER CONFIG ===================== -->
<!-- ===================================================== -->
<bean id="atomikosTransactionManager" class="com.atomikos.icatch.jta.UserTransactionManager"
init-method="init" destroy-method="close">
<property name="forceShutdown" value="true" />
</bean>
<bean id="atomikosUserTransaction" class="com.atomikos.icatch.jta.UserTransactionImp" />
<bean id="transactionManager"
class="org.springframework.transaction.jta.JtaTransactionManager">
<property name="transactionManager" ref="atomikosTransactionManager" />
<property name="userTransaction" ref="atomikosUserTransaction" />
</bean>
<!-- enable transaction annotations, and use the correct transaction manager! -->
<tx:annotation-driven transaction-manager="transactionManager" />
<bean id="sequenceDAO" class="com.findonnet.persistence.MessageSequenceDAO">
<property name="dataSource" ref="dataSource" />
</bean>
<!-- ========================================= -->
<!-- ==== JMS CONFIG FOR SPRING=============== -->
<!-- ========================================= -->
<jms:annotation-driven container-factory="listenerContainer" />
<jms:listener-container connection-factory="atomikosConnectionFactoryBean"
transaction-manager="transactionManager" concurrency="1"
factory-id="listenerContainer" />
</beans>
我的MessageHandlerImpl.handleOrder()方法上有@Transactional和@JmsListener(destination =&#34; test.q1&#34;)注释。
我不知道我做错了什么。
答案 0 :(得分:0)
事实证明一切正常,消息最终在死信队列中。我现在觉得很蠢。