AMQP · Study deck

AMQP Core: Consumers and Topology Contracts

AMQP puts a sorting desk between senders and receivers.

Broker Bex is your guide for this deck.

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

After studying this chapter

Learning objectives

You will be able to:

  • Explain: If you only need the intuition: the exchange is a sorting rule, the binding key is the label on a mailbox slot, and the routing key is the address written on the envelope.
  • Explain: Every queue is automatically bound to it with a binding key equal to the queue's own name, so publishing to "" with routing key orders lands straight in the queue named orders.
  • Explain: One queue bound with plant1.# receives a site-wide copy, another bound with.line3. Receives the line-3 copy, and a third bound with #.vibration receives nothing.
iotclass.org

Major section

Worked Example: Designing Multi-Tier Alert Routing with AMQP Topic Exchange

Scenario: Manufacturing facility needs to route machine alerts to appropriate teams based on severity and location.

  • The system has 100 machines across 4 production lines, and 3 alert levels (info, warning, critical).
  • Server-side filtering reduces network traffic by 66% vs broadcast-and-filter approach.
  • Adding new subscribers requires only 1 binding, not 100 per-machine configurations.

Why it matters

Wildcards reduce binding complexity from 6×100 machine-specific bindings to 6 pattern bindings.

iotclass.org

Major section

Worked Example: Designing Multi-Tier Alert Routing with AMQP Topic Exchange (continued)

Pattern-based routing scales to 1,000 machines with no binding changes (wildcards handle new machines automatically).

  • Lesson Learned: AMQP topic exchanges provide sophisticated routing that would require complex application-layer filtering with MQTT.
  • The broker's pattern matching offloads work from consumers and reduces network bandwidth, making it ideal for enterprise IoT with multiple subscriber tiers needing selective message delivery.
  • Wildcards reduce binding complexity from 6×100 machine-specific bindings to 6 pattern bindings.
iotclass.org

Major section

AMQP Routing Topology Contracts

AMQP topology makes that a broker decision: exchanges inspect the routing key, bindings state who qualifies, and queues hold each matched copy.

  • A successful publish does not prove that every required consumer received a copy.
  • A protocol means an agreed set of message and behavior rules.
  • A broker means the service that receives and routes messages.

Why it matters

A single publish of hq.floor1.temperature is copied into all three distinct queues because each queue is reached by a matching binding; a topic exchange does not choose only the most specific match.

Exchange type is the matching rule: direct is exact, fanout ignores the key, topic uses wildcard keys, and headers uses message attributes.
Exchange type is the matching rule: direct is exact, fanout ignores the key, topic uses wildcard keys, and headers uses message attributes.
iotclass.org

Major section

AMQP Routing Topology Contracts (continued)

AMQP means Advanced Message Queuing Protocol, which defines roles and behavior for brokers, producers, queues, and consumers.

  • The exchange holds no messages of its own; it evaluates every binding and enqueues one copy in each distinct destination queue reached by at least one match.
  • That makes troubleshooting concrete.
  • Numbers make the difference visible.
iotclass.org

Major section

AMQP Routing Topology Contracts (continued)

The producer did not know those queue names and did not send three messages; the exchange evaluated three bindings and made two copies.

  • MQTT also decouples publishers from subscribers through broker-side subscription matching; what it does not expose is AMQP 0-9-1's explicit exchange-binding-queue topology.
  • Worked example: a temperature device publishes once to exchange iot.events with routing key plant1.line3.temperature.
  • Queue topology, not worker count alone, controls the semantics.
iotclass.org

Major section

AMQP Routing Topology Contracts (continued)

One queue bound with plant1.# receives a site-wide copy, another bound with.line3. Receives the line-3 copy, and a third bound with #.vibration receives nothing.

  • If operations later adds a billing queue bound with plant1.line3.#, the producer still publishes the same packet, but the topology now creates a third copy.
  • When a queue is empty, inspect the exchange name, routing key, and binding keys before blaming the producer.
  • A perfectly published message can still be unrouted if no binding matches, or copied to several distinct queues if several routes match.
  • Choosing one is choosing a matching rule, not a feature set.
iotclass.org

Major section

AMQP Routing Topology Contracts (continued)

If you only need the intuition: the exchange is a sorting rule, the binding key is the label on a mailbox slot, and the routing key is the address written on the envelope.

  • The four standard exchange types differ only in how they compare a routing key to a binding key.
  • The comparison connects topology choice to test cases for positive matches, negative matches, and operational handling of unroutable messages.
  • Direct is easiest to audit, fanout is easiest to reason about for broadcast, topic is the usual IoT default when keys carry hierarchy, and headers only pays off when routing depends on several independent attributes.
iotclass.org

Major section

AMQP Routing Topology Contracts (continued)

Five independent analytics services that must each receive every event require five distinct queues with matching bindings.

  • Every queue is automatically bound to it with a binding key equal to the queue's own name, so publishing to "" with routing key orders lands straight in the queue named orders.
  • Exchange matching selects a set of distinct destination queues, which determines how many independently buffered service copies exist; consumers attached to one queue determine that service's in-flight processing capacity.
  • If each service runs three worker instances, those three workers consume from that service's one queue.
One AMQP 0-9-1 publish is enqueued once in each distinct matching service queue. Consumers attached to one queue compete for that queue's delivery attempts, so binding another service queue adds an independently buffered copy, while adding consumers changes only that service's processing capacity.
One AMQP 0-9-1 publish is enqueued once in each distinct matching service queue. Consumers attached to one queue compete for that queue's delivery attempts, so binding another service queue adds an independently buffered copy, while adding consumers changes only that service's processing capacity.
iotclass.org

