Spring Boot JTA with Artemis Issue

901 Views Asked by At

I am trying to use XA Connection of Apache ActiveMQ Artemis for JMS with Spring Boot. My relevant config looks like this:

spring:  
  artemis:
    host: localhost
    mode: native

  jta:
    bitronix:
      tm:
        serverId: spring-btm
        timer:
          defaultTransactionTimeout: 100

      connectionfactory:
        user: jmsuser
        password: password
        allow-local-transactions: true
        class-name: org.apache.activemq.artemis.jms.client.ActiveMQXAConnectionFactory

But this is producing continuous errors in the log which says:

o.s.t.jta.JtaTransactionManager - Using JTA TransactionManager: a BitronixTransactionManager with 0 in-flight transaction(s)
WARN  bitronix.tm.twopc.Preparer - executing transaction with 0 enlisted resource

The "executing transaction with 0 enlisted resource" keeps getting printed every 3 milliseconds. How do we get the BTM JTA provider to "see" that it should use the Artemis resource? I have had MySQL based spring boot application working without much fuss but Artemis does not work.

1

There are 1 best solutions below

0
samyem On

I've eventually figured it out. The trick is to use the Spring Boot's JTA wrapper with XAConnectionFactoryWrapper as:

@Bean(name = { "jmsConnectionFactory"})
public ConnectionFactory artemisJmsConnectionFactory(ListableBeanFactory beanFactory,
        ArtemisProperties properties, XAConnectionFactoryWrapper wrapper) throws Exception {

    ActiveMQXAConnectionFactory xaFactory = new ArtemisConnectionFactoryFactory(beanFactory, properties)
                .createConnectionFactory(ActiveMQXAConnectionFactory.class);
    javax.jms.ConnectionFactory wrapConnectionFactory = wrapper.wrapConnectionFactory(xaFactory);
    return wrapConnectionFactory;
}

That solved the issue of the resource not being enlisted in the JTA transaction.