Get Started

After installing it, run mqttx on the terminal.

Quick Start

Connect

mqttx conn -h 'broker.emqx.io' -p 1883 -u 'admin' -P 'public'

Subscribe

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

Publish

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

Benchmark

# Connect Benchmark
mqttx bench conn -c 5000

# Subscribe Benchmark
mqttx bench sub -c 5000 -t bench/%i

# Publish Benchmark
mqttx bench pub -c 5000 -t bench/%i

Version Check

mqttx check

Use

mqttx --help
OptionsDescription
-v, --versionOutput the version number
-h, --helpDisplay help for command
CommandDescription
checkCheck for updates
connCreate a connection and connect to MQTT Broker
pubPublish a message to a topic
subSubscribes to one or multiple topics
benchMQTT Benchmark in performance testing

Connection

mqttx conn --help
OptionsDescription
-V, --mqtt-version <5/3.1.1/3.1>the MQTT version (default: 5)
-h, --hostname <HOST>the broker host (default: "localhost")
-p, --port <PORT>the broker port
-i, --client-id <ID>the client id
--no-cleanset the clean session flag to false (default: true)
-k, --keepalive <SEC>send a ping every SEC seconds (default: 30)
-u, --username <USER>the username
-P, --password <PASS>the password
-l, --protocol <PROTO>the protocol to use, mqtt or mqtts (default: mqtt)
--key <PATH>path to the key file
--cert <PATH>path to the cert file
--ca <PATH>path to the ca certificate
--insecuredo not verify the server certificate
-up, --user-properties <USERPROPERTIES...>the user properties of MQTT 5.0 (e.g. -up "name: mqttx cli")
-Wt, --will-topic <TOPIC>the will topic
-Wm, --will-message <BODY>the will message
-Wq, --will-qos <0/1/2>the will qos
-Wr, --will-retainsend a will retained message (default: false)
-Wd, --will-delay-interval <SECONDS>the will delay interval in seconds
-Wpf, --will-payload-format-indicatorwill message is UTF-8 encoded character data or not
-We, --will-message-expiry-interval <SECONDS>lifetime of the will message in seconds
-Wct, --will-content-type <CONTENTTYPE>description of the will message’s content
-Wrt, --will-response-topic <TOPIC>topic name for a response message
-Wcd, --will-correlation-data <DATA>correlation data for the response message
-Wup, --will-user-properties <USERPROPERTIES...>the user properties of will message
-se, --session-expiry-interval <SECONDS>the session expiry interval in seconds
--rcv-max, --receive-maximum <NUMBER>the receive maximum value
--maximum-packet-size <NUMBER>the maximum packet size the client is willing to accept
--topic-alias-maximum <NUMBER>the topic alias maximum value
--req-response-infothe client requests response information from the server
--no-req-problem-infothe client requests problem information from the server
--helpdisplay help for conn command

Publish

mqttx sub --help
OptionsDescription
-V, --mqtt-version <5/3.1.1/3.1>the MQTT version (default: 5)
-h, --hostname <HOST>the broker host (default: "localhost")
-p, --port <PORT>the broker port
-i, --client-id <ID>the client id
-q, --qos <0/1/2>the QoS of the message (default: 0)
--no-cleanset the clean session flag to false (default: true)
-t, --topic <TOPIC>the message topic
-k, --keepalive <SEC>send a ping every SEC seconds (default: 30)
-u, --username <USER>the username
-P, --password <PASS>the password
-l, --protocol <PROTO>the protocol to use, mqtt or mqtts (default: mqtt)
-nl, --no_localthe no local MQTT 5.0 flag
-rap, --retain-as-publishedthe retain as published MQTT 5.0 flag
-rh, --retain-handling <0/1/2>the retain handling MQTT 5.0
--key <PATH>path to the key file
--cert <PATH>path to the cert file
--capath to the ca certificate
--insecuredo not verify the server certificate
-up, --user-properties <USERPROPERTIES...>the user properties of MQTT 5.0 (e.g. -up "name: mqttx cli")
-v, --verboseprint the topic before the message
-Wt, --will-topic <TOPIC>the will topic
-Wm, --will-message <BODY>the will message
-Wq, --will-qos <0/1/2>the will qos
-Wr, --will-retainsend a will retained message (default: false)
-Wd, --will-delay-interval <SECONDS>the will delay interval in seconds
-Wpf, --will-payload-format-indicatorwill message is UTF-8 encoded character data or not
-We, --will-message-expiry-interval <SECONDS>lifetime of the will message in seconds
-Wct, --will-content-type <CONTENTTYPE>description of the will message’s content
-Wrt, --will-response-topic <TOPIC>topic name for a response message
-Wcd, --will-correlation-data <DATA>correlation data for the response message
-Wup, --will-user-properties <USERPROPERTIES...>the user properties of will message
-se, --session-expiry-interval <SECONDS>the session expiry interval in seconds
-si, --subscription-identifier <NUMBER>the identifier of the subscription
--rcv-max, --receive-maximum <NUMBER>the receive maximum value
--maximum-packet-size <NUMBER>the maximum packet size the client is willing to accept
--topic-alias-maximum <NUMBER>the topic alias maximum value
--req-response-infothe client requests response information from the server
--no-req-problem-infothe client requests problem information from the server
-Cup, --conn-user-properties <USERPROPERTIES...>the connect user properties of MQTT 5.0 (e.g. -Cup "name: mqttx cli")
--helpdisplay help for sub command

