This article is a mirror article of machine translation, please click here to jump to the original article.

View: 26359|Reply: 2

An in-depth analysis of the mechanism of RabbitMQ message response

[Copy link]
Posted on 3/30/2018 10:42:59 AM | | | |


When the consumer receives the message and the processing task is completed, it will send an ack with this message identifier to tell the server that the message has been received and the processing is complete. RabbitMQ waits until the link of the consumer processing a message is lost before determining that the message was not processed correctly, so RabbitMQ retransmits the message.
Message acknowledgment is turned off by default. There is a noAck parameter when initializing Consumer,If set to true, the consumer will return an ack as soon as it receives the message


Generally speaking, the commonly used scenario noack is generally set to true, but for projects with high risk requirements, such as payment. For every message, we need to ensure its integrity and correctness. After obtaining the message, you need to confirm that the correct business logic is executed, and then actively return an ack to the server. You can view the messages in the queue through the rabbitmqctl list_queues name message_rady message_unacknowleded command, or through the background management interface.

If noAck is set to false, the client needs to actively send an ack to the server, and if the client does not confirm the message, the following situation will occur:



As long as the program is still running, these 10 messages remain unacked and cannot be redelivered by RabbitMQ. What's even more powerful is thatRabbitMQ message consumption does not have a timeout mechanism, that is, if the program is not restarted, the message will always be in the Unacked state. Don't forget these unacked state messages when working on operations events.

Ready

Messages with this status exist in the queue to be processed.

Unacknowledged

A message in this status indicates that it is already being processed but not acknowledged.




When the program is closed (as long as the Consumer is closed), these 10 messages will return to the Ready state.


Confirmation message

What if the client sends an ack to the server? That is, confirm the receipt of the message? The code is as follows:


When the second parameter of the BasicAck method, multiple, is set to false, it means that RabbitMQ is notified that the current message has been acknowledged.If true, an additional message smaller than the delivery tag specified by the first parameter will be acknowledged。 (Bulk confirmation is for the entire channel)

Cancel confirmation

What if one of the clients of the distributed program has an exception and wants to cancel the confirmation of the message and let other clients process the message?

When there is an exception in the consumption message, we need to cancel the confirmation, and then we can use the basicReject method of Channel.

The first parameter specifies the delivery tag, and the second parameter describes how to handle this failure message.A value of true means that the message is put back in the queue header, and a value of false means that the message is abandoned




Previous:Teach you how to set up your own DNS server!
Next:Baidu Maps to get city coordinates
Posted on 9/22/2021 8:49:04 PM |
Learn to learn...
Disclaimer:
All software, programming materials or articles published by Code Farmer Network are only for learning and research purposes; The above content shall not be used for commercial or illegal purposes, otherwise, users shall bear all consequences. The information on this site comes from the Internet, and copyright disputes have nothing to do with this site. You must completely delete the above content from your computer within 24 hours of downloading. If you like the program, please support genuine software, purchase registration, and get better genuine services. If there is any infringement, please contact us by email.

Mail To:help@itsvse.com