Recently, the MQTT 5.0 cross-platform desktop client MQTT X , which was open sourced by EMQ, released version 1.8.0. MQTT X was born to connect and test various MQTT message servers . It supports the rapid creation of multiple simultaneous online MQTT client connections. It adopts a one-click connection method and a simple graphical interface to help users easily test MQTT/TCP and MQTT. /TLS, MQTT/WebSocket connection, publish and subscribe functions, explore more MQTT protocol features.

The newly released v1.8.0 not only optimizes the user experience through the new fast copy connection function, but also expands two new usage scenarios, namely, adding two new interaction methods, CLI (command line) and Web. This makes MQTT X 1.8.0 the most complete MQTT test client supporting usage scenarios. Users can choose to download the desktop client, use the terminal command line, or quickly complete the MQTT connection test on the desktop browser according to their needs.

MQTT X CLI: Rapidly develop and debug MQTT services and applications on the terminal

With the widespread use of the MQTT protocol in the IoT field, more and more users choose to use MQTT X for IoT connection testing. For some users, such as server developers, service operation and maintenance personnel, etc., downloading the desktop client may occupy a large amount of disk space in the system. Before each test, the client application needs to be opened in the operating system with a graphical interface. to debug. In this case, the desktop client is not very friendly to use.

Therefore, MQTT X adds an interactive form of command line - MQTT X CLI. This is a fully open source MQTT 5.0 command line client tool, namely MQTT X on the command line. Developers can quickly develop and debug MQTT services and applications using the command line through the MQTT X CLI without using a graphical interface. To achieve the following usage goals:

  • The deployed MQTT service can be tested in the server terminal
  • A quick test of the MQTT service by editing and using command line scripts
  • Use command line scripts to complete some simple stress tests or automated tests

MQTT X CLI website: https://mqttx.app/en/cli

MQTT X CLI v1.8.0 version download: https://github.com/emqx/MQTTX/releases/tag/v1.8.0

MQTT X CLI GitHub repository: https://github.com/emqx/MQTTX/tree/main/cli

Convenient and efficient: can be installed and used without relying on the environment

Install

MQTT X CLI can be quickly downloaded and installed on macOS, Linux and Windows systems. It does not require any dependent environment preparation before installation . Just execute commands in the terminal to install and use MQTT X CLI.

For users of macOS and Linux systems, we provide a quick installation method. Using the command line, you can quickly download the binary file and install the latest stable version of MQTT X CLI on the operating system. Windows users can go to the release page of MQTT X to find the exe package of the corresponding system architecture, which can be downloaded and used manually.

Note: When downloading and installing, please pay attention to distinguish the CPU architecture of the current system environment

macOS

  • Homebrew

    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

Linux

  • x86-64

     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
  • ARM64

     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

Windows users, please go to the download page of MQTT X to manually download the corresponding exe file to use, download address: https://github.com/emqx/MQTTX/releases/tag/v1.8.0

npm

In addition to the above methods, we also provide an installation method using npm , so that no matter what the current operating system environment is, as long as your system has the Node.js environment, you can quickly install and use.

 npm install mqttx-cli -g

quick start

After completing the download and installation, you can directly enter the mqttx command in the terminal to run and use it. You can add the -V parameter to verify whether the MQTT X CLI is successfully installed. When a version number is output, it proves that the MQTT X CLI has been successfully installed.

 $ mqttx -V
1.8.0

In order to test the use of MQTT X CLI, we need to prepare an MQTT service. This article will use the free public MQTT server provided by EMQ. The service is created based on the MQTT IoT cloud platform - EMQX Cloud . The server access information is as follows:

  • Broker: broker.emqx.io
  • TCP Port: 1883
  • WebSocket Port: 8083

After the MQTT service is ready, we can use the command line in the terminal to publish and subscribe messages. We first edit a command to subscribe to a topic in a terminal window.

subscription

 mqttx sub -t 'mqttx/cli' -h 'broker.emqx.io' -p 1883

After completing the subscription, we create a new terminal window and edit a command to publish a message to the topic we just subscribed to.

release

 mqttx pub -t 'mqttx/cli' -h 'broker.emqx.io' -p 1883 -m 'hello from MQTTX CLI!'

At this point, we can see a message just published in the window of the subscription topic command.

Post multiple messages

MQTT X CLI also supports a pub command that can publish multiple messages, just need to add a -M parameter and -s parameter to the command when editing. After each input is completed, you can wrap the line.

 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 with the MQTT X CLI. We use the MQTT X CLI to publish a message through the MQTT X desktop client. to receive, and in turn use 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 messages.

Epilogue

So far, we have completed the testing and verification of the MQTT message publish and subscribe function using MQTT X CLI. In addition to the above-mentioned common functions, MQTT X CLI also supports setting testament messages, using SSL/TLS to test the connection of mqtts, etc. MQTT 5.0 connections will also be supported in the future.

The release of MQTT X CLI provides a new option for IoT developers to test MQTT connections. The complete support for command line calls, desktop client downloads and online browsers enables MQTT X 1.8.0 to help users with different usage scenarios to complete the development and debugging of MQTT services or applications, thereby improving The user's own related business capabilities and stability. The easy-to-use test client tool MQTT X combined with the efficient and reliable IoT message server EMQX will help IoT developers build competitive IoT platforms and applications.

Attachment: use help

You can enter the --help parameter in the command line to get help, or check the parameter table below to use the MQTT X CLI.

 # 获取 mqttx 命令的帮助
mqttx --help

# 获取订阅命令的帮助
mqttx sub --help

# 获取发布命令的帮助
mqttx pub --help

Use the parameter comparison table


subscription

release

Copyright statement: This article is original by EMQ, please indicate the source when reprinting.

Original link: https://www.emqx.com/zh/blog/powerful-and-easy-to-use-mqtt-5-command-line-tool


EMQX
336 声望437 粉丝

EMQ(杭州映云科技有限公司)是一家开源物联网数据基础设施软件供应商,交付全球领先的开源 MQTT 消息服务器和流处理数据库,提供基于云原生+边缘计算技术的一站式解决方案,实现企业云边端实时数据连接、移动、...