Chapters

18 MQTT and AMQP: Routing Architectures

amqp
mqtt
use
hybrid
architecture

Start with the story: MQTT and AMQP are not rivals so much as tools for different parts of the route. MQTT is the lightweight uplink for devices; AMQP is the richer backend broker when routing, queues, and delivery evidence matter.

18.1 Start With the Decision

This section: Start With the Decision — MQTT sends device data through a simple topic tree.

MQTT sends device data through a simple topic tree. AMQP adds routes, queues, and work rules for enterprise flows.

18.2 Route Overview

This section: Route Overview — This is part 2 of 2.

This is part 2 of 2. Review MQTT and AMQP: Operational Tradeoffs for the preceding evidence.

18.3 Learning Objectives

This section: Learning Objectives

  • Trace architecture comparison: mqtt vs amqp data flow across its components and failure boundaries.
  • Define amqp and mqtt hybrid bridge contracts with explicit inputs, errors, and change rules.

18.4 Chapter Roadmap

This section: Chapter Roadmap

  • Architecture Comparison: MQTT vs AMQP Data Flow
  • Quick Check: Infrastructure Cost Comparison
  • Hybrid Architecture Pattern
  • Battery Life Impact Calculator
  • Protocol Overhead Impact on Battery Life
  • Knowledge Check
  • Quiz: Concept Matching and Sequencing
  • Label the Diagram
  • Code Challenge
  • Design Contract: Hybrid Bridge Placement
  • AMQP and MQTT Hybrid Bridge Contracts
  • Summary
  • What’s Next
  • Key Takeaway

18.5 Architecture Comparison: MQTT vs AMQP Data Flow

This section: Architecture Comparison: MQTT vs AMQP Data Flow

18.5.1 MQTT: Simple Pub/Sub Architecture

Inspect Figure 18.1 to understand the compact routing model that makes MQTT attractive at the device edge.

Architecture diagram of MQTT showing 50,000 sensors publishing to hierarchical topics like sensors/cardiff/lab and sensors/london/plant, with central broker routing to dashboard, alert service, and analytics subscribers using simple topic matching
Figure 18.1: MQTT architecture showing IoT sensors publishing to topic hierarchy with broker distributing messages to multiple subscribers

Trace Figure 18.1 from sensor publishes into the topic hierarchy, then follow matching subscriptions to their consumers. The broker mediates fan-out without separate application-visible queues and bindings. That simplicity reduces device-side burden while leaving durable backend work distribution to another layer when needed.

MQTT Characteristics:

  • Overhead: 2-byte fixed header minimum
  • Routing: Simple topic matching (sensors/+/temp)
  • Throughput: 166.7 msg/sec for 50,000 devices at 5-min intervals, easily handled by single broker
  • Cost: ~$96/year for AWS IoT Core (50K devices)

18.5.2 AMQP: Advanced Routing Architecture

Inspect Figure 18.2 to see where AMQP adds routing state beyond a simple topic subscription.

AMQP architecture diagram showing camera alert producer publishing to topic exchange with routing keys like zone.north.fire.critical, exchange distributing to dispatch queue, maintenance queue, and insurance queue based on binding patterns, with dead-letter queue for failed messages
Figure 18.2: AMQP architecture with exchange-based routing showing producer sending to topic exchange which routes messages to multiple queues based on binding patterns

Trace Figure 18.2 from producer to exchange, then evaluate bindings into distinct queues before following consumers. Exchanges decide matches while queues decouple delivery and processing. That separation enables backend fan-out and work distribution, but it also creates topology and failure policies the operator must own.

AMQP Characteristics:

  • Overhead: 8-byte frame header + exchange routing
  • Routing: Complex binding patterns with wildcards (zone..fire.)
  • Guarantees: Transactional delivery with acknowledgments and dead-letter queues
  • Cost: ~$15K setup + $5K/year maintenance for RabbitMQ cluster

This section:

18.6 Hybrid Architecture Pattern

This section: Hybrid Architecture Pattern — Inspect Figure 18.3 to identify the bridge as a reliability boundary, not merely a protocol translator.

Inspect Figure 18.3 to identify the bridge as a reliability boundary, not merely a protocol translator.

Hybrid architecture diagram with IoT sensors using MQTT to publish telemetry to edge broker, protocol bridge translating MQTT messages to AMQP format, AMQP topic exchange routing to enterprise services including ERP system, analytics platform, and alert management, combining MQTT efficiency at edge with AMQP sophistication in backend
Figure 18.3: The hybrid keeps lightweight MQTT at the edge and uses an owned reliability bridge before AMQP routes work to backend queues.

