4 Replies Latest reply on Nov 19, 2007 2:25 PM by jay.howell

    How to enlist JMS in stateless session bean container manage

    davidcj

      I am currently working with JBoss 3.0.8. My application has a stateless session EJB that performs a DB update and sends a JMS message. I want the DB update and JMS message send to be managed in the same JTA transaction context. The EJB is using a container managed transaction.

      The J2EE 1.3 spec isn't very clear about how this works with managed transactions, but according to the Sun tutorial at http://java.sun.com/products/jms/tutorial/1_3_1-fcs/doc/j2eeapp2.html, the container should manage the JMS transaction if the session is creating using this call:

      session = connection.createQueueSession(true, 0);

      The call to session.commit() should be unnecessary since the container manages the transaction.

      However, when I try this from JBoss it appears the JMS transaction is never committed and therfore the message is never sent. If I instead use connection.createQueueSession(false, QueueSession.AUTO_ACKNOWLEDGE) then I run into the problem where the JMS message is immediately commited independent of the session EJB transaction. Depending on timing the message receiver may attempt to process the message before the session EJB's transaction has committed, which is a problem since the receiver needs that data.

      Can anyone provide any hints on how to get JBoss to coordinate the JMS transaction as part of the session EJB transaction when sending a message from a session EJB?

      Thanks,
      David Johnson
      StorePerform Technologies, Inc.