Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Example Analysis of message Reliability in rabbitMq

2025-02-25 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/01 Report--

This article mainly shows you the "sample analysis of message reliability in rabbitMq", which is easy to understand and well-organized. I hope it can help you solve your doubts. Let the editor lead you to study and learn the article "sample analysis of message reliability in rabbitMq".

Text: although messages have the advantages of asynchronism and high concurrency, they have some disadvantages such as certain delay, weak data consistency, and even message sending / consumption failure. Therefore, we can guarantee the message reliability from the producer side, the server side and the consumer side. If all three sides can guarantee the message reliability, the message reliability will be OK.

Producer side:

Exception catch mechanism exception catch in client code, if an exception is thrown during the execution of the business logic, it is reissued or rolled back. However, no exception does not mean success, so this scheme is the best effort to ensure.

Note: you can also enable the retry of the sender through spring.rabbitmq.template.retry.enabled=true configuration.

The transaction mechanism of AMQP/RabbitMQ turns on the transaction mode of mq. If the transaction is successfully committed, it must be sent successfully. As shown below:

However, this method has a high performance overhead and is generally not used.

The sender-side acknowledgement mechanism (publish confirm, later referred to as pc) is to ensure that the message is sent successfully. If it is not successful, it is necessary to know which messages are not successful and deal with them accordingly.

Pc principle: after creating a channel, set channel to confirm mode, and messages sent over this channel will generate a unique id (msg_id, starting with 1). After the message is successfully sent to the queue, an ack confirmation message is returned to the sender, and a Nack message is returned if it fails.

Special note: the so-called return ack and nack are actually two callback functions. The callback function contains msg_id, as well as two parameters: Long deliveryTag and Boolean multiple. If multiple is true, it stands for msg_id

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.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report