In Figure 18.3, begin with constrained devices publishing telemetry into a simple MQTT topic tree. The edge broker keeps that uplink light and collects many device streams. At the center, stop at the protocol bridge rather than jumping straight to AMQP: topic mapping, stable identifiers, buffering, and replay all cross this boundary. Someone must own its backlog and duplicate policy when either side is unavailable. Continue into the AMQP topic exchange only after those duties are explicit; bindings can then copy work into separate ERP, analytics, and alert queues. The split uses each protocol’s strength without pretending translation alone provides end-to-end reliability.

Hybrid Benefits:

  • Best of both worlds: MQTT efficiency at edge + AMQP sophistication in backend
  • Cost optimization: Pay for complexity only where needed (~$5K/year total vs $80K+ for pure AMQP)
  • Gradual migration: Start with MQTT, add AMQP backend as complexity grows
  • Technology match: Use each protocol where it naturally excels

18.7 Battery Life Impact Calculator

This section: Battery Life Impact Calculator

Protocol Overhead Impact on Battery Life

See how protocol choice affects battery life in battery-powered IoT devices.

18.8 Knowledge Check

This section: Knowledge Check — Test your understanding of AMQP vs MQTT protocol selection.

Test your understanding of AMQP vs MQTT protocol selection.

Match each concept to its correct definition or use case:

Arrange the steps of setting up an MQTT-to-AMQP protocol bridge in the correct order:

18.9 Design Contract: Hybrid Bridge Placement

This section: Design Contract: Hybrid Bridge Placement — MQTT and AMQP are usually a layer boundary decision, not a winner-takes-all protocol choice.

MQTT and AMQP are usually a layer boundary decision, not a winner-takes-all protocol choice. The deeper treatment now lives in AMQP and MQTT Hybrid Bridge Contracts, covering constrained-device uplink, backend routing, retained state versus durable work queues, MQTT-to-AMQP wildcard translation, bridge reliability, local spool sizing, idempotency keys, and operational metrics across both brokers.

18.10 AMQP and MQTT Hybrid Bridge Contracts

This section: AMQP and MQTT Hybrid Bridge Contracts — Start with the story: In a hybrid design, MQTT gets small messages off constrained devices and AMQP turns them into durable backend work.

Start with the story: In a hybrid design, MQTT gets small messages off constrained devices and AMQP turns them into durable backend work. The bridge is the border checkpoint that must preserve identity, routing meaning, replay rules, and monitoring evidence.

18.10.1 Learning Objectives

18.10.1.1 Keep Meaning Intact at the Bridge

A protocol is an agreed set of exchange rules. Telemetry is a time-linked record of a device or process. Quality of service is a named delivery level, not proof that a business action happened. Message queuing telemetry transport (MQTT) is often used by devices to publish readings. Advanced message queuing protocol (AMQP) is often used for richer service workflows. A QoS label describes the chosen delivery level.

Picture a cold-store alarm crossing from a device service into a work queue. The bridge must keep identity, time, unit, quality, and message age. If it changes a topic into a route but loses those fields, a valid delivery can still create a wrong action.

Write the mapping before building it. Name source field, target field, default, rejection rule, duplicate key, expiry, and failure store. Test a missing field, an old alarm, a duplicate, a full store, and a restart on each side. Check which team owns replay and correction.

This evidence proves the named mapping and limits. It does not make two message systems identical. The deeper sections compare their mechanisms and show how to build, monitor, and retire the boundary.

After this page, you should be able to:

  • Decide whether MQTT, AMQP, or a hybrid bridge owns each layer of an IoT system.
  • Compare MQTT topics, retained messages, QoS, and Last Will behavior with AMQP exchanges, queues, acknowledgments, and dead-letter routing.
  • Translate MQTT topic wildcards to AMQP topic-exchange routing keys without dropping deeper telemetry.
  • Specify bridge reliability contracts, including retained headers, idempotency keys, bounded spools, and replay rate.
  • Monitor a hybrid bridge by comparing MQTT ingress, AMQP publish rate, queue age, dead-letter rate, and spool growth.

18.10.2 Why This Follows AMQP vs MQTT

AMQP vs MQTT and Use Cases compares protocol overhead, feature fit, battery impact, decision trees, and hybrid architecture. This page tightens the production contract for the hybrid case: MQTT usually carries constrained device uplink, AMQP usually owns backend routing and work queues, and the bridge becomes a reliability boundary that must preserve enough metadata to replay safely.

Use it when a design review needs more than “MQTT at the edge, AMQP in the backend”: the bridge must define topic-to-routing-key mapping, replay ownership, failure back-pressure, deduplication, and the metrics that prove neither side is silently falling behind.

18.10.3 Overview: They Optimize for Different Ends of the System

MQTT and AMQP are both publish/subscribe, but they are tuned for opposite ends of an IoT system. MQTT is a deliberately tiny wire protocol for constrained devices on flaky links: a 2-byte minimum header, three QoS levels, retained messages, and a Last Will and Testament so the broker announces a device that dropped off. AMQP 0-9-1 is a richer broker protocol for the server side: first-class exchanges, queues, and bindings, plus acknowledgements, publisher confirms, and dead-letter routing for reliable work distribution.

