Test Your HiveMQ Software Broker
After you deploy HiveMQ Software, use the MQTT CLI to connect clients and test publish and subscribe operations.
The MQTT CLI is an open-source Java-based client tool included in the tools directory of HiveMQ version 4.4.0 and higher.
The following steps assume HiveMQ and the MQTT clients run on the same machine.
If the broker and clients run on separate systems, replace localhost with your broker address in the commands.
|
Before You Begin
-
Confirm that your HiveMQ instance is running.
-
Review the introductory MQTT CLI tutorial on YouTube (optional).
Connect MQTT Clients to Your Broker
-
Open a terminal window, go to the
tools/mqtt-cli/bindirectory in your HiveMQ installation, and start the MQTT CLI in shell mode:mqtt shThe MQTT CLI starts and lists available options and commands.
-
Connect your first MQTT client to the broker:
con -h localhost -i testClient1This command creates a client with the identifier
testClient1and connects it to your broker on localhost. -
Open a second terminal window and start a second MQTT CLI session:
mqtt sh -
In the second terminal window, connect a second MQTT client:
con -h localhost -i testClient2This command creates a second client with the identifier
testClient2and connects it to your broker on localhost.
Test Subscribe and Publish
-
In the second terminal window, subscribe to a test topic:
sub -t testTopic -s -
In the first terminal window, publish a test message:
pub -t testTopic -m HelloThe message
Helloappears immediately in the second terminal window. -
Confirm delivery by publishing a second message:
pub -t testTopic -m GoodbyeThe message
Goodbyeappears immediately in the second terminal window.