3 Replies Latest reply on Oct 8, 2002 11:52 AM by frito

    MDB with Oracle and XA transactions not working because of X

    frito

      Hello!

      I have set up a MDB (PersistenceManager is JDBC2 with Oracle DB) with CMT. I am doing the following work:
      - MDB receives Message from Queue A
      - the instance of my MDB will do some work in the onMessage method (could be transactional, too)
      - the MDB sends a message to another queue

      AFAIK, since no RuntimeException is thrown in the onMessage() method and setRollbackOnly() was not invoked, the received message should be acknowledged, my work should be commited and the message should be sent when the TransactionManager commits the XA transaction covering these actions.

      But all i get is this exception (after onMessage was invoked without errors):
      [pre]
      2002-10-08 12:58:32,912 52635 WARN [org.jboss.tm.TxCapsule] (Thread Pool Worker-0:) XAException: tx=XidImpl [FormatId=257, GlobalId=edv-ws7722-bz//26, BranchQual=] errorCode=XAER_RMERR
      javax.transaction.xa.XAException
      at org.jboss.mq.SpyXAResource.prepare(SpyXAResource.java:173)
      at org.jboss.tm.TxCapsule.prepareResources(TxCapsule.java:1619)
      at org.jboss.tm.TxCapsule.commit(TxCapsule.java:402)
      at org.jboss.tm.TransactionImpl.commit(TransactionImpl.java:73)
      at org.jboss.jms.asf.StdServerSession.onMessage(StdServerSession.java:319)
      at org.jboss.mq.SpyMessageConsumer.sessionConsumerProcessMessage(SpyMessageConsumer.java:603)
      at org.jboss.mq.SpyMessageConsumer.addMessage(SpyMessageConsumer.java:417)
      at org.jboss.mq.SpySession.run(SpySession.java:259)
      at org.jboss.jms.asf.StdServerSession.run(StdServerSession.java:177)
      at EDU.oswego.cs.dl.util.concurrent.PooledExecutor$Worker.run(PooledExecutor.java:642)
      at java.lang.Thread.run(Thread.java:536)
      [/pre]
      Due to this exception a RollbackException is thrown, rolling back everything. The transaction status was still active when beforeCompletion() was invoked. I can see the (not acknowledged) message in my DB (so this should be set up correctly) and the client who sent the message is waiting for the answering message (the client resides outside JBoss).

      To show what I have done, I will post some code and configuration snippets:
      I deployed ORACLE-XA-SERVICE.XML and ORACLE_JBOSSMQ-SERVICE.XML (my oracle XA datasource is working with a SFSB and a SLSB)

      ejb-jar.xml
      [pre]<ejb-jar>
      <display-name>StepAMDB</display-name>
      <enterprise-beans>
      <message-driven>
      <ejb-name>StepAMDB</ejb-name>
      <ejb-class>myPackage.StepAMDB</ejb-class>
      <message-selector>filter = 'StepAMDB'</message-selector>
      <transaction-type>Container</transaction-type>
      <resource-ref>
      <res-ref-name>MyConnection</res-ref-name>
      <res-type>javax.jms.QueueConnectionFactory</res-type>
      <res-auth>Container</res-auth>
      </resource-ref>
      <resource-ref>
      <res-ref-name>MyQueue</res-ref-name>
      <res-type>javax.jms.Queue</res-type>
      <res-auth>Container</res-auth>
      </resource-ref>
      <acknowledge-mode>Auto-acknowledge</acknowledge-mode>
      <message-driven-destination>
      <destination-type>javax.jms.Queue</destination-type>
      </message-driven-destination>
      </message-driven>
      </enterprise-beans>
      <assembly-descriptor>
      <security-role>
      <role-name>everyone</role-name>
      </security-role>
      <container-transaction>

      <ejb-name>StepAMDB</ejb-name>
      <method-name>onMessage</method-name>

      <trans-attribute>Required</trans-attribute>
      </container-transaction>
      </assembly-descriptor>
      </ejb-jar>[/pre]

      jboss.xml
      [pre]
      <resource-managers>
      <resource-manager>
      <res-name>MyConnection</res-name>
      <res-jndi-name>java:/JmsXA</res-jndi-name>
      </resource-manager>
      <resource-manager>
      <res-name>MyQueue</res-name>
      <res-jndi-name>queue/MySendingQueue</res-jndi-name>
      </resource-manager>
      </resource-managers>

      <enterprise-beans>
      <message-driven>
      <ejb-name>StepAMDB</ejb-name>
      <configuration-name>My Message Driven Bean</configuration-name>
      <destination-jndi-name>queue/MyListeningQueue</destination-jndi-name>
      </message-driven>
      </enterprise-beans>
      [/pre]

      I even tried to add the queue the MDB listens on as a managed resource, setting <destination-jndi-name> to the appropriate value. The result was that the MDB didn't process the message.
      The configuration 'My Message Driven Bean' is the standard configuration with an extra interceptor.

      from ejbCreate in my MDB
      [pre]InitialContext jndiContext = new InitialContext();
      QueueConnectionFactory queueConnectionFactory =
      (QueueConnectionFactory)jndiContext.lookup("java:comp/env/MyConnection");
      Queue queue = (Queue)jndiContext.lookup("java:comp/env/MyQueue");
      queueConnection = queueConnectionFactory.createQueueConnection();
      queueSession = queueConnection.createQueueSession(true, 0);
      queueSender = queueSession.createSender(queue);
      [/pre]
      Can anybody tell me what is wrong with my code / configuration? Or is this a bug?

      Greetings,
      Frito