Mosquitto as MQTT connector

To install Mosquitto, we can follow the instructions from https://mosquitto.org/download/, or we can use Docker as usual.

  1. From the command console, run the following command:
$ docker run -it -p 1883:1883 -p 9001:9001 eclipse-mosquitto
  1. 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
  1. Subscribe to a topic as follows:
$ mqtt-cli localhost topic/hello payload -w
  1. 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
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset