A Mutable Log

A blog by Devendra Tewari


Project maintained by tewarid Hosted on GitHub Pages — Theme by mattgraham

MQTT with RabbitMQ and Node-RED

This post shows how to enable MQTT in RabbitMQ, and use Node-RED to test the setup. Official Docker container images of both RabbitMQ and Node-RED are used for convenience.

To start RabbitMQ Docker container run

docker run -it --name myrabbitmq -p 5672:5672 -p 15672:15672 -p 1883:1883 -p 15675:15675 rabbitmq:3

AMQP port 5672, management web interface port 15672, MQTT protocol port 1883, and WebSocket protocol port 15675 are exposed. MQTT over WebSocket can be accessed at ws://172.24.6.221:15675/ws.

If you kill the above shell and need to run the same container again

docker start -ai myrabbitmq

Management web interface plugin and MQTT plugin need to be enabled next.

Start a Bash shell into the container

docker exec -it myrabbitmq /bin/bash

Enable the plugins by issuing the rabbitmq-plugins command

rabbitmq-plugins enable rabbitmq_management
rabbitmq-plugins enable rabbitmq_mqtt
rabbitmq-plugins enable rabbitmq_web_mqtt
rabbitmq-plugins enable rabbitmq_amqp1_0

Now, you should be able to log into the management interface at http://localhost:15672 using username/password guest/guest, and use MQTT from any compatible MQTT client. AMQP 1.0 plugin is also enabled in case you want to emulate a service such as Azure Service Bus.

Node-RED, a popular tool to orchestrate IoT devices, can now be used to test MQTT.

If RabbitMQ is part of a larger solution that requires other containers, you may want to use docker-compose to bring them all up. Here’s a simple configuration file that shows how RabbitMQ may be brought up using docker-compose

  broker:
    image: rabbitmq:3
    command: "/bin/bash -c \"rabbitmq-plugins enable rabbitmq_mqtt; rabbitmq-server\""
    ports:
      - "1883:1883"
    volumes:
      - "./rabbitmq:/etc/rabbitmq"