3 Replies Latest reply on May 26, 2010 11:45 PM by Clebert Suconic

    How do you "unacknowledge" a message?

    Keith Irwin Newbie

      Using ClientConsumer (and Core API in general), I have a MessageHandler something like:

       

      public void onMessage(ClientMessage msg) {
         try {
             doSomething(msg);
             msg.acknowledge();
         }
      
         catch (Exception e) {
            msg.pleaseRedeliverThisLaterPrettyPlease();
         }
      

       

      My question is, how to I set things up so that HornetQ will indeed re-deliver that message? Is there something I need to do (other than msg.setDurable() on send) to make sure the message gets retried? How long does HornetQ wait before assuming the message was not properly delivered?

       

      I've scanned the docs, but this doesn't seem to be directly addressed.

       

      Keith

        • 1. Re: How do you "unacknowledge" a message?
          Keith Irwin Newbie

          Interesting.

           

          If I send 30 durable messages to a consumer (using the above), and I throw five exceptions (out of the thirty), I end up with 35 messages.

           

          However, when I restart my consumer by killing the JVM and starting it up again, I get the remaining 5 messages.

           

          How come they don't get resent "later"?

           

          How to you set the time out for acknowledgement?  (I'm using blockOnAcknowledge(true).)

           

          Keith

          • 2. Re: How do you "unacknowledge" a message?
            Keith Irwin Newbie

            Okay, maybe this solves it?

             

              try {
                 doSomething();
                 msg.acknowledge();
              }
            
              catch (Something s) {
                 session.rollback();
              }
            

            That seems to work, actually.

            • 3. Re: How do you "unacknowledge" a message?
              Clebert Suconic Master

              When you create the core session, you have two parameters you choose to create the session:

               

               

              createSession(boolean autoCommitSends, boolean autoCommitAcks)

               

               

              the auto-commit-ack means... they will get auto-committed...

               

              if you use false.. you have to explicity call session.commit or session.rollback();

               

               

               

              for autoCommitACKs there's also a third parameter you may choose:

               

               

              createSession(boolean autoCommitSends, boolean autoCommitAcks, int ackBatchSize)

               

               

              If you want ACKs to always be taken immediately, you have to set ackBatchSize = 0;

               

               

              If you don't call ACK.. closing the consumer will also place the message back to the queue.