AMQP · Study deck

AMQP Delivery: Guarantees and Acknowledgements

An AMQP message is a parcel with a label, a body, and a delivery receipt path.

Broker Bex is your guide for this deck.

archmessagesdelivery
Broker Bex, the module guide, in a scene from this chapter.
iotclass.org

After studying this chapter

Learning objectives

You will be able to:

  • Analyze Message Structure: Distinguish the role of AMQP header, properties, and body sections and explain how each field affects message routing and delivery
  • Configure Delivery Modes: Select appropriate message persistence, priority, and time-to-live (TTL) settings to match application reliability requirements
  • Implement Delivery Guarantees: Evaluate at-most-once and at-least-once delivery, and implement exactly-once processing with application deduplication based on data criticality and overhead trade-offs
  • Apply Acknowledgments: Demonstrate correct use of publisher confirms and consumer acknowledgments to construct reliable messaging pipelines
iotclass.org

Major section

In 60 Seconds

Losing one reading may be acceptable.

  • Losing the order is not.
  • Repeating the order may also create two visits, so the sender needs evidence of the receiver's final result, not only evidence that a message left.
  • AMQP is a set of messaging rules for moving labelled messages through a message service.
  • The application must close its own result.
iotclass.org

Major section

In 60 Seconds (continued)

AMQP 0-9-1 messages have properties (delivery mode, priority, expiration/TTL, correlation ID, message ID) and a body.

  • For each message class, record identity, sender, receiver, allowed age, repeat rule, order need, storage need, acceptance point, and final business result.
  • Stored delivery does not prove that the receiver acted, and a confirmation does not prove that the message was true.
  • Dead-letter queues can retain selected rejected, expired, or overflowed messages for investigation when configured.
iotclass.org

Major section

The Tracked Package

"My temperature alert says the warehouse is overheating, but the cooling system never turned on!" Temperature Terry cried. "What happened to my message?".

  • When you sent your alert, did you ask for a publisher confirm?" Sammy looked blank. "That's like asking the post office to text you when they receive your package.
  • If the cooling system crashes before saying ACK, the broker sends the message again.
  • Engineers can check it later to find out what went wrong.
iotclass.org

Major section

Message Structure

Reliability depends on the routing, persistence, timing, and identity metadata the message carries.

  • An AMQP message consists of multiple sections that provide metadata and payload.
  • Delivery controls such as durability and priority belong in the header; identifiers and content description travel as properties; the application value remains in the body.
AMQP message structure with header, properties, and body sections
AMQP message structure with header, properties, and body sections
iotclass.org

Major section

Delivery Guarantees

Once the parcel is shaped, choose the promise: speed and low overhead, or stronger protection against loss.

  • AMQP provides configurable delivery semantics to match application requirements.
  • Acknowledgment and retry trade possible loss for possible duplication; stronger coordination costs more state.
  • Fastest but may lose messages.
  • This needs publisher confirms, durable queues and manual consumer ACKs.

Key terms

Each message
Each message is delivered one or more times: once the broker confirms it, it is retried rather than silently dropped, but duplicates are possible.

Why it matters

The final caveat returns the design to application idempotency because transport evidence alone cannot prove a business effect happened exactly once.

AMQP delivery guarantee levels: at-most-once, at-least-once, exactly-once
AMQP delivery guarantee levels: at-most-once, at-least-once, exactly-once
iotclass.org

Major section

Delivery Guarantees (continued)

Each message is delivered one or more times: once the broker confirms it, it is retried rather than silently dropped, but duplicates are possible.

  • Delivery still depends on the configured broker and recovery path.
  • AMQP 0-9-1 can redeliver after a lost acknowledgment.
  • The aim here is one business effect even if the message is processed again.
iotclass.org

Major section

Try It: Delivery Guarantee Simulator

It assumes one retry after an uncertain first attempt; an unconfirmed result is counted as lost in the display.

  • Real broker guarantees depend on confirms, persistence, routing, consumer acknowledgments, and recovery.

Select a delivery pattern in this simplified model.

iotclass.org

Major section

Publisher Confirms

Delivery promises begin before the consumer sees the message.

  • Publisher confirms allow producers to know when messages are safely received by the broker.
  • The broker then reaches the durable acceptance boundary configured for that connection before returning an ACK.
  • The application must gather those later results separately.

Why it matters

A NACK or timeout leaves the producer without positive acceptance evidence; a timeout is ambiguous because the broker may already hold the first copy.

A publisher records ACK, NACK, or timeout after the broker reaches its configured acceptance boundary.
A publisher records ACK, NACK, or timeout after the broker reaches its configured acceptance boundary.
iotclass.org

Major section

Consumer Acknowledgments

After broker receipt, ACK and NACK behavior decides whether a queued message is removed, retried, or routed elsewhere.

  • If the work ends well, basic_ack() lets the broker remove that delivery.
  • If the work fails, follow the NACK branch.
  • With requeue=True, the broker can send the message again.
  • The handler must therefore make a repeat safe.

Key terms

Consumer acknowledgments ensure messages
Consumer acknowledgments ensure messages are processed successfully before removal from queues.
A consumer reports success with ACK or makes retry versus dead-letter handling explicit with NACK.
A consumer reports success with ACK or makes retry versus dead-letter handling explicit with NACK.
iotclass.org

