2 Replies Latest reply on Mar 20, 2011 3:47 AM by Andy Taylor

    QueueQuery seems to return stale message count

    Richard Lawson Newbie

      Background - I am running an embedded HornetQ using in InVM transport.

       

      I have various threads that are dumping messages on a queue.

       

      This queue has some MessageHandlers registered that pick up messages and stick them in the database.

       

      Problem:

      1. dump 1000 messages onto queue

      2. MessageHandlers begin to get Messages in their onMessage method

      3. When I do a QueueQuery I still see 1000 messages even though messages are being consumed and ack'd

       

      If I stop and start the embedded instance then I see the correct count at startup (ie, some value less than 1000)

       

      Here is my code for getting a QueueCount

       

          public int getQCount(String queueName) throws Exception {

              log.debug("Get queue count");

       

              ClientSession session = sf.createSession(false, false, false);

       

              try {

                  QueueQuery qq = session.queueQuery(SimpleString.toSimpleString(queueName));

                  int count = qq.getMessageCount();

              log.debug("Get queue count: " + count);

                  return count;

       

              } finally {

                  closeSession(session);

              }

          }

       

      Thanks for any guidance,

      Rick

        • 1. QueueQuery seems to return stale message count
          Richard Lawson Newbie

          Ok I found the issue but I'm not sure I understand why.

           

          My messages sent were using a session created via createTransactionalClientSession

           

          My messages being consumed were using a  session created with createSession(false, false) and I was ack'ing the message in the MessageHandler.

           

          I switched the MessageHandler to using a session created via createTransactionalClientSession and added a commit to the MessageHandler and now the message count updates fine.

           

          Now the wierd thing is before even though message counts were not updating the messages were being taken off the queue

          • 2. QueueQuery seems to return stale message count
            Andy Taylor Master

            with a transacted session acks are only committed once the session.commit() is called. Alternatively at thius point you could have rolled back the session and the messages would have been put back on the queue