4 Replies Latest reply on Aug 31, 2005 5:05 PM by Adrian Brock

    Message acknowledgments in MDBs

    Tim Fox Master

      I have some confusion about to handle acknowledgment of the received message in an MDB, and was hoping one of you JMS gurus may be able to help....

      I have an MDB using CMT.

      Looking at the code in org.jboss.jms.asf.StdServerSession, a transaction is started, the onMessage method is executed, then the tx is committed/rolledback.

      After the onMessage method has executed the ServerSession.run() method returns and control returns to Session.run() where the jms call to acknowledge the message can be made.

      Unfortunately the tx that the onMessage method was run in no longer active.

      So how can we send the ack in the same tx context as the onMessage method runs in, if that tx is finished before the onMessage method returns?

      The EJB 2.0 spec (15.4.8) says:


      .... If the message-driven bean uses container
      managed transaction demarcation, message acknowledgment is handled automatically as a part of the
      transaction commit. .....


      Any ideas? I'm obviously missing something here but would appreciate a pointer.



        • 1. Re: Message acknowledgments in MDBs
          Adrian Brock Master

          CMT => transacted session => commit() => JMSXAResource.commit() => transacted ack

          I'd suggest you forget about MDBs.
          The MDB is implemented by the application server as is the session pool.
          Your responsibility is to implement the ConnectionConsumer/Session.run() and the session level message listener.

          If you really want to see how it works, enable TRACE logging as described in the user forum
          and follow through an MDB message delivery from jbossmq.

          • 2. Re: Message acknowledgments in MDBs
            Ovidiu Feodorov Master

             

            If you really want to see how it works, enable TRACE logging as described in the user forum
            and follow through an MDB message delivery from jbossmq.


            I told ya Tim. You asked for it! :)

            • 3. Re: Message acknowledgments in MDBs
              Tim Fox Master

              Hi Adrian-

              The ConnectionConsumer, Session.run and Session message listener get/set are implemented.

              The problem I have is this:

              1. AS starts tx
              2. AS calls sessionListener.onMessage for the mdb. Call returns successfully
              3. AS commits tx
              4. Return controls to Session.run()
              5. Message has been delivered ok so we add an ack to the tx.
              6. Ooops! Exception occurs because tx was committed at step 3. There's no tx to add the ack to.

              I.e. currently we are adding the ack to the transaction *after* onmessage has been called, but by then there is no active tx for the session.

              I think I see the problem here: We should be adding the ack to the tx before onMessage is called. (This seems to be what JBossMQ does). And then when the AS starts a tx and enlists the session in it, any local work done in the session gets converted into work in the global tx.

              Does that sound right?




              • 4. Re: Message acknowledgments in MDBs
                Adrian Brock Master

                I should add a link to this painfully long dicussion
                http://www.mail-archive.com/jboss-user@lists.sourceforge.net/msg30737.html
                and countless others to the FAQ.

                Of course, the explanation in the spec (as far it goes) and the JBoss code
                is better than any attempt I can make to "dumb it down".


                Does that sound right?


                JBossMQ does it that way, so suck it and see....