2 Replies Latest reply on Jun 2, 2015 10:52 AM by Jesus Gabriel y Galan

    message.getDeliveryCount is always 1

    Jesus Gabriel y Galan Newbie

      Hi,

       

      I am having a problem in which I try to check if a message is being redelivered and if it is, what number of times it has been redelivered. I am using a standalone HornetQ (2.4.Final) and the core API. The code is:

       

      session = sf.createSession();

      consumer = session.createConsumer("queue");

      session.start();

      while (true) {

           ClientMessage message = consumer.receive();

           System.out.println(message.getDeliveryCount());

           session.rollback();

      }

       

      This is a test, obviously in the production code I only rollback in specific error cases, otherwise I message.acknowledge().

       

      The redelivery works fine, so my loop keeps getting the same message time and time again, but the getDeliveryCount() always returns 1. I have tried many combinations of transacted and non-transacted sessions, acknowledging and committing the session, etc, but the result is always the same.

       

      Am I missing something to make this work?

       

      Thanks,

       

      Jesus.

        • 1. Re: message.getDeliveryCount is always 1
          Justin Bertram Master

          From what I can tell this is working as expected.  You need to acknowledge the message first and then rollback or the message won't be considered "delivered" in the first place.

          • 2. Re: message.getDeliveryCount is always 1
            Jesus Gabriel y Galan Newbie

            Thanks Justin.

             

            Looks like I didn't test a specific combination: creating the session without autoCommitAcks and acknowledging before either commiting and rollbacking. It is confusing for me, since with autocommitAcks and no ack, the session.rollback() produces that the message is sent again. For the record, this works:

             

            session = sf.createSession(true, false);

            consumer = session.createConsumer("queue");

            while (true) {

                ClientMessage message = consumer.receive();

                message.acknowledge();

                if (processMessageOK(message)) {

                    session.commit();

                } else {

                    session.rollback();

                }

            }

             

            Thanks,

             

            Jesus.