mqttmosquitto

How to test the `Mosquitto` server?


I am new to Mosquitto and MQTT, I downloaded the Mosquitto server library but I do not know how to test it.

Is there any way to test the Mosquitto server?


Solution

  • In separate terminal windows do the following:

    1. Start the broker:

      mosquitto
      
    2. Start the command line subscriber:

      mosquitto_sub -v -t 'test/topic'
      
    3. Publish test message with the command line publisher:

      mosquitto_pub -t 'test/topic' -m 'helloWorld'
      

    As well as seeing both the subscriber and publisher connection messages in the broker terminal the following should be printed in the subscriber terminal:

    test/topic helloWorld
    

    EDIT:

    It is worth pointing out that from v2.0.0 of Mosquitto it will only be listening for connections on the loopback interface by default. If you want to access the broker from machines other than the one it is installed on you will need to edit the config file (and pass it to the broker with the -c option e.g. mosquitto -c /path/to/mosquitto.conf) to enable listening on other interfaces. Details can be found in the v2.0.0 release notes here