NOTE

3.2 RabbitMQ Message Reliability

Message loss at the producer, MQ, and consumer, and the corresponding transaction, confirm, persistence, and manual-acknowledgement mechanisms.

Message QueuesCreated Updated 1 min readhistorical

This is a historical learning note and may contain outdated or incomplete understanding.

1. Three Situations

1.1. Producer

The message is lost before reaching MQ, or it reaches MQ but MQ encounters a problem and does not save it.

1.2. MQ

MQ temporarily keeps the message in memory and goes down before writing it to disk.

1.3. Consumer

The consumer consumes the message but goes down before processing it successfully.

2. Solutions

2.1. Producer

2.1.1. Enable Transactions

After a transaction starts, the producer blocks synchronously until MQ returns success or failure.

  • Disadvantage This reduces MQ throughput and is generally not used.

2.1.2. Confirmation Mechanism

Configure the channel in confirm mode. After sending, the producer does not wait; MQ asynchronously calls back the producer’s interface. When the message is successfully sent to MQ, the producer’s success callback is called [ack]. When message sending fails, the producer’s failure callback is called [nack], and the message can be sent again here.

2.2. MQ

  • Set the queue to durable when creating it. This persists MQ metadata.
  • Set deliveryMode to 2 when sending messages. This persists MQ data.

2.3. Consumer

  • Disable automatic ack and use manual ack.

Discussion

Sign in with GitHub to comment. Discussions are stored as GitHub Issues.View on GitHub