Middle — Middle+
Can you explain the hierarchy of messages with guaranteed delivery, where the message is guaranteed to be delivered at least once?
sobes.tech AI
Answer from AI
Guaranteeing message delivery at least once (at-least-once delivery) means that the system ensures the message is delivered to the recipient at least once, but duplicates may occur.
The hierarchy of such message guarantees is usually built on the following levels:
- Sending the message:
- The message is placed in a queue or message broker.
- Acknowledgment of receipt:
- The recipient confirms receipt of the message.
- Resending:
- If acknowledgment is not received within a timeout, the message is resent.
In Go, for example, when working with brokers like Kafka or RabbitMQ, this logic can be implemented:
- The message is published to the queue.
- The recipient processes the message and sends an acknowledgment.
- If acknowledgment is not received, the broker re-delivers the message.
This guarantees that the message will be delivered at least once but may be delivered multiple times if acknowledgment is lost or processing was not completed.
Example in Go with RabbitMQ (simplified):
ch, _ := conn.Channel()
msgs, _ := ch.Consume("queue", "", false, false, false, false, nil)
for d := range msgs {
// process message
processMessage(d.Body)
// acknowledge processing
d.Ack(false)
}
If Ack is not called, the message will be redelivered.