17  AMQP and MQTT Hybrid Bridge Contracts

amqp
mqtt
hybrid
architecture

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.

17.1 Learning Objectives

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.

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

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

Protocol selection decision tree comparing MQTT, AMQP, and hybrid choices from constrained devices, routing complexity, and transaction needs.
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.

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.

That distinction becomes visible at scale. With 20,000 meters sending a 50-byte reading every minute, a 2-byte MQTT header yields about 20,000 x 52 / 60 = 17.3 KB/s before TLS and TCP. An 8-byte AMQP frame header raises that simple payload path to about 20,000 x 58 / 60 = 19.3 KB/s, plus a heavier connection model. The difference is not dramatic for one meter, but it matters for battery fleets and cellular plans; the AMQP features earn their cost only once backend routing and durable work handling are needed.

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.

17.4 Practitioner: Mechanism-by-Mechanism

Concern MQTT AMQP 0-9-1
Addressing Topic tree; wildcards + (one level) and # (rest, last only) Exchange + binding key; topic wildcards * (one word), # (zero+ words)
Server-side queueing None as a first-class object; delivery via subscriptions and (persistent) sessions Queues are first-class: durable, competing consumers, DLX
Reliability QoS 0/1/2 between client and broker Publisher confirms + consumer acks + durable/persistent
Liveness Keepalive/PINGREQ + Last Will and Testament Connection heartbeats
Footprint Minimal; built for microcontrollers and cellular Heavier framing; built for servers and brokers
Sweet spot Many constrained publishers, edge telemetry Backend 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.

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