As MQTT continues to gain popularity as a lightweight messaging protocol for the IoT, the need for efficient and user-friendly command line interface (CLI) tools is increasing. In this article, we will take a look at the top 5 MQTT CLI Tools available in 2023.
Before diving into the MQTT CLI tools, we need an MQTT broker to communicate and test. We choose the free public MQTT broker available on broker.emqx.io
.
MQTT Broker Info
- Server: broker.emqx.io
- TCP Port: 1883
- WebSocket Port: 8083
- SSL/TLS Port: 8883
- Secure WebSocket Port: 8084
For more information, please check out: Free Public MQTT Broker for IoT Testing.
MQTTX CLI is a lightweight and easy-to-use MQTT 5.0 command line tool. With various commands for MQTT publishing, subscribing, benchmarking, and IoT data simulation, it is one of the most powerful tools for MQTT development.
MQTTX CLI is an open-source project written in Node.js and developed by EMQ. It’s cross-platform and can work on Windows, macOS, and Linux.
Official Website: https://mqttx.app/cli
GitHub: https://github.com/emqx/MQTTX/tree/main/cli
- Fully support for both MQTT v3.1.1 and MQTT v5.0
- Cross-platform compatibility with Windows, MacOS, and Linux
- Dependency-free setup allowing for quick installation without prerequisites
- Supports CA, self-signed certificates, and one-way and two-way SSL authentication
- Performance testing capabilities for quickly evaluating MQTT service performance.
docker pull emqx/mqttx-cli
docker run -it --rm emqx/mqttx-cli
brew install emqx/mqttx/mqttx-cli
Test connecting to an MQTT broker:
mqttx conn -h 'broker.emqx.io' -p 1883 -u 'test' -P 'test'
Publish a QoS1 message to an MQTT topic:
mqttx pub -t 'topic' -q 1 -h 'broker.emqx.io' -p 1883 -m 'Hello from MQTTX CLI'
Subscribe to an MQTT topic:
mqttx sub -t 'topic/#' -h 'broker.emqx.io' -p 1883
Create 100 connections, bench a pub/sub scenario at 100 msgs/s:
mqttx bench pub -c 100 -t bench/%i -h 'broker.emqx.io' -p 1883
mqttx bench sub -c 100 -t bench/%i -h 'broker.emqx.io' -p 1883
Mosquitto is a widely used open-source MQTT broker with the popular mosquitto_pub
and mosquitto_sub
command line clients. These CLI tools offer a wide range of options to connect, subscribe to, and publish messages to an MQTT broker.
The Mosquitto project is written in C/C++ and maintained by the Eclipse Foundation. Mosquitto is highly portable and can be deployed on various platforms, including Linux, Mac, Windows, and Raspberry Pi.
- Lightweight and easy to use
- Support for MQTT v3.1.1 and v5.0 protocols
- Extensive command-line parameters
- Support for SSL/TLS encryption/authentication
- MQTT v5.0 request/response functionality
docker pull eclipse-mosquitto
brew install mosquitto
https://mosquitto.org/download/
Publish a QoS1 message to an MQTT topic:
mosquitto_pub -t 'topic' -q 1 -h 'broker.emqx.io' -p 1883 -m 'Hello from Mosquitto CLI'
Subscribe to an MQTT topic:
mosquitto_sub -t 'topic/#' -h 'broker.emqx.io' -p 1883
mosquitto_rr -t 'req-topic' -e 'rep-topic' -m 'request message' -h 'broker.emqx.io'
mosquitto_pub -t 'rep-topic' -m 'response message' -h 'broker.emqx.io'
NanoMQ is the latest open-source MQTT broker written in pure C for the IoT edge, initially developed by EMQ in 2020. It is fast and lightweight with multi-threading and asynchronous I/O architecture.
NanoMQ also provides an MQTT client SDK and a command line tool for MQTT benchmarking and debugging, specifically for MQTT over QUIC, the next generation of the MQTT protocol standard.
GitHub: https://github.com/nanomq/nanomq
- Comprehensive MQTT Toolkit with Proto Proxy
- Full support for MQTT v3.1.1 and MQTT v5.0 protocols
- Cross-platform compatibility with Windows, Mac, Linux, POSIX RTOS, and more
- Support for CA, self-signed certificates, and TLS/SSL encryption
- Built-in nanomsg (NNG)/DDS/ZeroMQ/SOME-IP proxy
- Performance benchmarking support
docker pull emqx/nanomq
Publish a QoS1 message to a topic:
nanomq_cli pub -t 'topic' --url "mqtt-tcp://broker.emqx.io:1883" -q 2 -u nano -m test
Subscribe to a topic:
nanomq_cli sub -t topic --url "mqtt-tcp://broker.emqx.io:1883" -q 1
Test connecting to an MQTT broker:
nanomq_cli conn --url "mqtt-tcp://broker.emqx.io:1883" -q 1
Create 10 connections, publish to a topic at 100 msgs/s:
nanomq_cli bench pub -t topic -h broker.emqx.io -s 16 -q 0 -c 10 -I 10
MQTT.js is a popular MQTT client library, written in JavaScript for node.js and the browser. MQTT.js also provides a CLI tool that can be used for MQTT testing and debugging in the command line.
MQTT.js CLI depends on Node.js, and Node v12+ is required to run.
GitHub: https://github.com/mqttjs/MQTT.js
- Easy to install and use, even for those who are not familiar with the MQTT protocol
- Support for both MQTT v3.1.1 and MQTT v5.0
- Cross-platform compatibility with Windows, MacOS, and Linux
- Support for CA, self-signed certificates, and TLS/SSL encryption
npm install mqtt -g
mqtt pub -t 'topic' -h broker.emqx.io -m 'Hello from MQTT.js CLI'
mqtt sub -t 'topic' -h broker.emqx.io
HiveMQ CLI is a fully MQTT 5.0 and MQTT 3.1.1 compatible command line interface developed by HiveMQ.
HiveMQ CLI is implemented with Java, and Java 8 is required to run.
GitHub: https://github.com/hivemq/mqtt-cli
- All MQTT 3.1.1 and MQTT 5.0 features are supported
- Interactive, direct, and verbose Modes for all MQTT Commands
- Shell behavior with Syntax Highlighting, Command history
- Ability to connect simultaneously various MQTT Clients to different Broker
- Built on JVM and various distributions available
docker pull hivemq/mqtt-cli
brew install hivemq/mqtt-cli/mqtt-cli
https://github.com/hivemq/mqtt-cli/releases
Publish a message to an MQTT topic:
docker run hivemq/mqtt-cli pub -t 'topic' -h 'broker.emqx.io' -p 1883 -m 'Hello from HiveMQ CLI'
Subscribe to an MQTT topic:
docker run hivemq/mqtt-cli sub -t 'topic' -h 'broker.emqx.io' -p 1883
Test features and limitations of an MQTT broker:
docker run hivemq/mqtt-cli test -h 'broker.emqx.io' -p 1883
MQTT 3: OK
- Maximum topic length: 65535 bytes
- QoS 0: Received 10/10 publishes in 497.85ms
- QoS 1: Received 10/10 publishes in 1992.64ms
- QoS 2: Received 10/10 publishes in 4460.73ms
- Retain: OK
- Wildcard subscriptions: OK
- Shared subscriptions: OK
- Payload size: >= 100000 bytes
- Maximum client id length: 15346 bytes
- Unsupported Ascii Chars: ALL SUPPORTED
MQTT 5: OK
- Connect restrictions:
> Retain: OK
> Wildcard subscriptions: OK
> Shared subscriptions: OK
> Subscription identifiers: OK
> Maximum QoS: 2
> Receive maximum: 65535
> Maximum packet size: 1048576 bytes
> Topic alias maximum: 65535
> Session expiry interval: Client-based
> Server keep alive: Client-based
In short, the MQTT CLI tools mentioned above offer a wide range of options for testing and debugging MQTT. You can choose according to the specific needs of your project. We hope this article provides some helpful insights into the top MQTT CLI tools for 2023.