Get Started with MQTT over QUIC: A Quick Guide for The Next-generation IoT Standard Protocol

Preface

Enable MQTT over QUIC

  1. Open the configuration file etc/emqx.conf, and uncomment the listeners.quic.default block (add it manually if it does not exist):
# etc/emqx.conf
listeners.quic.default {
enabled = true
bind = "0.0.0.0:14567"
max_connections = 1024000
keyfile = "etc/certs/key.pem"
certfile = "etc/certs/cert.pem"
}
EMQX_LISTENERS__QUIC__DEFAULT__keyfile="etc/certs/key.pem" \
EMQX_LISTENERS__QUIC__DEFAULT__certfile="etc/certs/cert.pem" \
EMQX_LISTENERS__QUIC__DEFAULT__ENABLED=true
> emqx_ctl listeners
quic:default
listen_on : :14567
acceptors : 16
proxy_protocol : undefined
running : true
ssl:default
listen_on : 0.0.0.0:8883
acceptors : 16
proxy_protocol : false
running : true
current_conn : 0
max_conns : 512000
docker run -d --name emqx \
-p 1883:1883 -p 8083:8083 \
-p 8084:8084 -p 8883:8883 \
-p 18083:18083 \
-p 14567:14567/udp \
-e EMQX_LISTENERS__QUIC__DEFAULT__keyfile="etc/certs/key.pem" \
-e EMQX_LISTENERS__QUIC__DEFAULT__certfile="etc/certs/cert.pem" \
-e EMQX_LISTENERS__QUIC__DEFAULT__ENABLED=true \
emqx/emqx:5.0.10

Clients and tools for MQTT over QUIC

Available client SDKs

  • NanoSDK: An MQTT SDK based on C, released by the NanoMQ team at EMQ. In addition to MQTT over QUIC, it also supports other protocols, such as WebSocket and nanomsg/SP.
  • NanoSDK-Python: The Python binding of NanoSDK.
  • NanoSDK-Java: The Java JNA binding of NanoSDK.
  • emqtt: A MQTT client library, developed in Erlang, supporting QUIC.

Problems and solutions

Connect MQTT over QUIC via NanoSDK

NanoSDK examples

## Create MQTT over Quic client with NanoSDK
nng_mqtt_quic_client_open(&socket, url);
quic_client sub/pub mqtt-quic://54.75.171.11:14567 topic msg

Bridge MQTT 3.1.1/5.0 and MQTT over QUIC via NanoMQ

NanoMQ bridging example

git clone https://github.com/emqx/nanomq.git
cd nanomq ; git submodule update --init --recursive

mkdir build && cd build
cmake -G Ninja -DNNG_ENABLE_QUIC=ON ..
sudo ninja install
## Bridge address: host:port .
##
## Value: String
## Example: ## Example: mqtt-tcp://broker.emqx.io:1883 (This is standard MQTT over TCP)
bridge.mqtt.emqx.address=mqtt-quic://54.75.171.11:14567

MQTT over QUIC CLI tools

nanomq_cli quic --help
Usage: quic conn <url>
quic sub <url> <qos> <topic>
quic pub <url> <qos> <topic> <data>

## subscribe example
nanomq_cli quic sub mqtt-quic://54.75.171.11:14567 2 msg

Use emqtt-bench for performance testing of QUIC

Compile emqtt-bench

brew install coreutils
brew install erlang@24
git clone https://github.com/emqx/emqtt-bench.git
cd emqtt-bench
CMAKE_BUILD_TYPE=Debug BUILD_WITH_QUIC=1 make
...
===> Warnings generating release:
*WARNING* Missing application sasl. Can not upgrade with this release
===> Release successfully assembled: _build/emqtt_bench/rel/emqtt_bench
===> Building release tarball emqtt_bench-0.3+build.193.ref249f7f8.tar.gz...
===> Tarball successfully created: _build/emqtt_bench/rel/emqtt_bench/emqtt_bench-0.3+build.193.ref249f7f8.tar.gz
/Users/patilso/emqtt-bench/scripts/rename-package.sh: line 9: gsed: command not found
/Users/patilso/emqtt-bench/scripts/rename-package.sh: line 9: gsed: command not found
/Users/patilso/emqtt-bench/scripts/rename-package.sh: line 9: gsed: command not found
/Users/patilso/emqtt-bench/scripts/rename-package.sh: line 9: gsed: command not found

Test QUIC

cd _build/emqtt_bench/rel/emqtt_bench/bin
./emqtt_bench sub -p 14567 --quic -t t/1 -c 10
./emqtt_bench pub -p 14567 --quic -t t/1 -c 1
$ lsof -nP -iUDP | grep 14567

com.docke 29372 emqx 76u IPv6 0xea2092701c033ba9 0t0 UDP *:14567
beam.smp 50496 emqx 39u IPv6 0xea2092701c014eb9 0t0 UDP [::1]:52335->[::1]:14567
beam.smp 50496 emqx 40u IPv6 0xea2092701c017689 0t0 UDP [::1]:56709->[::1]:14567
beam.smp 50496 emqx 41u IPv6 0xea2092701c0151c9 0t0 UDP [::1]:52175->[::1]:14567
beam.smp 50496 emqx 42u IPv6 0xea2092701c0157e9 0t0 UDP [::1]:54050->[::1]:14567
beam.smp 50496 emqx 43u IPv6 0xea2092701c015af9 0t0 UDP [::1]:58548->[::1]:14567
beam.smp 50496 emqx 44u IPv6 0xea2092701c013639 0t0 UDP [::1]:52819->[::1]:14567
beam.smp 50496 emqx 45u IPv6 0xea2092701c016119 0t0 UDP [::1]:57351->[::1]:14567
beam.smp 50496 emqx 46u IPv6 0xea2092701c017999 0t0 UDP [::1]:52353->[::1]:14567
beam.smp 50496 emqx 47u IPv6 0xea2092701c017ca9 0t0 UDP [::1]:57640->[::1]:14567
beam.smp 50496 emqx 48u IPv6 0xea2092701c014ba9 0t0 UDP [::1]:55992->[::1]:14567
beam.smp 51015 emqx 39u IPv6 0xea2092701c017069 0t0 UDP [::1]:64686->[::1]:14567
./emqtt_bench pub –help

./emqtt_bench conn –help

./emqtt_bench --help

Summary

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
EMQ Technologies

EMQ is an open-source IoT data infrastructure software provider, delivering the world’s leading open-source MQTT message broker and stream processing database.