DEV Community

Cover image for šŸš€ Set Up RabbitMQ with MQTT and Management UI UsingĀ Docker
Mahmud Ibrahim
Mahmud Ibrahim

Posted on

šŸš€ Set Up RabbitMQ with MQTT and Management UI UsingĀ Docker

RabbitMQ is a powerful message broker that supports multiple protocols, including AMQP and MQTT. If you’re building event-driven microservices or IoT-based apps, having RabbitMQ locally with MQTT support is extremely useful.

In this guide, you’ll learn how to:

  • Spin up RabbitMQ using Docker
  • Enable the Management UI
  • Add MQTT protocol support
  • Test both MQTT and AMQP pub/sub functionality via terminal scripts

Let’s dive in!

rabbitmq

āœ… Prerequisites

Before you start, make sure you have the following installed:

  • Docker
  • Docker Compose
  • jq for parsing JSON (used in the subscriber script)

Install jq on Ubuntu:

sudo apt install jq
Enter fullscreen mode Exit fullscreen mode

🧱 Step 1: Docker Compose Setup

Create a file called rabbitmq-docker-compose.yml and paste in the following configuration:

services:
  # RabbitMQ
  rabbitmq:
    image: rabbitmq:4-management
    container_name: rabbitmq
    restart: unless-stopped
    ports:
      - "15672:15672" # RabbitMQ Management UI
      - "5672:5672" # RabbitMQ AMQP
    environment:
      RABBITMQ_HOST: '%'
      RABBITMQ_DEFAULT_USER: user
      RABBITMQ_DEFAULT_PASS: root
    volumes:
      - rabbitmq_data:/var/lib/rabbitmq
    networks:
      - rabbitmq_network
    healthcheck:
      test:
        - CMD
        - rabbitmq-diagnostics
        - '-q'
        - ping
      retries: 3
      timeout: 5s
      interval: 30s

volumes:
  rabbitmq_data:
    driver: local

networks:
  rabbitmq_network:
    driver: bridge
Enter fullscreen mode Exit fullscreen mode

šŸš€ Step 2: Launch the RabbitMQ Container

Run the following command to spin up the service:

docker compose -f rabbitmq-docker-compose.yml up -d --build
Enter fullscreen mode Exit fullscreen mode

Verify that it’s running:

docker ps
Enter fullscreen mode Exit fullscreen mode

You should see the RabbitMQ container up and listening on ports 5672, 15672, and 1883.

🌐 Step 3: Access the RabbitMQ Management UI

Open your browser and visit:

http://localhost:15672
Enter fullscreen mode Exit fullscreen mode

Log in with:

  • Username: user
  • Password: root

You’ll get a full dashboard with queues, exchanges, bindings, and users.

šŸ”Œ Step 4: Enable MQTTĀ Plugin

RabbitMQ supports MQTT through its plugin system. To enable it:

docker exec -it rabbitmq rabbitmq-plugins enable rabbitmq_mqtt
Enter fullscreen mode Exit fullscreen mode

Verify that it’s enabled:

docker exec -it rabbitmq rabbitmq-plugins list | grep mqtt
Enter fullscreen mode Exit fullscreen mode

You should see output like this:

[E*] rabbitmq_mqtt
Enter fullscreen mode Exit fullscreen mode

šŸ”„ Step 5: Test MQTT with Mosquitto

āœ… Install Mosquitto Clients

On Ubuntu:

sudo apt install mosquitto-clients
Enter fullscreen mode Exit fullscreen mode

After installation. Open a new terminal and type the command to publish a message

šŸ“¤ Publish a Message

mosquitto_pub -h localhost -p 1883 -t test_mqtt -m "Hello, MQTT!" -u user -P root
Enter fullscreen mode Exit fullscreen mode

šŸ“„ Subscribe to aĀ Topic

In a second terminal:

mosquitto_sub -h localhost -p 1883 -t test_mqtt -u user -P root
Enter fullscreen mode Exit fullscreen mode

You should see:

Hello, MQTT!
Enter fullscreen mode Exit fullscreen mode

šŸ–„ļø Step 6: Test AMQP Pub/Sub (Optional BashĀ Scripts)

You can also test RabbitMQ’s core AMQP protocol using publisher.sh and subscriber.sh scripts.

šŸ–‹ Sample publisher.sh

#!/bin/bash

RABBITMQ_USER="user"
RABBITMQ_PASS="root"
RABBITMQ_HOST="localhost"
QUEUE_NAME="test_queue"

# Declare the queue
curl -u "$RABBITMQ_USER:$RABBITMQ_PASS" -X PUT \
  -H "Content-Type: application/json" \
  -d '{"auto_delete":false,"durable":true}' \
  "http://$RABBITMQ_HOST:15672/api/queues/%2F/$QUEUE_NAME"

# Publish messages every 5 seconds
while true; do
  MESSAGE="Hello, RabbitMQ, This is a message from docker compose! $(date)"
  curl -u "$RABBITMQ_USER:$RABBITMQ_PASS" -X POST \
    -H "Content-Type: application/json" \
    -d "{\"properties\":{},\"routing_key\":\"$QUEUE_NAME\",\"payload\":\"$MESSAGE\",\"payload_encoding\":\"string\"}" \
    "http://$RABBITMQ_HOST:15672/api/exchanges/%2F/amq.default/publish"
  echo " [x] Sent '$MESSAGE'"
  sleep 5
done
Enter fullscreen mode Exit fullscreen mode

šŸ–‹ Sample subscriber.sh

#!/bin/bash  
RABBITMQ_USER="user"
RABBITMQ_PASS="root"
RABBITMQ_HOST="localhost"
QUEUE_NAME="test_queue"

# Continuously fetch messages from the queue
while true; do
  RESPONSE=$(curl -u "$RABBITMQ_USER:$RABBITMQ_PASS" -X POST \
    -H "Content-Type: application/json" \
    -d '{"count":1,"ackmode":"ack_requeue_false","encoding":"auto","truncate":50000}' \
    "http://$RABBITMQ_HOST:15672/api/queues/%2F/$QUEUE_NAME/get")

echo "Response: $RESPONSE"
MESSAGE=$(echo "$RESPONSE" | jq -r '.[0].payload' 2>/dev/null)

  if [ "$MESSAGE" != "null" ] && [ -n "$MESSAGE" ]; then
    echo " [x] Received '$MESSAGE'"
  fi

  sleep 1
done
Enter fullscreen mode Exit fullscreen mode

ā–¶ļø Make Scripts Executable

chmod +x publisher.sh subscriber.sh
Enter fullscreen mode Exit fullscreen mode

Then run them in separate terminals:

./publisher.sh  
./subscriber.sh
Enter fullscreen mode Exit fullscreen mode

rabbitmq in functional

🧯 Step 7: Stop the Service

When you’re done testing:

docker compose -f rabbitmq-docker-compose.yml down
Enter fullscreen mode Exit fullscreen mode

āœ… Summary

GitHub Link: https://github.com/rafi021/rabbitmq-message-broker-docker-compose

Youtube : https://youtu.be/Wld_qudiTeo

You’ve now set up:

  • RabbitMQ with MQTT and AMQP support
  • A web-based Management UI
  • Pub/Sub testing with both MQTT clients and bash scripts

This local setup is great for developing event-driven backends, IoT systems, or microservices without relying on cloud infrastructure.

If you found this helpful, consider bookmarking or sharing it with your team.

Top comments (0)