RabbitMQ STOMP and MQTT
RabbitMQ natively speaks AMQP, but many devices and applications use other messaging protocols. The STOMP and MQTT plugins extend RabbitMQ to support these additional protocols, making it a multi-protocol message broker that serves IoT devices, browser-based clients, and legacy systems alongside standard AMQP applications.
STOMP Protocol
STOMP stands for Simple Text Orientated Messaging Protocol. It is a simple, text-based protocol that works over TCP. Any language or platform that can open a TCP connection and read text can implement a STOMP client. STOMP clients connect to RabbitMQ and send/receive messages using plain text frames, making it easy to debug with raw tools like Telnet or Netcat.
Enabling STOMP
rabbitmq-plugins enable rabbitmq_stomp
STOMP listens on port 61613 by default.
STOMP Frame Structure
SEND destination:/queue/my-queue content-type:text/plain Hello from STOMP client! ^@ (null byte terminates the frame)
A STOMP frame has a command (SEND, SUBSCRIBE, CONNECT), headers (key:value pairs), and a body. This simplicity is why STOMP is popular for scripting and rapid prototyping.
STOMP Destinations and RabbitMQ Mapping
STOMP Destination Maps To /queue/my-queue → direct exchange, queue "my-queue" /exchange/my-exchange → named exchange "my-exchange" /topic/my.routing.key → amq.topic exchange, routing key "my.routing.key" /temp-queue/xyz → exclusive, auto-delete queue
WebSocket STOMP (rabbitmq_web_stomp)
The rabbitmq_web_stomp plugin wraps STOMP over WebSocket, allowing browser JavaScript to connect to RabbitMQ directly and receive real-time messages:
rabbitmq-plugins enable rabbitmq_web_stomp # WebSocket STOMP listens on port 15674
In a browser:
const ws = new WebSocket('ws://localhost:15674/ws');
// Use a STOMP.js library over this WebSocket connection
MQTT Protocol
MQTT (Message Queuing Telemetry Transport) is a lightweight publish-subscribe protocol designed for constrained devices and low-bandwidth networks. It is the dominant protocol in IoT (Internet of Things) deployments. Smart home sensors, factory machines, GPS trackers, and remote weather stations all commonly use MQTT.
Why MQTT Is Different
- Extremely small message overhead (2-byte minimum header)
- Built-in Quality of Service (QoS) levels
- Last Will and Testament — the broker publishes a message on behalf of a client that disconnects unexpectedly
- Retained messages — the broker keeps the last message on a topic and delivers it to new subscribers immediately
Enabling MQTT
rabbitmq-plugins enable rabbitmq_mqtt
MQTT listens on port 1883 (plain TCP) and port 8883 (TLS).
MQTT QoS Levels
QoS 0 (At most once): Fire and forget. Message may be lost. Fastest. QoS 1 (At least once): Message delivered at least once but may be duplicated. Consumer must handle duplicates. QoS 2 (Exactly once): Message delivered exactly once. Safest but slowest. Four-step handshake between client and broker.
MQTT and RabbitMQ Routing
MQTT uses topic strings like sensor/building1/temperature. RabbitMQ maps these to AMQP routing via the amq.topic exchange. The MQTT topic separator / maps to the AMQP topic separator ..
MQTT topic: sensor/building1/temperature AMQP key: sensor.building1.temperature MQTT wildcard + (single level): sensor/+/temperature AMQP wildcard *: sensor.*.temperature MQTT wildcard # (multi-level): sensor/# AMQP wildcard #: sensor.#
MQTT Configuration in rabbitmq.conf
mqtt.listeners.tcp.default = 1883 mqtt.allow_anonymous = false mqtt.vhost = / mqtt.exchange = amq.topic mqtt.subscription_ttl = 86400000 # 24 hours mqtt.prefetch = 10
WebSocket MQTT (rabbitmq_web_mqtt)
rabbitmq-plugins enable rabbitmq_web_mqtt # WebSocket MQTT listens on port 15675
STOMP vs MQTT: Which to Use
Criterion STOMP MQTT --------------------------------------------------- Target use case Web/scripting IoT devices Protocol style Text-based Binary, compact Browser support Yes (web_stomp) Yes (web_mqtt) QoS levels No (manual ack) Yes (0, 1, 2) Retained messages No Yes Last Will No Yes Overhead Low Very low Debugging ease High (text frames) Lower (binary)
Use MQTT for resource-constrained IoT devices, mobile apps, and any client where packet size matters. Use STOMP for web applications, scripting, and environments where simplicity and text-based debugging are priorities.
AMQP Clients Still Work
STOMP and MQTT clients publish messages that end up in the same RabbitMQ exchanges and queues as AMQP messages. A temperature reading from an MQTT sensor lands in a queue that an AMQP Java service can consume. A STOMP browser client can subscribe to events published by a Python AMQP producer. All protocols are first-class citizens in the same broker.
Summary
STOMP is a simple text-based protocol ideal for web clients, scripting, and any platform that can open a TCP socket. Enable it with rabbitmq_stomp on port 61613. MQTT is a lightweight binary protocol designed for IoT devices with QoS, retained messages, and Last Will support. Enable it with rabbitmq_mqtt on port 1883. Both protocols integrate with RabbitMQ's native AMQP routing through the amq.topic exchange. WebSocket variants (web_stomp, web_mqtt) enable browser-based real-time messaging.
