Saturday 19 September 2015

RabbitMQ: Message Acknowledgement

Whatever the code I explained in previous post is not robust, means once RabbitMQ delivers a message to the receiver and immediately removes it from memory. Suppose if any receiver terminated abnormally, you will lose information it was just processing. We'll also lose all the messages that were dispatched to this particular receiver (consumer) but were not yet handled.

For robust transferring of message, RabbitMQ supports message acknowledgments. In robust communication, RabbitMQ delete message, once it got positive acknowledgement from consumer. 

If a consumer dies without sending an ack, RabbitMQ will understand that a message wasn't processed fully and will redeliver it to another consumer.

Message acknowledgements are turned on by default. In my previous posts, I turned them off by explicitly setting autoAck flag to true.

channel.basicConsume(QUEUE_NAME, true, consumer);

If you call above function like below, it enables message acknowledgement by default.

channel.basicConsume(QUEUE_NAME, consumer);

Use following command to know about messages ready, messages unacknowledged in the queue.

rabbitmqctl list_queues name messages_ready messages_unacknowledged



Prevoius                                                 Next                                                 Home

No comments:

Post a Comment