Sobes.tech
Middle — Middle+

Kas saaksite selgitada sõnumite hierarhiat koos kohaletoimetamise garantiiga, kus sõnum jõuab kindlasti vähemalt korra?

sobes.tech AI

Vastus AI-lt

The at-least-once delivery guarantee means that the system ensures that a message is delivered to the recipient at least once, but duplicates may occur.

The hierarchy of messages with this guarantee is usually built on the following levels:

  1. Sending the message — the message is placed in a queue or message broker.
  2. Acknowledgment of receipt — the recipient confirms receipt of the message (acknowledgment).
  3. Resending — if acknowledgment is not received within the specified timeout, the message is resent.

In Go, for example, 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 does not arrive, the broker re-delivers the message.

This guarantees that the message will be delivered at least once, but it may be delivered multiple times if the acknowledgment is lost or processing is 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 the message
    processMessage(d.Body)
    // Acknowledge processing
    d.Ack(false)
}

If Ack is not called, the message will be redelivered.