javax.jms.TransactionInProgressException: 无法在 JBoss EAP 6.2 和 Active MQ 5.10.0 上的 XASession 中回滚()

Posted

技术标签:

【中文标题】javax.jms.TransactionInProgressException: 无法在 JBoss EAP 6.2 和 Active MQ 5.10.0 上的 XASession 中回滚()【英文标题】:javax.jms.TransactionInProgressException: Cannot rollback() inside an XASession on JBoss EAP 6.2 and Active MQ 5.10.0 【发布时间】:2014-12-25 03:17:34 【问题描述】:

我们正在尝试使用在 JBoss EAP 6.2 上运行的 Active MQ 5.10.0、camel 2.13.1 创建一个 XA 连接池。当连接释放到池中时,将引发以下异常。根据其他线程,此错误已在 Active MQ 5.8.x 中修复。知道为什么我们仍然会收到错误吗?活动 MQ 客户端和服务器使用 5.10.0 运行。

弹簧配置:

 <!-- JBoss TX Manager -->
    <bean id="jtaTxManager"
        class="org.springframework.transaction.jta.JtaTransactionManager">
        <property name="transactionManagerName" value="java:/TransactionManager" />
    </bean>
    
    <bean id="jmsXaConnectionFactory" class="org.apache.activemq.ActiveMQXAConnectionFactory">
        <property name="brokerURL" value="$camelPropbrokerUrl" />
        <property name="userName" value="$camelPropqueueUsername" />
        <property name="password" value="$camelPropqueuePw" />
    </bean>
    
     <bean id="pooledXAConnectionFactory" class="org.apache.activemq.pool.XaPooledConnectionFactory"
        init-method="start" destroy-method="stop">
        <property name="maxConnections" value="$camelPropqueue.maxConnections" />
        <property name="connectionFactory" ref="jmsXaConnectionFactory" />
    </bean>

    <bean id="jmsConfig" class="org.apache.camel.component.jms.JmsConfiguration">
        <property name="connectionFactory" ref="pooledXAConnectionFactory" />
        <property name="concurrentConsumers" value="$camelPropqueue.concurrentConsumers" />
        <!-- define the jms consumer/producer as transacted -->
        <property name="transacted" value="true" />
        <!-- setup the transaction manager to use -->
        <property name="transactionManager" ref="jtaTxManager" />
    </bean>

    <!-- define our activemq component -->
    <bean id="activemq"
        class="org.apache.activemq.camel.component.ActiveMQComponent">
        <property name="configuration" ref="jmsConfig" />
    </bean>

例外:

