This is a docker container for running a normal MQTT broker. The MQTT broker is based on the Eclipse Mosquitto project. |
To run the container, you can use the following command that configure the environment with the necessary directory:
./init.sh
To test the mqtt broker, run a subcriber with the following command:
mosquitto_sub -h localhost -t /test
After that, publish a message on the same topic with the following command:
mosquitto_pub -h localhost -t /test -m "Hello, World!"
You should see the message "Hello, World!" on the subscriber terminal.
To test the mqtt broker with authentication, use the following command to publish a message:
mosquitto_pub -h localhost -p 51883 -t /test -m "Hello, World!" -u user -P password
And to subscribe to the topic, use the following command:
mosquitto_sub -h localhost -p 51883 -t /test -u user -P password
You should see the message "Hello, World!" on the subscriber terminal.
To add a new client to the broker MQTT, run the following command:
docker run -it --rm -v "$(pwd)"/mounted_volumes/mqtt-with-auth/config:/mosquitto/config eclipse-mosquitto mosquitto_passwd -b /mosquitto/config/passwords.txt username password
Where username
is the username of the new client wiht password
as the password of the new client.
After that, restart the MQTT broker with the following command:
docker restart mqtt-with-auth
This work is licensed under a Creative Commons Attribution 4.0 International License.