NOTE

3.2 RabbitMQ Message Reliability

Messages can be lost during sending, persistence, or consumer delivery. These notes organize RabbitMQ reliability issues by those stages.

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 invokes the producer’s callback asynchronously. 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], allowing the producer to resend the message.

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