12:45:06,277 WARN [org.apache.activemq.jms.pool.PooledSession] (http-localhost/127.0.0.1:8180-1) 将会话放回池中时尝试回滚()时捕获异常,将无效。 javax.jms.TransactionInProgressException:无法在 XASession 内回滚():javax.jms.TransactionInProgressException:无法在 XASession 内回滚() 在 org.apache.activemq.ActiveMQXASession.rollback(ActiveMQXASession.java:78) [activemq-client-5.10.0.jar:5.10.0] 在 org.apache.activemq.jms.pool.PooledSession.close(PooledSession.java:116) [activemq-jms-pool-5.10.0.jar:5.10.0] 在 org.springframework.jms.connection.JmsResourceHolder.closeAll(JmsResourceHolder.java:215) [spring-jms-3.2.8.RELEASE.jar:3.2.8.RELEASE] 在 org.springframework.jms.connection.ConnectionFactoryUtils$JmsResourceSynchronization.releaseResource(ConnectionFactoryUtils.java:412) [spring-jms-3.2.8.RELEASE.jar:3.2.8.RELEASE] 在 org.springframework.jms.connection.ConnectionFactoryUtils$JmsResourceSynchronization.releaseResource(ConnectionFactoryUtils.java:389) [spring-jms-3.2.8.RELEASE.jar:3.2.8.RELEASE] 在 org.springframework.transaction.support.ResourceHolderSynchronization.afterCompletion(ResourceHolderSynchronization.java:98) [spring-tx-3.2.8.RELEASE.jar:3.2.8.RELEASE] 在 org.springframework.transaction.support.TransactionSynchronizationUtils.invokeAfterCompletion(TransactionSynchronizationUtils.java:168) [spring-tx-3.2.8.RELEASE.jar:3.2.8.RELEASE] 在 org.springframework.transaction.support.AbstractPlatformTransactionManager.invokeAfterCompletion(AbstractPlatformTransactionManager.java:994) [spring-tx-3.2.8.RELEASE.jar:3.2.8.RELEASE] 在 org.springframework.transaction.support.AbstractPlatformTransactionManager.triggerAfterCompletion(AbstractPlatformTransactionManager.java:969) [spring-tx-3.2.8.RELEASE.jar:3.2.8.RELEASE] 在 org.springframework.transaction.support.AbstractPlatformTransactionManager.processCommit(AbstractPlatformTransactionManager.java:800) [spring-tx-3.2.8.RELEASE.jar:3.2.8.RELEASE] 在 org.springframework.transaction.support.AbstractPlatformTransactionManager.commit(AbstractPlatformTransactionManager.java:724) [spring-tx-3.2.8.RELEASE.jar:3.2.8.RELEASE] 在 org.springframework.transaction.support.TransactionTemplate.execute(TransactionTemplate.java:148) [spring-tx-3.2.8.RELEASE.jar:3.2.8.RELEASE] 在 org.apache.camel.spring.spi.TransactionErrorHandler.doInTransactionTemplate(TransactionErrorHandler.java:174) [camel-spring-2.13.1.jar:2.13.1] 在 org.apache.camel.spring.spi.TransactionErrorHandler.processInTransaction(TransactionErrorHandler.java:134) [camel-spring-2.13.1.jar:2.13.1] 在 org.apache.camel.spring.spi.TransactionErrorHandler.process(TransactionErrorHandler.java:103) [camel-spring-2.13.1.jar:2.13.1] 在 org.apache.camel.spring.spi.TransactionErrorHandler.process(TransactionErrorHandler.java:112) [camel-spring-2.13.1.jar:2.13.1] 在 org.apache.camel.processor.CamelInternalProcessor.process(CamelInternalProcessor.java:191) [camel-core-2.13.1.jar:2.13.1] 在 org.apache.camel.processor.CamelInternalProcessor.process(CamelInternalProcessor.java:191) [camel-core-2.13.1.jar:2.13.1] 在 org.apache.camel.util.AsyncProcessorHelper.process(AsyncProcessorHelper.java:105) [camel-core-2.13.1.jar:2.13.1] 在 org.apache.camel.processor.DelegateAsyncProcessor.process(DelegateAsyncProcessor.java:87) [camel-core-2.13.1.jar:2.13.1] 在 org.apache.camel.component.cxf.CxfConsumer$1.syncInvoke(CxfConsumer.java:136) [camel-cxf-2.13.1.jar:2.13.1] 在 org.apache.camel.component.cxf.CxfConsumer$1.invoke(CxfConsumer.java:77) [camel-cxf-2.13.1.jar:2.13.1] 在 org.apache.cxf.interceptor.ServiceInvokerInterceptor$1.run(ServiceInvokerInterceptor.java:58) [cxf-api-2.7.10.jar:2.7.10] 在 java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471) [rt.jar:1.7.0_65] 在 java.util.concurrent.FutureTask.run(FutureTask.java:262) [rt.jar:1.7.0_65] 在 org.apache.cxf.workqueue.SynchronousExecutor.execute(SynchronousExecutor.java:37) [cxf-api-2.7.10.jar:2.7.10] 在 org.apache.cxf.interceptor.ServiceInvokerInterceptor.handleMessage(ServiceInvokerInterceptor.java:107) [cxf-api-2.7.10.jar:2.7.10] 在 org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:272) [cxf-api-2.7.10.jar:2.7.10] 在 org.apache.cxf.transport.ChainInitiationObserver.onMessage(ChainInitiationObserver.java:121) [cxf-api-2.7.10.jar:2.7.10] 在 org.apache.cxf.transport.http.AbstractHTTPDestination.invoke(AbstractHTTPDestination.java:239) [cxf-rt-transports-http-2.7.10.jar:2.7.10] 在 org.apache.cxf.transport.servlet.ServletController.invokeDestination(ServletController.java:248) [cxf-rt-transports-http-2.7.10.jar:2.7.10] 在 org.apache.cxf.transport.servlet.ServletController.invoke(ServletController.java:222) [cxf-rt-transports-http-2.7.10.jar:2.7.10] 在 org.apache.cxf.transport.servlet.ServletController.invoke(ServletController.java:153) [cxf-rt-transports-http-2.7.10.jar:2.7.10] 在 org.apache.cxf.transport.servlet.CXFNonSpringServlet.invoke(CXFNonSpringServlet.java:167) [cxf-rt-transports-http-2.7.10.jar:2.7.10] 在 org.apache.cxf.transport.servlet.AbstractHTTPServlet.handleRequest(AbstractHTTPServlet.java:286) [cxf-rt-transports-http-2.7.10.jar:2.7.10] 在 org.apache.cxf.transport.servlet.AbstractHTTPServlet.doPost(AbstractHTTPServlet.java:206) [cxf-rt-transports-http-2.7.10.jar:2.7.10] 在 javax.servlet.http.HttpServlet.service(HttpServlet.java:754) [jboss-servlet-api_3.0_spec-1.0.2.Final-redhat-1.jar:1.0.2.Final-redhat-1] 在 org.apache.cxf.transport.servlet.AbstractHTTPServlet.service(AbstractHTTPServlet.java:262) [cxf-rt-transports-http-2.7.10.jar:2.7.10] 在 org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:295) [jbossweb-7.2.2.Final-redhat-1.jar:7.2.2.Final-redhat-1] 在 org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:214) [jbossweb-7.2.2.Final-redhat-1.jar:7.2.2.Final-redhat-1] 在 org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:230) [jbossweb-7.2.2.Final-redhat-1.jar:7.2.2.Final-redhat-1] 在 org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:149) [jbossweb-7.2.2.Final-redhat-1.jar:7.2.2.Final-redhat-1] 在 org.jboss.as.web.security.SecurityContextAssociationValve.invoke(SecurityContextAssociationValve.java:169) [jboss-as-web-7.3.0.Final-redhat-14.jar:7.3.0.Final-redhat-14] 在 org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:145) [jbossweb-7.2.2.Final-redhat-1.jar:7.2.2.Final-redhat-1] 在 org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:97) [jbossweb-7.2.2.Final-redhat-1.jar:7.2.2.Final-redhat-1] 在 org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:102) [jbossweb-7.2.2.Final-redhat-1.jar:7.2.2.Final-redhat-1] 在 org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:336) [jbossweb-7.2.2.Final-redhat-1.jar:7.2.2.Final-redhat-1] 在 org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:856) [jbossweb-7.2.2.Final-redhat-1.jar:7.2.2.Final-redhat-1] 在 org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:653) [jbossweb-7.2.2.Final-redhat-1.jar:7.2.2.Final-redhat-1] 在 org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:920) [jbossweb-7.2.2.Final-redhat-1.jar:7.2.2.Final-redhat-1] 在 java.lang.Thread.run(Thread.java:745) [rt.jar:1.7.0_65]

