In separate terminal windows do the following:
Start the broker:
mosquitto
Start the command line subscriber:
mosquitto_sub -v -t 'test/topic'
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
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…