Test Sub/Pub with the MQTT CLI
Use the MQTT CLI to connect MQTT clients to your HiveMQ Cloud broker and test publish and subscribe operations.
| These steps use the MQTT CLI. You can use any MQTT client you prefer. |
Before You Begin
-
Download and install the current version of the MQTT CLI from GitHub.
-
Review the introductory MQTT CLI tutorial on YouTube (optional).
Connect MQTT Clients to Your Broker
-
Open a terminal window and start the MQTT CLI in shell mode:
mqtt shThe MQTT CLI starts and displays available options and commands.
-
Connect to your HiveMQ Cloud broker using the connection details from the Overview page in HiveMQ Platform:
con -h <cluster-url> -p <port-number> -s -u <mqtt-credentials-username> -pw <mqtt-credentials-password>HiveMQ Cloud brokers require secure TLS connections. The -sflag opens a secure connection using the default SSL configuration.Connection information for the first MQTT client displays in the terminal.
-
Open a second terminal window and start a second MQTT CLI session:
mqtt sh -
Copy the connection command from step 2 and run it in the second terminal window.
Connection information for the second MQTT client displays in the terminal.
Test Subscribe and Publish
-
In the second terminal window, subscribe to a test topic:
sub -t testTopic -sIn shell mode, the -sflag blocks the MQTT CLI console so that incoming messages display automatically. -
In the first terminal window, publish a test message:
pub -t testTopic -m HelloThe message
Helloappears immediately in the second terminal window. -
Publish another message to confirm delivery:
pub -t testTopic -m GoodbyeThe message
Goodbyeappears immediately in the second terminal window.