Major section

Consumer Acknowledgments (continued)

This fork ties the ACK rule to retry bounds, safe repeats, and prefetch limits.

  • Each setting controls a different part of a failed attempt.
  • Prefetch controls how many unacknowledged messages a consumer can hold.
  • Raise the value only when measured idle time shows that additional overlap improves throughput without hiding too much unfinished work in one process.
iotclass.org

Major section

Dead Letter Queues

The last part of the reliability chain is evidence: failed messages should land somewhere inspectable.

  • Dead letter queues (DLQ) capture messages that cannot be processed successfully.
  • The exchange routes the failed message into the DLQ, where it can be inspected with its failure context.

Why it matters

When processing fails, basic_nack(requeue=False) prevents an immediate retry loop and sends the broker toward the configured dead-letter exchange.

A failed delivery leaves the main queue through the dead-letter exchange and waits in a DLQ for an operator decision.
A failed delivery leaves the main queue through the dead-letter exchange and waits in a DLQ for an operator decision.
iotclass.org

Deck summary

Key takeaways

Losing one reading may be acceptable.

  • AMQP 0-9-1 messages have properties (delivery mode, priority, expiration/TTL, correlation ID, message ID) and a body.
  • "My temperature alert says the warehouse is overheating, but the cooling system never turned on!" Temperature Terry cried. "What happened to my message?".
  • Reliability depends on the routing, persistence, timing, and identity metadata the message carries.
  • Once the parcel is shaped, choose the promise: speed and low overhead, or stronger protection against loss.
iotclass.org

Retrieval practice

Recall check 1 of 4

Broker Bex says: answer from memory, then check your reasoning.

Q1Per this chapter's Properties Section, which two AMQP properties work together to implement a request/reply (RPC) pattern over queues?

ACorrelation-ID links reply to request; Reply-To names response queue.
BContent-Type and Content-Encoding, since they identify how the response body is formatted
CMessage-ID and Timestamp, since they uniquely order requests and replies chronologically
DApp-ID and Type, since they identify which application should reply
Show answer

Answer: A see answers page

iotclass.org

Retrieval practice

Recall check 2 of 4

Broker Bex says: answer from memory, then check your reasoning.

Q2A water utility deploys AMQP to transmit two data streams: (1) water flow meter readings every 2 seconds across 1,000 sensors, and (2) automated valve-close commands triggered when a leak is detected. Which delivery modes should be configured, and why does the distinction matter at scale?

AExactly-once for both, since water infrastructure is safety-critical
BAt-least-once for both, since guaranteed delivery is always safer
CAt-most-once for flow readings; at-least-once for valve-close commands
DAt-most-once for both, since lower overhead improves system scalability
Show answer

Answer: C Choose the delivery path from the consequence of loss.

iotclass.org

Retrieval practice

Recall check 3 of 4

Broker Bex says: answer from memory, then check your reasoning.

Q3The shown Pika snippet calls confirm_delivery() before a blocking basic_publish(), then labels add_on_return_callback(on_confirm) as asynchronous publisher confirms. Which review finding is correct?

AThe blocking publish uses a callback while asynchronous confirms raise only exceptions on failure.
BBoth snippets have identical confirm behavior, differing only by their broker connection.
CAsynchronous confirms require exactly-once delivery while blocking confirms require at-most-once.
DThe blocking publish uses confirms; the shown return callback handles Basic.Return, not Basic.Ack/Nack confirms.
Show answer

Answer: D In the shown Pika BlockingChannel example, confirm_delivery makes basic_publish use synchronous publisher confirms.

iotclass.org

Retrieval practice

Recall check 4 of 4

Broker Bex says: answer from memory, then check your reasoning.

Q4Per this chapter's DLQ Triggers list, which of the following does the chapter NOT list as a way a message ends up in a dead-letter queue?

AConsumer rejection with requeue=false, which the chapter lists as a DLQ trigger
BMessage TTL expiry inside a queue, listed as a dead-letter trigger
CPublisher confirm timing out before broker Basic.Ack, before queue DLQ triggers apply
DMaximum queue length exceeded, another listed dead-letter trigger
Show answer

Answer: C The chapter's DLQ Triggers list has exactly four entries: consumer rejects with requeue=false, message TTL expires, queue length exceeded, and message rejected after max retries.

iotclass.org

Print reference

Answers 1 of 2

Answer key.

  1. A · The chapter's Key Concepts section states Correlation-ID is 'essential for request/reply patterns over queues,' and the properties table pairs it with Reply-To as the 'return address queue.' Together they let a requester publish to a well-known queue, specify where the reply should land (Reply-To), and match the eventual reply back to its original request (Correlation-ID).
  2. C · Choose the delivery path from the consequence of loss.
iotclass.org

Print reference

Answers 2 of 2

Answer key.

  1. D · In the shown Pika BlockingChannel example, confirm_delivery makes basic_publish use synchronous publisher confirms.
  2. C · The chapter's DLQ Triggers list has exactly four entries: consumer rejects with requeue=false, message TTL expires, queue length exceeded, and message rejected after max retries.
iotclass.org