In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)05/31 Report--
This article is about how RabbitMQ achieves reliable delivery of messages. The editor thinks it is very practical, so share it with you as a reference and follow the editor to have a look.
General message middleware (MQ) can only guarantee that messages will not be lost, but can not guarantee repeated transmission and other problems.
For example, in the process of using Rabbitmq, how to ensure that messages are correctly delivered and consumed is a problem to be considered.
So what are the problems faced by reliability delivery?
1. What if the message sent is repeated.
two。 What if the message is lost during delivery.
3. How to ensure that the MQ node receives the message successfully.
RabbitMQ provides the following mechanisms to solve this problem:
Producer confirmation
Persistence
Manual Ack
The picture below is a solution for the reliable delivery of a complete message from Rabbitmq.
Let's analyze it.
The data sent by Step1:Producer is our business data, such as order information. The order information given to us by Producer before sending the message is written into our local database (BIZ DB). BIZ DB is our business database, and then the message to be sent is stored in the message record database (MSG DB). This MSG DB is used to store all the message records sent to Rabbitmq. The record field status (status) will have several values in the message record table. For example, 0 indicates that the message is being sent. 1 indicates that the message was sent successfully, and 2 indicates that the message failed.
Step2: the application wants a message to be sent to the Broker of Rabbitmq. This message belongs to confirm mode and requires Rabbitmq confirmation after it is sent.
After receiving the message, Step3:Rabbitmq Broker will give Producer a reply to confirm that I have received the message.
Step4: following the previous step, Producer has been listening to (Listener) the information confirmed by Broker. After receiving the message, it updates the message delivery status in MSG DB according to the result of receiving the message, and updates the record status field to 1.
Step 5: but in the process of message confirmation, the failure or exception of the echo message may be caused by network flash breakage, MQ Broker-side exception and other reasons. At this time, it is necessary for the sender (producer) to deliver the message reliably to ensure that the message is not lost and that 100% of the delivery is successful! (there is a limit case where Broker returns a successful confirmation message, but because the network flash is not received at the production end, re-delivery at this time may cause repetition of the message and require the consumer to do idempotent processing.) therefore, we need to have a scheduled task, such as pulling a message in the middle state every 5 minutes. Of course, this message can set a timeout period, such as more than 1 minute Status = 0. This means that within the time window of 1 minute, if our message is not confirmed, it will be pulled out by the timing task.
Step 6: next, we re-deliver the intermediate message to retry send, and continue to send the message to MQ. Of course, there may be a variety of reasons that cause the delivery failure.
Step 7: we can set the maximum number of attempts, such as whether it has been delivered three times or failed, then we can set the final state to Status = 2 and leave the problem to be solved manually (or dump the message into the failure table).
Thank you for reading! This is the end of the article on "how to achieve reliable delivery of messages in RabbitMQ". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, you can share it for more people to see!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.