Inspect Figure 18.4 to decide where each protocol belongs before treating MQTT and AMQP as interchangeable publish-subscribe choices.

A decision flowchart for choosing between MQTT and AMQP based on device/link limits, routing/work requirements, and failure/replay needs.
Figure 18.4: Protocol choice is a placement decision: MQTT usually owns constrained uplink, AMQP owns backend routing, and a bridge connects the two when both constraints matter.

Read Figure 18.4 from device constraints to routing and work-handling needs. Lightweight, intermittent uplinks point toward MQTT; broker-side queues, richer routing, and replay controls point toward AMQP; mixed constraints lead to a bridge. The route establishes the ownership boundaries that the rest of the chapter must make reliable.

The honest summary is not "which is better" but "which layer": MQTT gets telemetry off the device cheaply; AMQP routes and processes it reliably in the backend. Many real systems use both. Start the decision with three questions: is the publisher constrained, does routing need broker-side fan-out or work queues, and must failed work be parked for replay? "Yes" to the first pushes toward MQTT; "yes" to the second or third pushes toward AMQP behind the ingestion edge.

For 20,000 50-byte readings per minute, 17.3 kB/s is only the payload plus a 2-byte minimum MQTT fixed-header lower bound; a link budget must also include topic-name bytes, remaining-length encoding, packet identifiers when used, TCP and TLS (HiveMQ protocol comparison). The 19.3 kB/s AMQP figure counts payload plus one 8-byte frame-header illustration, not a complete publish. Use an encoded example or remove this cross-protocol bandwidth claim.

When a design review cannot name the constrained link, the routing rule, and the replay owner, it is too early to pick a single protocol.

18.10.4 Practitioner: Mechanism-by-Mechanism

ConcernMQTTAMQP 0-9-1
AddressingTopic tree; wildcards + (one level) and # (rest, last only)Exchange + binding key; topic wildcards * (one word), # (zero+ words)
Server-side queueingNone as a first-class object; delivery via subscriptions and (persistent) sessionsQueues are first-class: durable, competing consumers, DLX
ReliabilityQoS 0/1/2 between client and brokerPublisher confirms + consumer acks + durable/persistent
LivenessKeepalive/PINGREQ + Last Will and TestamentConnection heartbeats
FootprintMinimal; built for microcontrollers and cellularHeavier framing; built for servers and brokers
Sweet spotMany constrained publishers, edge telemetryBackend routing, work queues, enterprise integration

A telling detail: MQTT's retained message keeps the last value on a topic for new subscribers, which suits state ("current temperature"). AMQP has no retained concept because it queues every message for durable consumption, which suits work ("process each order"). Reach for the model whose default matches your data.

Use this as an implementation checklist. If a device publishes status that will be superseded by the next sample, MQTT retained messages and QoS 1 are usually enough. If an order, alarm, or command must be processed once by a worker pool, AMQP's durable queue plus manual ACK is a better fit. If a message must reach several independent backends, MQTT subscribers can all receive it, but each subscriber owns its own durability story; AMQP can route one publish into separate durable queues with independent retry and dead-letter policies.

The wildcard difference is another migration trap. MQTT topic site/+/temp maps naturally to AMQP routing key pattern site.*.temp, but MQTT site/# means the rest of the slash-separated tree and must be a final token, while AMQP # matches zero or more dot-separated words. Bridge tests should include site/floor1/temp, site/floor1/room7/temp, and site so the mapping does not accidentally drop deeper telemetry.

18.10.5 Under the Hood: The Hybrid Edge-to-Backend Bridge

Because they fit different layers, the common production shape is a hybrid: devices speak MQTT to a broker at the edge, and a bridge republishes those messages into AMQP for backend routing and durable work queues. A broker plugin or bridge maps an MQTT topic onto an AMQP topic-exchange routing key, translating the MQTT / separator to the AMQP . separator -- so MQTT topic sensor/floor1/temp becomes AMQP routing key sensor.floor1.temp, which AMQP bindings then match with * and #.

Worked example. Ten thousand battery sensors publish MQTT QoS 1 to an edge broker on topic site/<id>/temp. A bridge feeds those into an AMQP topic exchange as site.<id>.temp. In the backend, a data-lake queue binds site.# (store everything, durable, persistent), while an alerting service binds site.*.temp behind competing consumers with a modest prefetch, and rejects unprocessable messages to a dead-letter queue. Each protocol does what it is best at: MQTT for cheap, resilient uplink; AMQP for durable, richly-routed, load-balanced processing.