【问题讨论】:

【参考方案1】:

该交易中发生了一些奇怪的事情。我知道的一件事是您的配置不太正确。

JmsConfig bean 需要有transacted="false" - 属性名称有点误导,因为它实际上意味着“在本地管理此事务”(它只是在底层 spring DefaultMessageListenerContainer 上设置 transactedSession 属性,请参阅this)

您还需要在 PooledConnectionFactory 上设置 transactionManager(我很确定您是否在此运行了调试器,此时 ActiveMQClient 上的 transactionManager 将为空)。

这是我目前正在运行的一个工作示例(EAP 6.2 和 AMQ 5.9)

<bean id="jmsXaConnectionFactory" class="org.apache.activemq.ActiveMQXAConnectionFactory"> 
    <property name="brokerURL" value="$amq.broker.url?jms.prefetchPolicy.all=1"/>
    <property name="userName" value="$amq.broker.connection.user" /> 
        <property name="password" value="$amq.broker.connection.password" /> 
    <property name="redeliveryPolicy"> 
    <bean class="org.apache.activemq.RedeliveryPolicy">
        <property name="maximumRedeliveries" value="0"/>
    </bean>
    </property>
</bean>

<bean id="jmsPoolConnectionFactory" class="org.apache.activemq.pool.XaPooledConnectionFactory">
        <property name="maxConnections" value="12" /> 
    <property name="connectionFactory" ref="jmsXaConnectionFactory" />
    <property name="transactionManager" ref="jtaTransactionManager" />