Major section

AMQP Routing Topology Contracts (continued)

RabbitMQ normally dispatches across active consumers in round-robin order, but prefetch, consumer availability, priorities or single-active-consumer settings, and redelivery can change the observed distribution.

  • If workers from all five services consume from one shared queue, only one service instance receives each delivery attempt; the other services do not receive independent copies.
  • If all fifteen workers instead have separate queues with identical matching bindings, one publication produces fifteen queue copies -- three copies inside each service rather than one.
  • In RabbitMQ, basic.qos(prefetch_count=10, global=false) applies the limit separately to each newly registered consumer.
iotclass.org

Deck summary

Key takeaways

Scenario: Manufacturing facility needs to route machine alerts to appropriate teams based on severity and location.

  • Pattern-based routing scales to 1,000 machines with no binding changes (wildcards handle new machines automatically).
  • AMQP topology makes that a broker decision: exchanges inspect the routing key, bindings state who qualifies, and queues hold each matched copy.
  • AMQP means Advanced Message Queuing Protocol, which defines roles and behavior for brokers, producers, queues, and consumers.
  • The producer did not know those queue names and did not send three messages; the exchange evaluated three bindings and made two copies.
iotclass.org

Retrieval practice

Recall check 1 of 6

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

Q1Two independent services each need every job from a stream of twelve jobs per second. One worker can complete four jobs per second. What topology and minimum total worker count keep up, ignoring overhead?

AA queue per service, with three workers each; six workers total.
BUse one shared queue and three workers, so each service receives a copy of all jobs.
CUse separate service queues but one worker each for twelve jobs per second.
DUse six independent queues with one worker each and assume each service sees every job.
Show answer

Answer: A Fan-out gives each service a copy; each queue needs three competing workers, for six workers overall.

iotclass.org

Retrieval practice

Recall check 2 of 6

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

Q2Complete the AMQP topic exchange setup with pika:

Aconnection = pika.BlockingConnection(pika.ConnectionParameters('localhost'))
Bconnection = pika.connect('localhost')
Cconnection = amqp.Connection('localhost')
Dconnection = pika.Connection(host='localhost')
Show answer

Answer: A Pika uses BlockingConnection with ConnectionParameters for synchronous AMQP connections.

iotclass.org

Retrieval practice

Recall check 3 of 6

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

Q3In this chapter's topic-exchange routing path, a downstream queue is unexpectedly empty. What should the team check before assuming the producer is broken?

AThe consumer's TCP connection settings, since routing has nothing to do with an empty queue
BWhether the producer restarted recently, since AMQP always re-routes messages after a producer reconnects
CCheck exchange name, routing key and bindings: a successful publish can still miss every queue.
DThe message's content-type header, since exchanges route based on payload format
Show answer

Answer: C The chapter's troubleshooting rule: an empty queue is a topology question first.

iotclass.org

Retrieval practice

Recall check 4 of 6

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

Q4In this chapter's topic-exchange telemetry worked example, a single publish of routing key hq.floor1.temperature matches bindings #, *.*.temperature, and hq.# at the same time. What does the chapter say happens to that one message?

AIt goes only to the data-lake queue bound with #, using that queue as the common ingestion path
BIt is delivered only to the most specific match, *.*.temperature, and the other bindings are ignored
CIt is rejected as ambiguous because more than one binding matches the same routing key
DIt is copied once into each of the three distinct queues reached by the matching bindings
Show answer

Answer: D A topic exchange evaluates every binding independently against the routing key.

iotclass.org

Retrieval practice

Recall check 5 of 6

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

Q5A smart factory uses an AMQP topic exchange for sensor data. Temperature sensors publish to sensor.temperature.line1 and vibration sensors publish to sensor.vibration.line2. The data lake queue is bound with pattern sensor.# and the temperature dashboard queue is bound with sensor.temperature.*. A message published with routing key sensor.temperature.line1 will be delivered to which queues?

AOnly the temperature dashboard queue; the data-lake wildcard cannot match this key.
BOnly the data lake queue; the dashboard binding cannot match a line1 temperature.
CBoth the temperature dashboard queue and the data lake queue
DNeither queue; a three-word key cannot match these topic binding wildcards.
Show answer

Answer: C see answers page

iotclass.org

Retrieval practice

Recall check 6 of 6

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

Q6An e-commerce platform processes 100,000 orders per second. Each order must be handled by exactly one worker, with work distributed across 10 consumers. Which AMQP consumer pattern should be used?

AA fanout exchange with one dedicated queue per consumer.
BA headers exchange filtered by a different worker attribute.
CA direct exchange with a separate routing key per worker.
DA shared queue with competing workers across ten consumers.
Show answer

Answer: D Competing consumers share one queue, distributing each delivery to one worker.

iotclass.org

Print reference

Answers 1 of 2

Answer key.

  1. A · Fan-out gives each service a copy; each queue needs three competing workers, for six workers overall.
  2. A · Pika uses BlockingConnection with ConnectionParameters for synchronous AMQP connections.
  3. C · The chapter's troubleshooting rule: an empty queue is a topology question first.
  4. D · A topic exchange evaluates every binding independently against the routing key.
iotclass.org

Print reference

Answers 2 of 2

Answer key.

  1. C · The # wildcard matches zero or more words, so sensor.# matches sensor.temperature.line1. The wildcard matches exactly one word, so sensor.temperature. matches sensor.temperature.line1 where line1 is the single matched word. Both patterns match, so the message is delivered to both queues. This multi-queue delivery is a key advantage of AMQP topic exchanges over MQTT's simpler filtering.
  2. D · Competing consumers share one queue, distributing each delivery to one worker.
iotclass.org