The bridge needs its own reliability contract. Preserve the MQTT packet identifier, client identifier, topic, QoS, and capture time as AMQP headers, then add an idempotency key before publishing into AMQP. If the AMQP broker blocks publishers, the bridge should stop acknowledging or committing MQTT-side intake rather than losing data in an in-memory buffer. A practical limit is a bounded local spool: for 10,000 sensors sending one message per minute, a 10-minute backend outage is about 10,000 x 10 = 100,000 records, so the bridge storage and replay rate must be sized deliberately.

Operationally, monitor both sides. MQTT metrics tell you connected clients, keepalive failures, retained-message count, and incoming message rate. AMQP metrics tell you exchange publish rate, queue depth, unacknowledged messages, dead-letter rate, and consumer drain rate. A healthy hybrid bridge keeps those curves aligned: MQTT ingress equals AMQP publish plus bounded spool growth, and AMQP queue age stays inside the business SLA.

18.11 Summary

This section: Summary — First: Protocol Selection Criteria should be based on device count, routing complexity, and transaction requirements.

First: Protocol Selection Criteria should be based on device count, routing complexity, and transaction requirements. MQTT excels for high-volume sensor telemetry (10,000+ devices), while AMQP provides sophisticated routing and transactional guarantees for enterprise integration.

Next: Overhead Comparison shows MQTT’s 2-byte minimum fixed header versus an AMQP 0-9-1 publish, which uses three frames with 8-byte envelopes each, making MQTT leaner for small, frequent IoT messages; measure complete packets and connection reuse before estimating costs.

Then: Routing Capabilities differ fundamentally: MQTT provides simple topic-based hierarchical routing with wildcards, while AMQP offers four exchange types (direct, fanout, topic, headers) for complex message routing scenarios like jurisdiction-based alert distribution.

After that: QoS vs Transactions have different boundaries. MQTT QoS 2 prevents duplicate application-message delivery on its protocol hop. AMQP 0-9-1 transactions group broker publishes and acknowledgments, but do not make an external business action exactly once.

Also inspect: Hybrid Architecture is the common production pattern, using MQTT for device-to-cloud telemetry (low overhead, simple) and AMQP for cloud-to-services integration (sophisticated routing, enterprise compatibility) connected via protocol bridges.

Finally: Cost Analysis needs current vendor quotes or a measured self-hosting budget. Compare message volume, retained state, availability, staff time, and bridge operations for the specific deployment.

18.12 What’s Next

This section: What’s Next — Having compared AMQP and MQTT and examined hybrid architecture patterns, the chapters below deepen each protocol and extend the comparison to additional protocols and integration concerns.

Having compared AMQP and MQTT and examined hybrid architecture patterns, the chapters below deepen each protocol and extend the comparison to additional protocols and integration concerns.

  1. MQTT Comprehensive Review Focus: MQTT patterns, performance optimization, and production deployment. Why read it: Deepen MQTT knowledge after understanding where it fits relative to AMQP.

  2. AMQP Production Operations Focus: Python, Java, and Node.js code for AMQP exchanges, queues, and transactions. Why read it: Implement the AMQP side of a hybrid architecture with working code examples.

  3. CoAP vs MQTT Comparison Focus: Extends the protocol comparison matrix to include CoAP for request-response scenarios. Why read it: Understand when CoAP is a better fit than either MQTT or AMQP.

  4. Protocol Bridges and Integration Gateways Focus: How protocol bridges translate between MQTT and AMQP in production systems. Why read it: Build the bridge layer that makes hybrid architectures work in practice.

  5. MQTT Labs and Implementation Focus: Hands-on MQTT coding exercises covering QoS levels, retained messages, and last-will. Why read it: Apply MQTT knowledge from this comparison chapter with practical exercises.

  6. IoT Protocols Review Focus: Comprehensive multi-protocol comparison across the full IoT stack. Why read it: Situate MQTT and AMQP within the broader landscape of Zigbee, CoAP, HTTP, and LoRaWAN.

18.13 Key Takeaway

This section: Key Takeaway — AMQP and MQTT solve different messaging problems.

AMQP and MQTT solve different messaging problems. Choose MQTT for lightweight device telemetry and publish-subscribe fleets; choose AMQP when enterprise routing, work queues, transactions, and broker-side delivery guarantees are the central requirement.

18.14 Continue Your Route

This section: Continue Your Route — This is the last part of this chapter.

This is the last part of this chapter. Return to MQTT and AMQP: Operational Tradeoffs or continue from the AMQP Module Guide.

Find help

3 reviewed answers.

Where should I start in a module?

Open the module page from the sidebar to see its chapters in order. Use the module map to return to a topic you need.

Modules and paths

Reviewed

What can I try when a project does not work?

Check the symptom, then work through the diagnostic steps. Keep the error message and the smallest example that reproduces it.

When you are stuck

Reviewed

How do interactive examples work?

Use the interactive guide to check how examples and simulations work before changing your project.

Interactive examples guide

Reviewed