How does rabbitmq ensure the reliable transmission of messages (brief version)?

I need to consider from three points,

  • The producer loses the data, the producer sends the message to Exchange and routes it to the queue
  • The queue needs to persist messages to it
  • The consumer must successfully consume the messages in the queue

For producers:

RabbitMQ provides a confirm mechanism to ensure the Exchange switch for sending messages. It also provides a return mechanism to ensure that messages are routed from the exchange to the queue. If the sending fails or the routing fails, it will provide a callback function that can be reworked. try or some compensation mechanism,

Persistence for queues

You only need to set the deliveryMode attribute in the BasicProperties of the message to 2 before sending the message, so that the message will not be lost even if RabbitMQ restarts

for consumers

He needs to enable manual ack. After the message is successfully consumed, he needs to manually perform ack based on the channel, which ensures that the message can be consumed normally.

Guess you like

Origin blog.csdn.net/weixin_43811057/article/details/131652947