</bean>


<bean id="jtaTransactionManager" class="org.springframework.jndi.JndiObjectFactoryBean">
    <property name="jndiName" value="java:/TransactionManager" />
    <property name="lookupOnStartup" value="false" />
    <property name="cache" value="true" />
    <property name="proxyInterface" value="javax.transaction.TransactionManager" />
</bean>

<bean id="userTransaction" class="org.springframework.jndi.JndiObjectFactoryBean">
    <property name="jndiName" value="java:jboss/UserTransaction" />
    <property name="lookupOnStartup" value="false" />
    <property name="cache" value="true" />
    <property name="proxyInterface" value="javax.transaction.UserTransaction" />
</bean>

<bean name="transactionManager"
    class="org.springframework.transaction.jta.JtaTransactionManager">
    <property name="transactionManager" ref="jtaTransactionManager" />
    <property name="userTransaction" ref="userTransaction" />
</bean>

<bean id="jms" class="org.apache.camel.component.jms.JmsComponent">
    <property name="configuration" ref="jmsTxConfig" />
</bean>

<bean id="jmsTxConfig"
      class="org.apache.camel.component.jms.JmsConfiguration">
    <property name="connectionFactory" ref="jmsPoolConnectionFactory"/> 
    <property name="transactionManager" ref="transactionManager"/> 
    <property name="transacted" value="false"/>
    <property name="cacheLevelName" value="CACHE_CONNECTION"/>
</bean> 

【讨论】:

【参考方案2】:

我已经更改了如下配置,它解决了我面临的类似问题;

<bean id="jmsXAConnectionFactory"
        class="org.apache.activemq.ActiveMQXAConnectionFactory"
        p:brokerURL="tcp://$activemq.host:$activemq.port" />

<bean id="xa.connectionFactory" class="com.atomikos.jms.AtomikosConnectionFactoryBean"> <!-- connection pool -->
        <property name="uniqueResourceName" value="amq1" />
        <property name="xaConnectionFactory" ref="jmsXAConnectionFactory" />
</bean>

<bean id="jmsConfig"
        class="org.apache.camel.component.jms.JmsConfiguration"
        p:connectionFactory-ref="xa.connectionFactory"
        p:concurrentConsumers="$concurrent.consumers.default" 
        p:transactionManager-ref="transactionManager"           
        p:transacted="true"         
        p:cacheLevelName="CACHE_CONNECTION"/>
<!-- we are using JMS component from apache-camel -->
<bean id="jms"
    class="org.apache.activemq.camel.component.ActiveMQComponent"
    p:configuration-ref="jmsConfig" />
</beans>

我们正在使用 gradle 来构建项目; Atomikos 依赖项如下

compile "com.atomikos:transactions-jms:4.0.6"
compile "com.atomikos:transactions-jta:4.0.6"
compile "com.atomikos:transactions-jdbc:4.0.6"

【讨论】:

以上是关于javax.jms.TransactionInProgressException: 无法在 JBoss EAP 6.2 和 Active MQ 5.10.0 上的 XASession 中回滚()的主要内容,如果未能解决你的问题,请参考以下文章