3 Replies Latest reply on Apr 9, 2010 11:19 AM by leosbitto

    Proper way to commit / rollback using MessageListener

    timowe1980

      With a transactional session what is the proper way to commit / rollback the session in MessageListener.onMessage, or is it done automatically?

        • 1. Re: Proper way to commit / rollback using MessageListener
          timfox

          Session.commit() or Session.rollback()

           

          Same with core and JMS.

           

          Assuming you're talking abvout JMS here.

           

          Take a look at the Sun JMS Javadoc , JMS spec, or JMS tutorial for more info.

          • 2. Re: Proper way to commit / rollback using MessageListener
            leosbitto

            Timo Westkamper wrote:

             

            With a transactional session what is the proper way to commit / rollback the session in MessageListener.onMessage, or is it done automatically?

             

            Optionally you can use Connection.createSession(false, Session.CLIENT_ACKNOWLEDGE) and then call Message.acknowledge() in your MessageListener.onMessage code when you are done. This way when anything goes wrong, it is up to the JMS provider to redeliver the Message again in the future - I don't know how HornetQ behaves in this situation, though.

            • 3. Re: Proper way to commit / rollback using MessageListener
              leosbitto

              There is one major difference between the fully transactional JMS sessions and those created with the CLIENT_ACKNOWLEDGE option: with the fully transactional JMS sessions the messages sent by MessageProducers created by the same Session are in the transaction, too. As Tim suggested, study the JMS documentation, there is plenty of information available on the internet...