1 2 3 Previous Next 31 Replies Latest reply on Jan 16, 2012 3:22 AM by markusdöring

    JMS transacted messages not working?




      I'm using JBoss AS 7.1.0.CR1, but had this issue on JBoss AS 7.0.1 (Full Profile).


      I have the following Stateless Session Bean:

      public class TestBean implements TestService {
           @Resource(mappedName = "java:/ConnectionFactory")
           private ConnectionFactory connectionFactory;
           @Resource(name = "TestQueue", mappedName = "java:jboss/queue/TestQueue")
           private Queue testQueue;
           public void sendMessage(Serializable message) {
                Connection connection;
                Session session;
                try {
                     connection = connectionFactory.createConnection();
                     session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
                     MessageProducer producer = session.createProducer(testQueue);
                     ObjectMessage message = session.createObjectMessage(message);
                } catch (Throwable thr) {
                     Logger.getLogger(TestBean.class).error("Error sending message.", thr);
                } finally {
                     if(session != null) {
                     if(connection != null) {


      And the following Message Driven Bean:


           activationConfig = {
                @ActivationConfigProperty(propertyName="acknowledgeMode", propertyValue="auto_acknowledge"),
                @ActivationConfigProperty(propertyName="destinationType", propertyValue="javax.jms.Queue"),
                @ActivationConfigProperty(propertyName="destination", propertyValue="queue/TestQueue"),
                @ActivationConfigProperty(propertyName="maxSession", propertyValue="1")
      public class TestMDB implements MessageListener {
           public void onMessage() {


      All of this is working perfectly, but i want the message to be added to the queue after transaction commit.

      So i change the following lines:


                     session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
                     session = connection.createSession(true, Session.SESSION_TRANSACTED);
                @ActivationConfigProperty(propertyName="acknowledgeMode", propertyValue="auto_acknowledge"),
                @ActivationConfigProperty(propertyName="acknowledgeMode", propertyValue="session_transacted"),

      (worked like this on JBoss 4.2.2)


      after this, the message is never commited to the queue and so the MDB never recives something.

      Anything I'm doing wrong?

      Or is this still a bug in CR1?

      Can't find anything on JIRA.




        • 1. Re: JMS transacted messages not working?

          §13.3.5 of the EJB 3.1 spec says:

          Because the container manages the transactional enlistment of JMS sessions on behalf of a bean, the parameters of the createSession(boolean transacted, int acknowledgeMode), createQueueSession(boolean transacted, int acknowledgeMode) and createTopicSession(boolean transacted, int acknowledgeMode) methods are ignored. It is recommended that the Bean Provider specify that a session is transacted, but provide 0 for the value of the acknowledgment mode.


          Session.SESSION_TRANSACTED is a value that may be returned from Session.getAcknowledegMode(). It's not a value that you can set.


          But the container would normally do what you want, because the message will not be delivered to the queue until your transaction commits anyway.

          • 2. Re: JMS transacted messages not working?

            Thanks for answer, but if i use my first code sample, the message is published immediatly to the queue.

            I have tested it with inserting:

            Logger.getLogger(TestBean.class).debug("Publish message");





            Logger.getLogger(TestBean.class).debug("Message delayed");




            Log result is:

            Publish message



            Message delay


            So the onMessage() is called before the sendMessage() transaction is commited.

            Also tested it with writing / reading database and the database changes in sendMessage() are not written to database when onMessage() is called.

            • 3. Re: JMS transacted messages not working?

              If I remember right you should set

              session = connection.createSession(true, Session.AUTO_ACKNOWLEDGE);

              to bind the sender to the transaction.


              And the ActivationConfig should be auto_acknowledge for the receiver will remove the message from the queue if the method return without Exception.

              • 4. Re: JMS transacted messages not working?

                I haven't tried it myself on JBossAS 7, but if it's doing this in 7.1 then it's broken and you should report a bug.


                JMS is not part of the web profile so I wouldn't be surprised if it did not work in 7.0.x.

                • 5. Re: JMS transacted messages not working?

                  I've done some more testing, and as far as I can see, it's behave like this:


                  If I use:

                  session = connection.createSession(false, ...)

                  the message is send immediatly and no (container managed) transaction handling is involved at all.


                  If I use:

                  session = connection.createSession(true, ...)

                  the message is never added to queue at all. Looks like me as if the producer wait's for some transaction commit, but he don't get the notification after commit (transaction is commited: database changes are written).


                  the later parameter (Session.AUTO_ACKNOLEDGE, ect.) don't make a diffrence at this point.

                  Behavior is the same on JBoss 7.0.1 (Full Profile) and JBoss 7.1.CR1


                  Anything else I could check before opening a JIRA?

                  Maybe something in persistance.xml (don't think so, it's nothing JMS related in there) or in JBoss standalone.xml I could check?




                  • 6. Re: JMS transacted messages not working?

                    Are you using XA Datasources for your database operations?


                    JMS is a transactional resource. Typically you need to use XA when mixing different types of resources in a transaction.


                    JBoss should really be complaining loudly if this is not the case anyway, rather than behaving as above.


                    Are you using container managed transactions or are you handling transaction management yourself?

                    • 7. Re: JMS transacted messages not working?

                      I'm using container managed transactions and "normal" datasource at ther moment.

                      JBoss is not complaining anything.


                      Will test with XA Datasource later.

                      • 8. Re: JMS transacted messages not working?

                        Nothing changed qhen using a XA Datasource, same behavior.

                        • 9. Re: JMS transacted messages not working?

                          This might seem like a dumb question, but are you running JBoss 7.1 with



                          • 10. Re: JMS transacted messages not working?

                            Someone told me once there are no dumb questions, and I think he might be right.


                            No, I'm not using the standalone-full.xml, I have changed my standalone.xml using the standalone-full.xml as templates and changed some thing (e.g. changed persistence-enabled to true for messaging configuration).


                            I've done an diff between the standalone-full.xml and the standalone.xml (once again) and can't see anything that might cause the problem.

                            • 11. Re: JMS transacted messages not working?

                              Could you please create a JIRA and attach a sample application which reproduces this issue? I think I had seen one other user mention a similar issue.

                              • 12. Re: JMS transacted messages not working?

                                OK, I will do this tomorrow.

                                • 13. Re: JMS transacted messages not working?

                                  I have subitted a jira:


                                  and added a simple EAR to reproduce the issue.


                                  I could reproduce it using JBoss 7.1.0.CR1 with standalone-full.xml without any changes.


                                  BTW if someone is interessted:

                                  I can't log in to JIRA with this account even after multiple password changes.

                                  Forum does work without problems.

                                  I had to create a new account, that worked without problems.

                                  I have an ö in my username, so this might cause the problem.

                                  • 14. Re: JMS transacted messages not working?

                                    I used connection factory java:/JmsXa to send message after transaction commit in jboss 6. Not sure is this works in 7.

                                    1 2 3 Previous Next