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

Connect MQTT Clients to Your Broker

  1. Open a terminal window and start the MQTT CLI in shell mode:

    mqtt sh

    The MQTT CLI starts and displays available options and commands.

  2. 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 -s flag opens a secure connection using the default SSL configuration.

    Connection information for the first MQTT client displays in the terminal.

  3. Open a second terminal window and start a second MQTT CLI session:

    mqtt sh
  4. 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

  1. In the second terminal window, subscribe to a test topic:

    sub -t testTopic -s
    In shell mode, the -s flag blocks the MQTT CLI console so that incoming messages display automatically.
  2. In the first terminal window, publish a test message:

    pub -t testTopic -m Hello

    The message Hello appears immediately in the second terminal window.

  3. Publish another message to confirm delivery:

    pub -t testTopic -m Goodbye

    The message Goodbye appears immediately in the second terminal window.