RABBITMQ Message Queuing: ACK mechanism

Source: Internet
Author: User
Tags ack rabbitmq
RABBITMQ Message Queuing: ACK mechanism

Each consumer may take some time to process the received data. If in this process, consumer error, abnormal exit, and the data has not been processed, so unfortunately, this data is lost.

Because we confirm it in a no-ack way, that is, every time the consumer is received, and whether or not it is done, RABBITMQ server immediately marks the message as complete and then deletes it from the queue.

if a consumer exception exits, the data it processes can be processed by another consumer so that the data will not be lost in this case (note that this is the case).

In order to ensure the data is not lost, RABBITMQ supports the message recognition mechanism, namely acknowledgments. In order to ensure that data can be handled correctly and not only received by consumer, we cannot use No-ack. Instead, send an ack after processing the data.

The ACK sent after processing the data is to tell RABBITMQ that the data has been received and processed, and that RABBITMQ can safely delete it.

if consumer exits but does not send an ACK, then RABBITMQ sends the message to the next consumer. This guarantees that the data will not be lost if the consumer exits unexpectedly.

The timeout mechanism is not used here. RABBITMQ only through a consumer connection interrupt to confirm that the message was not handled correctly.

That is to say,Rabbitmq gave consumer enough time to do data processing .

So even if you interrupt Recieve.cs through CTR-C, the message will not be lost and it will be distributed to the next consumer.

If you forget the ACK, then the consequences are serious . When consumer exits, the message is redistributed. The RABBITMQ will then occupy more and more memory, and the "Memory leak" is fatal because the RABBITMQ is running for a long time.

To debug this error, you can print un-acked Messages with the following command.

If the connection is not disconnected apply to notify the server to send the message back:

You can use Channel.nack (message) to let messages that are not passed into message queues again.

if (body== ' Hello world3! ') {Chnl.nack (msg);

This will allow the message to enter the queue again without restarting the service.

}else{

Console.log (' ack ');

Chnl.ack (msg);

}

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.