RabbitMQ ACK Message Acknowledgement mechanism

Source: Internet
Author: User
Tags ack rabbitmq

Added on the consumer MQ configuration file, the configuration key code is ACKNOWLEDEG = "Manual"
, meaning that the consumer's ACK is manually (at this point the queue has been bound to the producer's exchange through a routekey)

<rabbit:listener-container connection-factory= "connectionfactory" acknowledge= "Manual" > <rabbit:listener Queues= "queue_xxx" ref= "Mqconsumer"/> <rabbit:listener queues= "queue_xxx" ref= "MqConsumer2"/> </rabbit :listener-container>

Create a new class Mqconsumer, implement the interface Channelawaremessagelistener, implement the OnMessage method, and do not need to specify a method.


Key points after implementing the Channelawaremessagelistener OnMessage method, there are 2 parameters.

One is the message (the messaging entity), and the channel is the current one.

Many places are not clear how to go to manual ack, in fact, the manual ack is in the current channel inside the call Basicask method, and incoming current message tagid on it.

Note that if you throw an exception or unack (and Requeue is true), the message will always be re-queued, accidentally xxxxx a lot of messages repeatedly.


The identity of the message, false only confirms that the current message was received, and true confirms that all consumer received the message (normal consumption)

Channel.basicack (Message.getmessageproperties (). Getdeliverytag (), false);


ACK returns false and goes back to the queue, which is clearly explained in the API (local exception)

Channel.basicnack (Message.getmessageproperties (). Getdeliverytag (), false, true);


Reject Message

Channel.basicreject (Message.getmessageproperties (). Getdeliverytag (), true);

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.