0

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.

4

1 回答 1

0

我终于想通了。诀窍是将 Spring Boot 的 JTA 包装器与 XAConnectionFactoryWrapper 一起使用:

@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;
}

这解决了资源未被纳入 JTA 事务的问题。

于 2018-07-11T20:44:32.073 回答