0

I have a simple XA test setup, using JMS and JDBC. I use Atomikos 3.9.3, ActiveMQ 5.10.1 and DB2, with their proper XA drivers.

Sending messaged works ok, it is transactional. But the consume case does not - despite throwing an exception, the JMS message is consumed.

The strange thing is that it seems to be timing related - usually the first time the transaction is rolled back, and the message is still there - but one of the subsequent attempts to consume the message from the queue is successful.

This is my spring configuration for consuming messages:

<?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>

I have @Transactional and @JmsListener(destination = "test.q1") annotations on my MessageHandlerImpl.handleOrder() method.

I have no idea what I'm doing wrong.

Michael Böckling
  • 7,341
  • 6
  • 55
  • 76

1 Answers1

0

Turns out everything was working fine, the messages ended up in the dead letter queue. I feel stupid now.

Michael Böckling
  • 7,341
  • 6
  • 55
  • 76