MQTT X CLI: A Powerful and Easy-to-use MQTT CLI
MQTT X is designed to connect to MQTT brokers such as EMQX. It makes it easy and quick to create multiple simultaneous online MQTT client connections and test the connection, publishing, and subscription functions of MQTT/TCP, MQTT/TLS, MQTT/WebSocket as well as other MQTT protocol features.
The latest release of v1.8.0 not only optimizes the experience with a quick connection duplication feature but also supports new use cases by adding two new interaction methods, namely CLI (command line) and browser. This makes MQTT X 1.8.0 the most complete MQTT test client in terms of supported scenarios. Depending on your needs, you can choose to download the desktop client, use the terminal command line, or quickly test MQTT connections in your web browser.
MQTT X CLI: Rapidly Develop and Debug MQTT Services and Applications in the Terminal
With the widespread use of the MQTT protocol in the IoT industry, more developers are choosing to use MQTT X for connectivity testing.
In order to provide more choices and convenience for users to implement MQTT connection tests, MQTT X v1.8.0 adds the command line as a form of interaction - the MQTT X CLI, a fully open source MQTT 5.0 command line client tool. This allows developers to develop and debug MQTT services and applications faster using the command line without the graphical interface. This enables the following usage goals:
- Test deployed MQTT services in the server terminal
- Quickly test MQTT services by editing and using command line scripts
- Use command line scripts to perform simple stress tests or automated tests
MQTT X CLI website: https://mqttx.app/cli
MQTT X CLI 1.8.0 download: https://github.com/emqx/MQTTX/releases/tag/v1.8.0
MQTT X CLI GitHub repository: https://github.com/emqx/MQTTX/tree/main/cli
Dependency-free: Get up and Running with no Prerequisites Required
The MQTT X CLI can be quickly downloaded and installed on macOS, Linux, and Windows systems without any environmental dependencies, simply by executing commands in a terminal.
For macOS and Linux users, we provide a quick installation method using the command line to quickly download the binaries and install the latest stable version of MQTT X CLI on the operating system. Windows users can go to the MQTT X release page to find the exe package for the corresponding system architecture and manually download it for use.
Note: When downloading and installing, please be careful to distinguish the CPU architecture of the current system environment
- macOS users can quickly install and use the MQTT X CLI via Homebrew
brew install emqx/mqttx/mqttx-cli
- Intel Chip
curl -LO https://www.emqx.com/zh/downloads/MQTTX/v1.8.0/mqttx-cli-macos-x64
sudo install ./mqttx-cli-macos-x64 /usr/local/bin/mqttx
- Apple Silicon
curl -LO https://www.emqx.com/zh/downloads/MQTTX/v1.8.0/mqttx-cli-macos-arm64
sudo install ./mqttx-cli-macos-arm64 /usr/local/bin/mqttx
curl -LO https://www.emqx.com/zh/downloads/MQTTX/v1.8.0/mqttx-cli-linux-x64
sudo install ./mqttx-cli-linux-x64 /usr/local/bin/mqttx
curl -LO https://www.emqx.com/zh/downloads/MQTTX/v1.8.0/mqttx-cli-linux-arm64
sudo install ./mqttx-cli-linux-arm64 /usr/local/bin/mqttx
Windows users should manually download the corresponding exe file from the MQTT X download page at: https://github.com/emqx/MQTTX/releases/tag/v1.8.0
In addition to the above, we also provide an installation method using npm, so that you can quickly install and use it no matter what your current operating system environment is, as long as you have a Node.js environment on your system.
npm install mqttx-cli -g
Once you have completed the download and installation, you can run and use the
mqttx command by typing it directly into the terminal. You can verify that the MQTT X CLI has been installed successfully by adding the -V parameter, and when a version number is an output, the MQTT X CLI has been successfully installed.
$ mqttx -V
To test operation of the MQTT X CLI, you first need to connect to an MQTT server. In this article, we will use EMQ's free public MQTT broker, which runs on the fully managed MQTT cloud, EMQX Cloud, with the following access information:
- Broker: broker.emqx.io
- TCP Port: 1883
- WebSocket Port: 8083
We can use the command line to connect to the MQTT server and publish or subscribe to messages from within the terminal. We start by editing the command to subscribe to a topic within a terminal window.
mqttx sub -t 'mqttx/cli' -h 'broker.emqx.io' -p 1883
Next, let's try publishing a message to the topic we just subscribed to. Leave the listening subscriber running and create a new terminal window, then enter the command below.
mqttx pub -t 'mqttx/cli' -h 'broker.emqx.io' -p 1883 -m 'hello from MQTTX CLI!'
At this point, we can see a message that was just posted in the window of the Subscribe to Topic command.
Publishing Multiple Messages
The MQTT X CLI also supports a pub command to publish multiple messages, just add an -M parameter and an -s parameter to the command in the editor and separate each entry with a newline.
mqttx pub -t 'mqttx/cli' -h 'broker.emqx.io' -p 1883 -s -M
Finally, we test and verify the functionality of the MQTT X CLI by using the MQTT X desktop client to connect to the same MQTT service as the MQTT X CLI. We use the MQTT X CLI to publish a message, receive it through the MQTT X desktop client, and then reverse the process by using the MQTT X desktop client to send a message to the MQTT X CLI. At this point, we can see that both sides have received their respective incoming and outgoing messages.
This concludes our testing and verification of the MQTT message publish-subscribe feature using the MQTT X CLI. In addition to the common features mentioned above, the MQTT X CLI also supports setting up last will messages, using SSL/TLS to test mqtts connections, and more. MQTT 5.0 connectivity will also be supported in the future.
The release of the MQTT X CLI provides a new option for IoT developers to test MQTT connections. With complete support for command line calls, desktop client downloads, and online browsers, MQTT X 1.8.0 helps users with different use cases to complete the development and debugging of MQTT services or applications, improving their own business capabilities and stability. The easy-to-use test client tool, MQTT X, combined with the efficient, reliable MQTT broker, EMQX, will help IoT developers build competitive IoT platforms and applications.
Appendix: User Help
You can enter the — help parameter on the command line to get help or check the usage parameter table below to use the MQTT X CLI.
# Get help for the mqttx command
mqttx --help# Get help for the sub command
mqttx sub --help# Get help for the pub command
mqttx pub --help