Subscribe

mqttx pub --help
OptionsDescription
-V, --mqtt-version <5/3.1.1/3.1>the MQTT version (default: 5)
-h, --hostname <HOST>the broker host (default: "localhost")
-p, --port <PORT>the broker port
-i, --client-id <ID>the client id
-q, --qos <0/1/2>the QoS of the message (default: 0)
-t, --topic <TOPIC>the message topic
-m, --message<MSG>the message body (default: "Hello From MQTT X CLI")
-r, --retainsend a retained message (default: false)
-s, --stdinread the message body from stdin
-M, --multilineread lines from stdin as multiple messages
-u, --username <USER>the username
-P, --password <PASS>the password
-l, --protocol <PROTO>the protocol to use, mqtt or mqtts (default: mqtt)
--key <PATH>path to the key file
--cert <PATH>path to the cert file
--capath to the ca certificate
--insecuredo not verify the server certificate
-up, --user-properties <USERPROPERTIES...>the user properties of MQTT 5.0 (e.g. -up "name: mqttx cli")
-pf, --payload-format-indicatorthe payload format indicator of the publish message
-e, --message-expiry-interval <NUMBER>the lifetime of the publish message in seconds
-ta, --topic-alias <NUMBER>value that is used to identify the topic instead of using the topic name
-rt, --response-topic <TOPIC>string which is used as the topic name for a response message
-cd, --correlation-data <DATA>used by the sender of the request message to identify which request the response message is for when it is received
-si, --subscription-identifier <NUMBER>the identifier of the subscription
-ct, --content-type <TYPE>a description of the content of the publish message
-Wt, --will-topic <TOPIC>the will topic
-Wm, --will-message <BODY>the will message
-Wq, --will-qos <0/1/2>the will qos
-Wr, --will-retainsend a will retained message (default: false)
-Wd, --will-delay-interval <SECONDS>the will delay interval in seconds
-Wpf, --will-payload-format-indicatorwill message is UTF-8 encoded character data or not
-We, --will-message-expiry-interval <SECONDS>lifetime of the will message in seconds
-Wct, --will-content-type <CONTENTTYPE>description of the will message’s content
-Wrt, --will-response-topic <TOPIC>topic name for a response message
-Wcd, --will-correlation-data <DATA>correlation data for the response message
-Wup, --will-user-properties <USERPROPERTIES...>the user properties of will message
-se, --session-expiry-interval <SECONDS>the session expiry interval in seconds
--rcv-max, --receive-maximum <NUMBER>the receive maximum value
--maximum-packet-size <NUMBER>the maximum packet size the client is willing to accept
--topic-alias-maximum <NUMBER>the topic alias maximum value
--req-response-infothe client requests response information from the server
--no-req-problem-infothe client requests problem information from the server
-Cup, --conn-user-properties <USERPROPERTIES...>the connect user properties of MQTT 5.0 (e.g. -Cup "name: mqttx cli")
--helpdisplay help for pub command

Benchmark

The bench command is used to test the performance of the broker. It has basically the same as the normal command options, the following will only list the new or changed options.

Connect Benchmark

mqttx bench conn --help
OptionsDescription
-c, --count <NUMBER>the number of connections (default: 1000)
-i, --interval <MILLISECONDS>interval of connecting to the broker (default: 10ms)
-I, --client-id <ID>the client id, support %i (index) variable

Subscribe Benchmark

mqttx bench sub --help
OptionsDescription
-c, --count <NUMBER>the number of connections (default: 1000)
-i, --interval <MILLISECONDS>interval of connecting to the broker (default: 10ms)
-I, --client-id <ID>the client id, support %i (index) variable
-t, --topic <TOPIC...>the message topic, support %u (username), %c (client id), %i (index) variables
-v, --verboseprint history received messages and rate

Publish Benchmark

mqttx bench pub --help
OptionsDescription
-c, --count <NUMBER>the number of connections (default: 1000)
-i, --interval <MILLISECONDS>interval of connecting to the broker (default: 10ms)
-im, --interval-message <MILLISECONDS>interval of publishing message to the broker (default: 1000ms)
-I, --client-id <ID>the client id, support %i (index) variable
-t, --topic <TOPIC...>the message topic, support %u (username), %c (client id), %i (index) variables
-v, --verboseprint history received messages and rate
-s, --stdinread the message body from stdin
-M, --multilineread lines from stdin as multiple messages

Typical stress test scenario

Connection test

Create 10000 connections at a rate of one connection every 10ms, with client ID mqttx-bench-%i:

mqttx bench conn -c 10000 -i 10 -I "mqttx-bench-%i"

If you are using EMQX, you can check the number of connections in EMQX after all connections have been established via EMQX Dashboard or by running ./bin/emqx_ctl listeners to see the information about the number of connections in EMQX.

tcp:default
  listen_on       : :1883
  acceptors       : 16
  proxy_protocol  : false
  running         : true
  current_conn    : 10000
  max_conns       : 1024000

Throughput test

Start 500 clients, subscribe to topic mqttx/bench/t:

mqttx bench sub -c 500 -t mqttx/bench/t

Then start 20 publishers, publishing messages to the topic mqttx/bench/t at a rate of 10 messages per second with the message mqttx bench test:

mqttx bench pub -c 20 -im 100 -t mqttx/bench/t -m "mqttx bench test"

Then, go back to the subscribing client, you can see the total number of messages received and the real-time message rate:

Received total: 10989500, rate: 100000/s