0 Replies Latest reply on Feb 13, 2013 10:41 AM by Konrad Konrad

    Spring JMSTemplate + Remote JMS server + XA transaction + HeuristicMixedException

    Konrad Konrad Newbie

      I have very similar case to https://community.jboss.org/thread/170548.

      I have two servers (Jboss 5.1). Server A connects and sends messages to Server B with JMS queue. As sever A also changes sth in DB, the whole operation should be managed by JTA transaction.

       

      My jms-ds.xml on Server B side is:

      <?xml version="1.0" encoding="UTF-8"?>

       

      <connection-factories>

         <mbean code="org.jboss.jms.jndi.JMSProviderLoader"

                name="jboss.messaging:service=JMSProviderLoader,name=JMSProvider">

            <attribute name="ProviderName">DefaultJMSProvider</attribute>

            <attribute name="ProviderAdapterClass">org.jboss.jms.jndi.JNDIProviderAdapter</attribute>

            <attribute name="FactoryRef">java:/XAConnectionFactory</attribute>

            <attribute name="QueueFactoryRef">java:/XAConnectionFactory</attribute>

            <attribute name="TopicFactoryRef">java:/XAConnectionFactory</attribute>

         </mbean>

       

         <!-- JMS XA Resource adapter, use this to get transacted JMS in beans -->

         <tx-connection-factory>

            <jndi-name>JmsXA</jndi-name>

            <xa-transaction/>

            <rar-name>jms-ra.rar</rar-name>

            <connection-definition>org.jboss.resource.adapter.jms.JmsConnectionFactory</connection-definition>

            <config-property name="SessionDefaultType" type="java.lang.String">javax.jms.Topic</config-property>

            <config-property name="JmsProviderAdapterJNDI" type="java.lang.String">java:/DefaultJMSProvider</config-property>

            <max-pool-size>20</max-pool-size>

            <security-domain-and-application>JmsXARealm</security-domain-and-application>

            <depends>jboss.messaging:service=ServerPeer</depends>

         </tx-connection-factory>

       

      </connection-factories>

       

      On Server A I have:

        

      public ConnectionFactory getConnectionFactory() {

              try {

                  JndiObjectFactoryBean factory = new JndiObjectFactoryBean();

                  factory.setCache(false);

                  factory.setLookupOnStartup(false);

                  factory.setJndiEnvironment(getEndpointTargetEnvironment());

                  factory.setProxyInterface(ConnectionFactory.class);

                  factory.setJndiName("XAConnectionFactory");

                  factory.afterPropertiesSet();

                  return (ConnectionFactory) factory.getObject();

              } catch (Exception ex) {

                  throw new RuntimeException(ex);

              }

          }

       

      JmsTemplate result = new JmsTemplate();

      result.setPubSubDomain(false);

      result.setDefaultDestinationName("queue/live");

      result.setSessionTransacted(true);

      result.setDestinationResolver(configurationService.getDestinationResolver());

      result.setConnectionFactory(getConnectionFactory());

      result.afterPropertiesSet();

      The whole operation is run under TransactionTemplate managed by PlatformTransactionManager.

       

      The problem is that the operation is not managed by JTA transaction because I use "factory.setJndiName("XAConnectionFactory")".

      After googling I found out that I have to use "JmsXA" instead of "XAConnectionFactory".

      But after changing it

      factory.setJndiName("java:/JmsXA");

      I get exceptions:

       

      2013-02-13 15:59:46,122 ERROR [s.messaging.util.ExceptionUtil] ConnectionEndpoint[z1-ruvvl4dh-1-t18tl4dh-sgoo69-110j3] sendTransaction [52-iaxvl4dh-1-t18tl4dh-sgoo69-110j3]

      javax.jms.JMSException: Failed to route Reference[22294816130940928]:RELIABLE to live

              at org.jboss.jms.server.endpoint.ServerConnectionEndpoint.sendMessage(ServerConnectionEndpoint.java:757)

              at org.jboss.jms.server.endpoint.ServerConnectionEndpoint.processTransaction(ServerConnectionEndpoint.java:815)

              at org.jboss.jms.server.endpoint.ServerConnectionEndpoint.sendTransaction(ServerConnectionEndpoint.java:497)

              at org.jboss.jms.server.endpoint.advised.ConnectionAdvised.org$jboss$jms$server$endpoint$advised$ConnectionAdvised$sendTransaction$aop(ConnectionAdvised.java:101)

              at org.jboss.jms.server.endpoint.advised.ConnectionAdvised$sendTransaction_N3268650789275322226.invokeTarget(ConnectionAdvised$sendTransaction_N3268650789275322226.java)

              at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:111)

              at org.jboss.jms.server.container.SecurityAspect.handleSendTransaction(SecurityAspect.java:195)

              at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

              at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)

              at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)

              at java.lang.reflect.Method.invoke(Method.java:597)

              at org.jboss.aop.advice.PerInstanceAdvice.invoke(PerInstanceAdvice.java:122)

              at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102)

              at org.jboss.jms.server.container.ServerLogInterceptor.invoke(ServerLogInterceptor.java:105)

              at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102)

              at org.jboss.jms.server.endpoint.advised.ConnectionAdvised.sendTransaction(ConnectionAdvised.java)

              at org.jboss.jms.wireformat.ConnectionSendTransactionRequest.serverInvoke(ConnectionSendTransactionRequest.java:82)

              at org.jboss.jms.server.remoting.JMSServerInvocationHandler.invoke(JMSServerInvocationHandler.java:143)

              at org.jboss.remoting.ServerInvoker.invoke(ServerInvoker.java:891)

              at org.jboss.remoting.transport.local.LocalClientInvoker.invoke(LocalClientInvoker.java:106)

              at org.jboss.remoting.Client.invoke(Client.java:1724)

              at org.jboss.remoting.Client.invoke(Client.java:629)

              at org.jboss.remoting.Client.invoke(Client.java:617)

              at org.jboss.jms.client.delegate.DelegateSupport.doInvoke(DelegateSupport.java:189)

              at org.jboss.jms.client.delegate.DelegateSupport.doInvoke(DelegateSupport.java:160)

              at org.jboss.jms.client.delegate.ClientConnectionDelegate.org$jboss$jms$client$delegate$ClientConnectionDelegate$sendTransaction$aop(ClientConnectionDelegate.java:221)

              at org.jboss.jms.client.delegate.ClientConnectionDelegate$sendTransaction_N3268650789275322226.invokeTarget(ClientConnectionDelegate$sendTransaction_N3268650789275322226.java)

              at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:111)

              at org.jboss.jms.client.container.FailoverValveInterceptor.invoke(FailoverValveInterceptor.java:92)

              at org.jboss.aop.advice.PerInstanceInterceptor.invoke(PerInstanceInterceptor.java:86)

              at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102)

              at org.jboss.jms.client.container.ClosedInterceptor.invoke(ClosedInterceptor.java:170)

              at org.jboss.aop.advice.PerInstanceInterceptor.invoke(PerInstanceInterceptor.java:86)

              at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102)

              at org.jboss.jms.client.delegate.ClientConnectionDelegate.sendTransaction(ClientConnectionDelegate.java)

              at org.jboss.jms.tx.ResourceManager.sendTransactionXA(ResourceManager.java:667)

              at org.jboss.jms.tx.ResourceManager.prepare(ResourceManager.java:337)

              at org.jboss.jms.tx.MessagingXAResource.prepare(MessagingXAResource.java:241)

              at org.jboss.resource.adapter.jms.JmsXAResource.prepare(JmsXAResource.java:82)

              at com.arjuna.ats.internal.jta.resources.arjunacore.XAResourceRecord.topLevelPrepare(XAResourceRecord.java:264)

              at com.arjuna.ats.arjuna.coordinator.BasicAction.doPrepare(BasicAction.java:2919)

              at com.arjuna.ats.arjuna.coordinator.BasicAction.doPrepare(BasicAction.java:2876)

              at com.arjuna.ats.arjuna.coordinator.BasicAction.prepare(BasicAction.java:2419)

              at com.arjuna.ats.arjuna.coordinator.BasicAction.End(BasicAction.java:1790)

              at com.arjuna.ats.arjuna.coordinator.TwoPhaseCoordinator.end(TwoPhaseCoordinator.java:94)

              at com.arjuna.ats.arjuna.AtomicAction.commit(AtomicAction.java:177)

              at com.arjuna.ats.internal.jta.transaction.arjunacore.TransactionImple.commitAndDisassociate(TransactionImple.java:1423)

              at com.arjuna.ats.internal.jta.transaction.arjunacore.BaseTransaction.commit(BaseTransaction.java:137)

              at com.arjuna.ats.jbossatx.BaseTransactionManagerDelegate.commit(BaseTransactionManagerDelegate.java:75)

              at org.jboss.tm.usertx.client.ServerVMClientUserTransaction.commit(ServerVMClientUserTransaction.java:162)

              at org.springframework.transaction.jta.JtaTransactionManager.doCommit(JtaTransactionManager.java:1010)

              at org.springframework.transaction.support.AbstractPlatformTransactionManager.processCommit(AbstractPlatformTransactionManager.java:754)

              at org.springframework.transaction.support.AbstractPlatformTransactionManager.commit(AbstractPlatformTransactionManager.java:723)

              at org.springframework.transaction.support.TransactionTemplate.execute(TransactionTemplate.java:147)

      2013-02-13 15:59:46,304 WARN  [una.ats.jta.logging.loggerI18N] [com.arjuna.ats.internal.jta.resources.arjunacore.preparefailed] [com.arjuna.ats.internal.jta.resources.arjunacore.preparefailed] XAResourceRecord.prepare - prepare failed with exception XAException.XA_RETRY

      2013-02-13 15:59:46,304 WARN  [s.arjuna.logging.arjLoggerI18N] [com.arjuna.ats.arjuna.coordinator.BasicAction_50] - Prepare phase of action 7f000101:d6ea:511baa07:eb received heuristic decision: TwoPhaseOutcome.HEURISTIC_HAZARD

      2013-02-13 15:59:46,304 WARN  [s.arjuna.logging.arjLoggerI18N] [com.arjuna.ats.arjuna.coordinator.BasicAction_36] - BasicAction.End() - prepare phase of action-id 7f000101:d6ea:511baa07:eb failed.

      2013-02-13 15:59:46,304 WARN  [s.arjuna.logging.arjLoggerI18N] [com.arjuna.ats.arjuna.coordinator.BasicAction_37] - Received heuristic: TwoPhaseOutcome.HEURISTIC_HAZARD .

      2013-02-13 15:59:46,304 WARN  [s.arjuna.logging.arjLoggerI18N] [com.arjuna.ats.arjuna.coordinator.BasicAction_38] - Action Aborting

      org.springframework.transaction.HeuristicCompletionException: Heuristic completion: outcome state is mixed; nested exception is javax.transaction.HeuristicMixedException

              at org.springframework.transaction.jta.JtaTransactionManager.doCommit(JtaTransactionManager.java:1017)

              at org.springframework.transaction.support.AbstractPlatformTransactionManager.processCommit(AbstractPlatformTransactionManager.java:754)

              at org.springframework.transaction.support.AbstractPlatformTransactionManager.commit(AbstractPlatformTransactionManager.java:723)

              at org.springframework.transaction.support.TransactionTemplate.execute(TransactionTemplate.java:147)

      Caused by: javax.transaction.HeuristicMixedException

              at com.arjuna.ats.internal.jta.transaction.arjunacore.TransactionImple.commitAndDisassociate(TransactionImple.java:1431)

              at com.arjuna.ats.internal.jta.transaction.arjunacore.BaseTransaction.commit(BaseTransaction.java:137)

              at com.arjuna.ats.jbossatx.BaseTransactionManagerDelegate.commit(BaseTransactionManagerDelegate.java:75)

              at org.jboss.tm.usertx.client.ServerVMClientUserTransaction.commit(ServerVMClientUserTransaction.java:162)

              at org.springframework.transaction.jta.JtaTransactionManager.doCommit(JtaTransactionManager.java:1010)

              ... 16 more

       

      What I can do?

      Should I differently configure JmsXA connection factory ?

       

      Thanks in advance for any suggestions.