To install Mosquitto, we can follow the instructions from https://mosquitto.org/download/, or we can use Docker as usual.
- From the command console, run the following command:
$ docker run -it -p 1883:1883 -p 9001:9001 eclipse-mosquitto
- We are going to deploy the official Mosquito distribution, so we can test our MQTT broker. We need to install an MQTT client. Run the following command with an administrative user:
$ npm install mqtt-cli -g
- Subscribe to a topic as follows:
$ mqtt-cli localhost topic/hello payload -w
- Publish our first message as follows:
$ mqtt-cli localhost topic/hello "Test hello message"
The outcome should look like this:
$ mqtt-cli localhost topic/hello payload -w
Topic: topic/hello Message: payload
Topic: topic/hello Message: Test hello message