AMQP · Study deck

AMQP Core: Consumers and Topology Contracts

AMQP adds a smart 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: 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.
  • 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: 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.

Numbers to remember

66%Server-side filtering reduces network traffic by 66% vs broadcast-and-filter approach.

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.
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 5

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

Q1Complete 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.

Q2Place each app protocols concept where it lives so you can separate connection scope from routing work and durable delivery state.

AMessage Broker
BWeb Server
CDatabase
DLoad Balancer
Show answer

Answer: A These boundaries keep scope connection, route message, hold delivery distinct so you can separate connection scope from routing work and durable delivery state.

iotclass.org

Retrieval practice

Recall check 2 of 5

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

Q3Per this chapter's Routing Path Contract section, when a downstream queue turns up unexpectedly empty, what should you check before assuming the producer is broken?

AThe exchange name, routing key, and binding keys, because a message can be perfectly published and still go unrouted if no binding matches
BThe consumer's TCP connection settings, since routing has nothing to do with an empty queue
CWhether the producer restarted recently, since AMQP always re-routes messages after a producer reconnects
DThe message's content-type header, since exchanges route based on payload format
Show answer

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

iotclass.org

Retrieval practice

Recall check 3 of 5

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

Q4You need every one of five analytics services to process every telemetry message, and within each service you want to add workers to go faster. Which AMQP topology is correct?

AOne queue per service; workers compete within each queue.
BOne shared queue for all five services with everyone consuming from it.
CFive separate exchanges, one per service, each with one consumer.
DA direct exchange with the routing key set to each worker's name.
Show answer

Answer: A Independent service queues control which services receive buffered copies; competing consumers on one service queue control that service's in-flight processing capacity.

iotclass.org

Retrieval practice

Recall check 4 of 5

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
BOnly the data lake queue
CNeither queue because the routing key has three words
DBoth the temperature dashboard queue and the data lake queue
Show answer

Answer: D

iotclass.org

Retrieval practice

Recall check 5 of 5

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 exactly once and distributed across 10 worker consumers. Which AMQP consumer pattern should be used?

AFan-out distribution with each consumer having a dedicated queue bound to a fanout exchange
BCompeting consumers where all 10 workers subscribe to the same queue
CHeaders exchange with each consumer filtering by a different header attribute
DDirect exchange with 10 different routing keys, one per consumer
Show answer

Answer: B Competing consumers is the correct pattern when each message must be processed exactly once with load distribution.

iotclass.org

Print reference

Answers 1 of 2

Answer key.

  1. A · Pika uses BlockingConnection with ConnectionParameters for synchronous AMQP connections.
  2. A · These boundaries keep scope connection, route message, hold delivery distinct so you can separate connection scope from routing work and durable delivery state.
  3. A · The chapter's troubleshooting rule: an empty queue is a topology question first.
  4. A · Independent service queues control which services receive buffered copies; competing consumers on one service queue control that service's in-flight processing capacity.
  5. D
iotclass.org

Print reference

Answers 2 of 2

Answer key.

  1. B · Competing consumers is the correct pattern when each message must be processed exactly once with load distribution.
iotclass.org