00a0 22039 22008 2286 2713x27fa() 221ap 221bp …...6.10 plugins . . . . . . . . . . . . . . . . . ....

288
00A0 2203220022862713x 27FA⇐⇒ 221A 221B 3 22952297

Upload: others

Post on 22-Feb-2020

10 views

Category:

Documents


0 download

TRANSCRIPT

00A0 2203∃ 2200∀ 2286⊆ 2713x 27FA⇐⇒ 221A√ 221B 3√ 2295⊕ 2297⊗

EMQ X - ����� MQTT ������� 3.1.0

���������� <[email protected]>

2019 � 07 � 16 �

Contents

1 ���� (Get Started) 31.1 EMQ X R3.1 ������� . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31.2 MQTT �������� . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31.3 EMQ X R3.1 ��������� . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41.4 ������� EMQ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 51.5 �� MQTT ����� . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6

2 ���� (Installation) 72.1 EMQ X ����� . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 72.2 CentOS . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 72.3 Ubuntu . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 92.4 Debian . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 122.5 macOS . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 142.6 Windows . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 152.7 openSUSE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 152.8 FreeBSD . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 172.9 Docker . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 182.10 ������ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 182.11 Windows ������ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19

3 ���� (User Guide) 213.1 ���� . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 213.2 MQTT ���� . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 213.3 ��/���� . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 223.4 ���� (Shared Subscription) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 243.5 ���� (Bridge) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 253.6 HTTP ���� . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 293.7 MQTT WebSocket �� . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 303.8 $SYS-���� . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 303.9 �� . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 34

4 ���� (Configuration) 354.1 EMQ X ���� . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 354.2 EMQ X ������ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 354.3 EMQ X ���� . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 364.4 EMQ X ���� . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 374.5 EMQ X ������ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 37

i

4.6 EMQ X ��� Cookie . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 394.7 EMQ X ������ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 394.8 Erlang ����� . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 404.9 RPC ���� . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 414.10 ������ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 414.11 ����� ACL �� . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 424.12 MQTT ������ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 434.13 MQTT Zones ���� . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 444.14 MQTT Listeners ���� . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 484.15 MQTT/TCP ��� - 1883 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 484.16 MQTT/SSL ��� - 8883 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 504.17 MQTT/WebSocket ��� - 8083 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 524.18 MQTT/WebSocket with SSL ��� - 8084 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 544.19 Bridges �� . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 574.20 Modules �� . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 594.21 �������� . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 604.22 Broker ���� . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 604.23 Erlang ������� . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 61

5 ���� (Plugins) 635.1 Dashboard �� . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 655.2 ClientID ���� . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 665.3 Username ���� . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 665.4 JWT ���� . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 665.5 LDAP ��/������ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 675.6 HTTP ��/������ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 685.7 MySQL ��/������ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 695.8 Postgres ���� . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 715.9 Redis ��/������ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 735.10 MongoDB ��/������ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 755.11 PSK ���� . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 775.12 WebHook �� . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 775.13 Lua �� . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 785.14 Retainer �� . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 785.15 Delayed Publish �� . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 785.16 CoAP ���� . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 785.17 LwM2M ���� . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 795.18 MQTT-SN ���� . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 805.19 Stomp ���� . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 805.20 Recon ������ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 815.21 Reloader ����� . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 815.22 ������ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 825.23 EMQ X R3.1 ���� . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 82

6 ���� (Commands) 876.1 status �� . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 876.2 mgmt �� . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 876.3 broker �� . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 886.4 cluster �� . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 906.5 acl �� . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 916.6 clients �� . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 916.7 sessions �� . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 926.8 routes �� . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 936.9 subscriptions �� . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 94

ii

6.10 plugins �� . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 956.11 bridges �� . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 966.12 vm �� . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 986.13 mnesia �� . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1006.14 log �� . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1006.15 trace �� . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1026.16 listeners . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1036.17 ����(rule engine) �� . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1046.18 rules �� . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1046.19 rule-actions �� . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1066.20 resources �� . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1076.21 resource-types �� . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1086.22 recon �� . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1096.23 retainer �� . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1116.24 admins �� . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 112

7 ����API (REST API) 1137.1 URL �� . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1137.2 Basic �� . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1137.3 API �� . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1137.4 ����� . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1227.5 ����(Connections) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1247.6 ��(Sessions) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1287.7 ��(Subscriptions) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1337.8 ��(Routes) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1357.9 ��/��/���� . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1367.10 ��(Plugins) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1387.11 ���(Listeners) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1457.12 ������ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1487.13 ������ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1517.14 ���� . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1527.15 ��� . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1537.16 ��������� . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1547.17 ����(rule engine) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 155

8 ���� (Design) 1658.1 �� . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1658.2 ���� . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1668.3 ����� . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1678.4 ����� . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1678.5 ����� . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1688.6 ����� . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1698.7 ��(Hook)�� . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1698.8 ��������� . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1718.9 ��(Plugin)�� . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1738.10 Mnesia/ETS ��� . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1748.11 Erlang ���� . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 174

9 ���� (Clustering) 1759.1 Erlang/OTP ����� . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1759.2 EMQ X ������ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1779.3 �������� . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1789.4 ��������� . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1799.5 ��������� . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 181

iii

9.6 �������� . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1819.7 �����(Session) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1829.8 ����� . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 182

10 ���� (Deployment) 18310.1 LB (����) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18310.2 EMQ X �� . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18410.3 ��(QingCloud) �� . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18410.4 ���(AWS)�� . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18510.5 ����� . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18610.6 ������ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 186

11 ���� (Tuning Guide) 18911.1 Linux ������ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18911.2 TCP ������� . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19011.3 Erlang ����� . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19111.4 EMQ X ������� . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19111.5 ������� . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 191

12 ���� (Changes) 19312.1 3.1.1 �� . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19312.2 3.1.0 �� . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19412.3 3.1-rc.3 �� . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19412.4 3.1-rc.2 �� . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19612.5 3.1-rc.1 �� . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19712.6 3.1-beta.3 �� . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19912.7 3.1-beta.2 �� . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19912.8 3.1-beta.1 �� . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20112.9 3.0.1 �� . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20212.10 3.0.0 �� . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20412.11 3.0-rc.5 �� . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20512.12 3.0-rc.4 �� . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20612.13 3.0-rc.3 �� . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20812.14 3.0-rc.2 �� . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20912.15 3.0-rc.1 �� . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20912.16 3.0-Beta.4 �� . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21012.17 3.0-Beta.3 �� . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21212.18 3.0-Beta.2 �� . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21412.19 3.0-Beta.1 �� . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21512.20 2.3.11 �� . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21712.21 2.3.10 �� . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21812.22 2.3.9 �� . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21812.23 2.3.8 �� . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21812.24 2.3.7 �� . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21912.25 2.3.6 �� . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21912.26 2.3.5 �� . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21912.27 2.3.4 �� . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22012.28 2.3.3 �� . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22012.29 2.3.2 �� . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22112.30 2.3.1 �� . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22212.31 2.3.0 �� “Passenger’s Log” . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22312.32 2.3-rc.2 �� . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22412.33 2.3-rc.1 �� . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22412.34 2.3-beta.4 �� . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 225

iv

12.35 2.3-beta.3 �� . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22612.36 2.3-beta.3 �� . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22612.37 2.3-beta.2 �� . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22612.38 2.3-beta.1 �� . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22712.39 2.2 ��� “Nostalgia” . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22912.40 2.2-rc.2 �� . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22912.41 2.2-rc.1 �� . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22912.42 2.2-beta.3 �� . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23012.43 2.2-beta.2 �� . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23012.44 2.2-beta.1 �� . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23112.45 2.1.2 �� . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23312.46 2.1.1 �� . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23312.47 2.1.0 �� . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23312.48 2.1.0-rc.2 �� . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23412.49 2.1.0-rc.1 �� . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23412.50 2.1.0-beta.2 �� . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23412.51 2.1.0-beta.1 �� . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23412.52 2.1-beta �� . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23512.53 2.0.7 �� . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23712.54 2.0.6 �� . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23712.55 2.0.5 �� . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23712.56 2.0.4 �� . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23712.57 2.0.3 �� . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23812.58 2.0.2 �� . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23812.59 2.0.1 �� . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23812.60 2.0 ��� “����” . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23812.61 2.0-rc.3 �� . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24112.62 2.0-rc.3 �� . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24112.63 2.0-rc.2 �� . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24112.64 2.0-rc.1 �� . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24212.65 2.0-beta.3 �� . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24212.66 2.0-beta.2 �� . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24312.67 2.0-beta.1 �� . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24312.68 1.1.3 �� . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24612.69 1.1.2 �� . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24612.70 1.1.1 �� . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24612.71 1.1 �� . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24612.72 1.0.2 �� . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24812.73 1.0.1 �� . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24812.74 1.0 (���) �� . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24812.75 0.17.1-beta �� . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24912.76 0.17.0-beta �� . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24912.77 0.16.0-beta �� . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25012.78 0.15.0-beta �� . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25112.79 0.14.1-beta �� . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25112.80 0.14.0-beta �� . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25112.81 0.13.1-beta �� . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25212.82 0.13.0-beta �� . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25312.83 0.12.3-beta �� . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25412.84 0.12.2-beta �� . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25412.85 0.12.1-beta �� . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25412.86 0.12.0-beta �� . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25412.87 0.11.0-beta �� . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25512.88 0.10.4-beta �� . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 255

v

12.89 0.10.3-beta �� . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25612.90 0.10.2-beta �� . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25612.91 0.10.1-beta �� . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25612.92 0.10.0-beta �� . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25612.93 0.9.3-alpha �� . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25712.94 0.9.2-alpha �� . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25712.95 0.9.1-alpha �� . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25712.96 0.9.0-alpha �� . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25812.97 0.8.6-beta �� . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25812.98 0.8.5-beta �� . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25912.99 0.8.4-beta �� . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25912.1000.8.3-beta �� . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25912.1010.8.2-alpha �� . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25912.1020.8.1-alpha �� . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25912.1030.8.0-alpha �� . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25912.1040.7.1-alpha �� . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26012.1050.7.0-alpha �� . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26012.1060.6.2-alpha �� . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26112.1070.6.1-alpha �� . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26112.1080.6.0-alpha �� . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26112.1090.5.5-beta �� . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26212.1100.5.4-alpha �� . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26212.1110.5.3-alpha �� . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26212.1120.5.2-alpha �� . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26212.1130.5.1-alpha �� . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26312.1140.5.0-alpha �� . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26312.1150.4.0-alpha �� . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26312.1160.3.4-beta �� . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26412.1170.3.3-beta �� . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26412.1180.3.2-beta �� . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26412.1190.3.1-beta �� . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26412.1200.3.0-beta �� . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26412.1210.3.0-alpha �� . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26512.1220.2.1-beta �� . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26512.1230.2.0 �� . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26512.1240.1.5 �� . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26612.1250.1.4 �� . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26612.1260.1.3 �� . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26612.1270.1.2 �� . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26612.1280.1.1 �� . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26612.1290.1.0 �� . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 266

13 ���� (Upgrade) 26713.1 ���3.1�� . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26713.2 2.0���2.0.3�� . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26713.3 ���2.0�� . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26713.4 ���1.1.2�� . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 268

14 ���� (Protocol) 26914.1 MQTT�� . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26914.2 MQTT-SN �� . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27614.3 LWM2M �� . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 277

vi

EMQ X - ����� MQTT �����, �� 3.1.0

EMQ X R3.1 (Erlang/Enterprise/Elastic MQTT Broker) ��� Erlang/OTP ������������������������������ MQTT ������

��: 3.0 ���� emqttd ����������� EMQ X

EMQ X ��������� MQTT V3.1/V3.1.1/V5.0 ������������ MQTT-SN �WebSocket�CoAP�LwM2M�Stomp ����TCP/UDP ���EMQ X ����������100�������������

EMQ X ������������� (C1000K+) ���������������������������������������������������������������� MQTT ������

��: MQTT-SN�CoAP ����2.0-rc.1�����LwM2M�LoRaWan ��� 3.0 �����

EMQ X R3.1 ������:

Contents 1

EMQ X - ����� MQTT �����, �� 3.1.0

2 Contents

CHAPTER 1

���� (Get Started)

1.1 EMQ X R3.1 �������

EMQ X (Erlang/Enterprise/Elastic MQTT Broker) ��� Erlang/OTP ���������� MQTT ������Erlang/OTP�������(Soft-Realtime)����(Low-Latency)����(Distributed) ������MQTT ����(Lightweight)�������(PubSub) ���������

EMQ X ����� ��/���/�� ����������������������������:

1. �������� MQTT �������������������

2. ��������������������������������

3. ���������������������������������

4. ����������MQTT�MQTT-SN�CoAP�LwM2M��� TCP/UDP �����

1.2 MQTT ��������

MQTT ��� ��(Publish)/��(Subscribe) ��������������� HTTP � ��(Request)/��(Response) ����������

���(Subscriber) �� �����(Broker) ���� ��(Topic) �������������������������������

��(Topic)� ‘/’ ����������������� ‘+’ � ‘#’ ������ �����(Topic Filters); �������� ���(Topic Names) ��:

sensor/1/temperature

chat/room/subject

presence/user/feng

sensor/1/#

sensor/+/temperature(����)

3

EMQ X - ����� MQTT �����, �� 3.1.0

(���)

uber/drivers/joe/inbox

��: �: ‘+’ �������’#’ ������(�����)�

��: �: ���(Publisher) ��� ‘���’ ��������(Subscriber) ������� ‘�����’ ����������

1.3 EMQ X R3.1 ���������

• ��� MQTT V3.1/V3.1.1 �V5.0������

• QoS0, QoS1, QoS2 ����

• �����������

• Retained ����

• Last Will ����

• TCP/SSL ����

• MQTT/WebSocket/SSL ��

• HTTP��������

• $SYS/# ������

• ��������������

• ��� ID � IP ������

• ���������

• LDAP ��

• Redis�MySQL�PostgreSQL�MongoDB�HTTP ����

• ��� Cookie ��

• ����� ID�IP �����������(ACL)

• ��������(Cluster)

• �� manual�mcast�dns�etcd�k8s ���������

• ��������

• ������

• ������

• �������

• ��������(Bridge)

• MQTT Broker ����

• Stomp ����

• MQTT-SN ����

4 Chapter 1. ���� (Get Started)

EMQ X - ����� MQTT �����, �� 3.1.0

• CoAP ����

• Stomp/SockJS ��

• �� Publish ($delay/topic)

• Flapping ��

• �����

• ����($share/<group>/topic)

• TLS/PSK ��

• ������

1.4 ������� EMQ

EMQ X ��������� CentOS�Ubuntu�Debian�FreeBSD�macOS�Windows�openSUSE ������ Docker ���

����: https://www.emqx.io/downloads/broker?osType=Linux

������������������� Mac ��:

unzip emqx-macosx-v3.1.0.zip && cd emqx

# ��emqx./bin/emqx start

# ������./bin/emqx_ctl status

# ��emqx./bin/emqx stop

EMQ X ����MQTT ������ 1883 �������������� log/ ���

EMQ X ���� Dashboard ����� Web ����������� Web ���������������������(Connections)���(Sessions)���(Topics)���(Subscriptions)���(Plugins)��

�����: http://127.0.0.1:18083������: admin����public

1.4. ������� EMQ 5

EMQ X - ����� MQTT �����, �� 3.1.0

1.5 �� MQTT �����

GitHub: https://github.com/emqtt

emqttc Erlang MQTT ����CocoaMQTT Swift �� MQTT ����QMQTT QT �� MQTT ����emqtt_benchmark MQTT ������

Eclipse Paho: https://www.eclipse.org/paho/

MQTT.org: https://github.com/mqtt/mqtt.github.io/wiki/libraries

6 Chapter 1. ���� (Get Started)

CHAPTER 2

���� (Installation)

EMQ X ������������ Linux�FreeBSD�macOS�Windows � openSUSE �����

��: ������ Linux ������� Windows ����

2.1 EMQ X �����

EMQ X ������������ CentOS�Ubuntu�Debian�FreeBSD�macOS�Windows �openSUSE ������ Docker ���

����: https://www.emqx.io/downloads

2.2 CentOS

• CentOS6.X

• CentOS7.X

2.2.1 ������� EMQ X

1. ���������

$ sudo yum install -y yum-utils device-mapper-persistent-data lvm2

2. ��������������� CentOS7 ��

$ sudo yum-config-manager --add-repo https://repos.emqx.io/emqx-ce/redhat/centos/7/↪→emqx-ce.repo

3. ������� EMQ X

7

EMQ X - ����� MQTT �����, �� 3.1.0

$ sudo yum install emqx

��: ������ GPG ���������� fc84 1ba6 3775 5ca8 487b 1e3c c0b4 0946 3e64 0d53�������������

4. ������� EMQ X

1. ������

$ yum list emqx --showduplicates | sort -r

emqx.x86_64 3.1.0-1.el7 emqx-stableemqx.x86_64 3.0.1-1.el7 emqx-stableemqx.x86_64 3.0.0-1.el7 emqx-stable

2. ��������������������� 3.1.0

$ sudo yum install emqx-3.1.0

5. �� EMQ X

• ����

$ emqx startemqx 3.1.0 is started successfully!

$ emqx_ctl statusNode '[email protected]' is startedemqx v3.1.0 is running

• systemctl ��

$ sudo systemctl start emqx

• service ��

$ sudo service emqx start

2.2.2 �� rpm ��� EMQ X

1. �� emqx.io � github �� CentOS ����������� EMQ X ��� rpm ��

2. �� EMQ X

$ sudo rpm -ivh emqx-centos7-v3.1.0.x86_64.rpm

3. �� EMQ X

• ����

$ emqx startemqx 3.1.0 is started successfully!

$ emqx_ctl status(����)

8 Chapter 2. ���� (Installation)

EMQ X - ����� MQTT �����, �� 3.1.0

(���)

Node '[email protected]' is startedemqx v3.1.0 is running

• systemctl ��

$ sudo systemctl start emqx

• service ��

$ sudo service emqx start

2.2.3 �� zip ��� EMQ X

1. �� emqx.io � github �� Centos ����������� EMQ X ��� zip ��

2. �����

$ unzip emqx-centos7-v3.1.0.zip

3. �� EMQ X

$ ./bin/emqx startemqx 3.1.0 is started successfully!

$ ./bin/emqx_ctl statusNode '[email protected]' is startedemqx v3.1.0 is running

2.3 Ubuntu

• Bionic 18.04 (LTS)

• Xenial 16.04 (LTS)

• Trusty 14.04 (LTS)

• Precise 12.04 (LTS)

2.3.1 ������� EMQ X

1. ���������

$ sudo apt update && sudo apt install -y \apt-transport-https \ca-certificates \curl \gnupg-agent \software-properties-common

2. �� EMQ X ��� GPG ��

2.3. Ubuntu 9

EMQ X - ����� MQTT �����, �� 3.1.0

$ curl -fsSL https://repos.emqx.io/gpg.pub | sudo apt-key add -

����

$ sudo apt-key fingerprint 3E640D53

pub rsa2048 2019-04-10 [SC]FC84 1BA6 3775 5CA8 487B 1E3C C0B4 0946 3E64 0D53

uid [ unknown] emqx team <[email protected]>

3. �������� stable ���� ����� unstable �������������� stable ������ unstable�

$ sudo add-apt-repository \"deb [arch=amd64] https://repos.emqx.io/emqx-ce/deb/ubuntu/ \$(lsb_release -cs) \stable"

��: lsb_release -cs ����� Ubuntu ��������� xenial� ����� Linux Mint �������������� $(lsb_release -cs) ������ Ubuntu���� ���������� Linux Mint Tessa������ bionic� EMQ X ������������ Ubuntu ����������

4. �� apt ���

$ sudo apt update

5. ������� EMQ X

$ sudo apt install emqx

��: ������ EMQ X ��������� apt install � apt update ��������������������� EMQ X���������������������

6. ������� EMQ X

1. ������

$ sudo apt-cache madison emqx

emqx | 3.1.0 | https://repos.emqx.io/emqx-ce/deb/ubuntu bionic/stable␣↪→amd64 Packagesemqx | 3.0.1 | https://repos.emqx.io/emqx-ce/deb/ubuntu bionic/stable␣↪→amd64 Packagesemqx | 3.0.0 | https://repos.emqx.io/emqx-ce/deb/ubuntu bionic/stable␣↪→amd64 Packages

2. ��������������������� 3.1.0

$ sudo apt install emqx=3.1.0

7. �� EMQ X

• ����

10 Chapter 2. ���� (Installation)

EMQ X - ����� MQTT �����, �� 3.1.0

$ emqx startemqx 3.1.0 is started successfully!

$ emqx_ctl statusNode '[email protected]' is startedemqx v3.1.0 is running

• systemctl ��

$ sudo systemctl start emqx

• service ��

$ sudo service emqx start

2.3.2 �� deb ��� EMQ X

1. �� emqx.io � github �� Ubuntu ����������� EMQ X ��� deb ��

2. �� EMQ X

$ sudo dpkg -i emqx-ubuntu18.04-v3.1.0_amd64.deb

3. �� EMQ X

• ����

$ emqx startemqx 3.1.0 is started successfully!

$ emqx_ctl statusNode '[email protected]' is startedemqx v3.1.0 is running

• systemctl ��

$ sudo systemctl start emqx

• service ��

$ sudo service emqx start

2.3.3 �� zip ��� EMQ X

1. �� emqx.io � github �� Ubuntu ����������� EMQ X ��� zip ��

2. �����

$ unzip emqx-ubuntu18.04-v3.1.0.zip

3. �� EMQ X

2.3. Ubuntu 11

EMQ X - ����� MQTT �����, �� 3.1.0

$ ./bin/emqx startemqx 3.1.0 is started successfully!

$ ./bin/emqx_ctl statusNode '[email protected]' is startedemqx v3.1.0 is running

2.4 Debian

• Stretch (Debian 9)

• Jessie (Debian 8)

2.4.1 ������� EMQ X

1. ���������

$ sudo apt update && sudo apt install -y \apt-transport-https \ca-certificates \curl \gnupg-agent \software-properties-common

2. �� EMQ X ��� GPG ��

$ curl -fsSL https://repos.emqx.io/gpg.pub | sudo apt-key add -

����

$ sudo apt-key fingerprint 3E640D53

pub rsa2048 2019-04-10 [SC]FC84 1BA6 3775 5CA8 487B 1E3C C0B4 0946 3E64 0D53

uid [ unknown] emqx team <[email protected]>

3. �������� stable ���� ����� unstable ��������������� stable ������ unstable�

$ sudo add-apt-repository \"deb [arch=amd64] https://repos.emqx.io/emqx-ce/deb/debian/ \$(lsb_release -cs) \stable"

��: lsb_release -cs ����� Debian ��������� helium� ����� BunsenLabs Linux �������������� $(lsb_release -cs) ������Debian ���� ���������� BunsenLabs Linux Helium������ stretch� EMQ X ������������ Debian ����������

4. �� apt ���

$ sudo apt update

12 Chapter 2. ���� (Installation)

EMQ X - ����� MQTT �����, �� 3.1.0

5. ������� EMQ X

$ sudo apt install emqx

��: ������ EMQ X ��������� apt install � apt update ��������������������� EMQ X���������������������

6. ������� EMQ X

1. ������

$ sudo apt-cache madison emqx

emqx | 3.1.0 | https://repos.emqx.io/emqx-ce/deb/debian stretch/stable␣↪→amd64 Packagesemqx | 3.0.1 | https://repos.emqx.io/emqx-ce/deb/debian stretch/stable␣↪→amd64 Packagesemqx | 3.0.0 | https://repos.emqx.io/emqx-ce/deb/debian stretch/stable␣↪→amd64 Packages

2. ��������������������� 3.1.0

$ sudo apt install emqx=3.1.0

7. �� EMQ X

• ����

$ emqx startemqx 3.1.0 is started successfully!

$ emqx_ctl statusNode '[email protected]' is startedemqx v3.1.0 is running

• systemctl ��

$ sudo systemctl start emqx

• service ��

$ sudo service emqx start

2.4.2 �� deb ��� EMQ X

1. �� emqx.io � github �� Debian ����������� EMQ X ��� deb ��

2. �� EMQ X

$ sudo dpkg -i emqx-debian9-v3.1.0_amd64.deb

3. �� EMQ X

• ����

2.4. Debian 13

EMQ X - ����� MQTT �����, �� 3.1.0

$ emqx startemqx 3.1.0 is started successfully!

$ emqx_ctl statusNode '[email protected]' is startedemqx v3.1.0 is running

• systemctl ��

$ sudo systemctl start emqx

• service ��

$ sudo service emqx start

2.4.3 �� zip ��� EMQ X

1. �� emqx.io � github �� Debian ����������� EMQ X ��� zip ��

2. �����

$ unzip emqx-debian9-v3.1.0.zip

3. �� EMQ X

$ ./bin/emqx startemqx 3.1.0 is started successfully!

$ ./bin/emqx_ctl statusNode '[email protected]' is startedemqx v3.1.0 is running

2.5 macOS

2.5.1 �� Homebrew ��

1. �� EMQ X � tap

$ brew tap emqx/emqx

2. �� EMQ X

$ brew install emqx

3. �� EMQ X

$ emqx startemqx 3.1.0 is started successfully!

$ emqx_ctl status(����)

14 Chapter 2. ���� (Installation)

EMQ X - ����� MQTT �����, �� 3.1.0

(���)

Node '[email protected]' is startedemqx v3.1.0 is running

2.5.2 �� zip ��� EMQ X

1. �� emqx.io � github��� EMQ X ����������� zip ��

2. �����

$ unzip emqx-macos-v3.1.0.zip

3. �� EMQ X

$ ./bin/emqx startemqx 3.1.0 is started successfully!

$ ./bin/emqx_ctl statusNode '[email protected]' is startedemqx v3.1.0 is running

2.6 Windows

1. �� emqx.io � github �� Windows ����������� .zip ��

2. �����

3. �� Windows ������cd ������ �� EMQ X�

cd emqx/binemqx start

2.7 openSUSE

• openSUSE leap

2.7.1 ������� EMQ X

1. �� GPG ������

$ curl -L -o /tmp/gpg.pub https://repos.emqx.io/gpg.pub$ sudo rpmkeys --import /tmp/gpg.pub

2. �������

$ sudo zypper ar -f -c https://repos.emqx.io/emqx-ce/redhat/opensuse/leap/stable␣↪→emqx

3. ������� EMQ X

2.6. Windows 15

EMQ X - ����� MQTT �����, �� 3.1.0

$ sudo zypper in emqx

4. ������� EMQ X

1. ������

$ sudo zypper pa emqx

Loading repository data...Reading installed packages...S | Repository | Name | Version | Arch--+------------+------+----------+-------| emqx | emqx | 3.1.0-1 | x86_64| emqx | emqx | 3.0.1-1 | x86_64| emqx | emqx | 3.0.0-1 | x86_64

2. �� Version ��������� 3.1.0

$ sudo zypper in emqx-3.1.0

5. �� EMQ X

• ����

$ emqx startemqx 3.1.0 is started successfully!

$ emqx_ctl statusNode '[email protected]' is startedemqx v3.1.0 is running

• systemctl ��

$ sudo systemctl start emqx

• service ��

$ sudo service emqx start

2.7.2 �� rpm ��� EMQ X

1. �� emqx.io � github �� openSUSE��������� EMQ X ��� rpm ��

2. �� EMQ X������������� EMQ X �������

$ sudo rpm -ivh emqx-opensuse-v3.1.0.x86_64.rpm

3. �� EMQ X

• ����

$ emqx startemqx 3.1.0 is started successfully!

$ emqx_ctl status(����)

16 Chapter 2. ���� (Installation)

EMQ X - ����� MQTT �����, �� 3.1.0

(���)

Node '[email protected]' is startedemqx v3.1.0 is running

• systemctl ��

$ sudo systemctl start emqx

• service ��

$ sudo service emqx start

2.7.3 �� zip ��� EMQ X

1. �� emqx.io � github �� openSUSE��������� EMQ X ��� zip ��

2. �����

$ unzip emqx-opensuse-v3.1.0.zip

3. �� EMQ X

$ ./bin/emqx startemqx 3.1.0 is started successfully!

$ ./bin/emqx_ctl statusNode '[email protected]' is startedemqx v3.1.0 is running

2.8 FreeBSD

• FreeBSD 12

2.8.1 �� zip ��� EMQ X

1. �� emqx.io � github �� FreeBSD��������� EMQ X ��� zip ��

2. �����

$ unzip emqx-freebsd12-v3.1.0.zip

3. �� EMQ X

$ ./bin/emqx startemqx 3.1.0 is started successfully!

$ ./bin/emqx_ctl statusNode '[email protected]' is startedemqx v3.1.0 is running

2.8. FreeBSD 17

EMQ X - ����� MQTT �����, �� 3.1.0

2.9 Docker

1. �� docker ��

• �� Docker Hub ��

$ docker pull emqx/emqx:v3.1.0

• �� emqx.io � github ���� docker ��������

$ wget -O emqx-docker.zip https://www.emqx.io/downloads/v3/latest/emqx-docker.↪→zip$ unzip emqx-docker.zip$ docker load < emqx-docker-v3.1.0

2. �� docker ��

$ docker run -d --name emqx31 -p 1883:1883 -p 8083:8083 -p 8883:8883 -p 8084:8084 -↪→p 18083:18083 emqx/emqx:v3.1.0

���� EMQ X Docker ������ Docker Hub � EMQ X Docker

2.10 ������

2.10.1 ����

EMQ X ������� Erlang/OTP ���������� GitHub ����������� Erlang ��� git ����

��: EMQ X �� Erlang R21.2+ ��

Erlang ��: http://www.erlang.org/

Git ���: http://www.git-scm.com/

2.10.2 ����EMQ X

1. ����

$ git clone -b v3.1.0 https://github.com/emqx/emqx-rel.git

2. ������

$ export EMQX_DEPS_DEFAULT_VSN=v3.1.0

3. ��

$ cd emqx-rel && make

4. �� EMQ X

18 Chapter 2. ���� (Installation)

EMQ X - ����� MQTT �����, �� 3.1.0

$ cd emqx-rel/_rel/emqx$ ./bin/emqx startemqx 3.1.0 is started successfully!

$ ./bin/emqx_ctl statusNode '[email protected]' is startedemqx v3.1.0 is running

2.11 Windows ������

Erlang ��: http://www.erlang.org/

MSYS2 ��: http://www.msys2.org/

MSYS2 �������� MSYS2 �� pacman ������� Git� Make ����

pacman -S git make

���������clone ������

git clone -b win30 https://github.com/emqx/emqx-rel.git

cd emqx-relx && make

cd _rel/emqx && ./bin/emqx console

�������� EMQ ���

cd _rel/emqx/binemqx console

2.11. Windows ������ 19

EMQ X - ����� MQTT �����, �� 3.1.0

20 Chapter 2. ���� (Installation)

CHAPTER 3

���� (User Guide)

3.1 ����

����: https://www.emqx.io/downloads/broker?osType=Linux

������������������� macOS ��:

unzip emqx-macosx-v3.1.0.zip && cd emqx

# ��emqx./bin/emqx start

# ������./bin/emqx_ctl status

EMQ X ���������� TCP ����:

1883 MQTT ����8883 MQTT/SSL ��8083 MQTT/WebSocket ��8080 HTTP API ��18083 Dashboard �������

3.2 MQTT ����

MQTT ��������������������������������� MQTT v3.1.1 � v5.0:

21

EMQ X - ����� MQTT �����, �� 3.1.0

EMQ X �������������� MQTT ����������� ��(Publish)/��(Subscribe) �������

MQTT ����: https://github.com/mqtt/mqtt.github.io/wiki/libraries

���mosquitto_sub/pub ���������:

mosquitto_sub -h 127.0.0.1 -p 1883 -t topic -q 2mosquitto_pub -h 127.0.0.1 -p 1883 -t topic -q 1 -m "Hello, MQTT!"

3.3 ��/����

EMQ X ����� ���� � ���� ���������(Plugins)����������� emqx_auth_<name> ����

� EMQ X ������������

1. ����: EMQ X ���������������������������������

2. ����: EMQ X ������� ��(Publish)/��(Subscribe) ����� ��/�� ����

3.3.1 ��(Authentication)

EMQ X ���������������(Plugins)��������������ClientID ������

����������(Anonymous)������������������������:

---------------- ---------------- ------------Client --> | Username�� | -ignore-> | ClientID�� | -ignore-> | ���� |

---------------- ---------------- ------------| | |\|/ \|/ \|/

allow | deny allow | deny allow | deny

������

etc/emqx.conf ��������:

22 Chapter 3. ���� (User Guide)

EMQ X - ����� MQTT �����, �� 3.1.0

������## Value: true | falseallow_anonymous = true

3.3.2 ����(ACL)

EMQ X ������� ACL(Access Control List) �� MQTT ��������

ACL ��������:

��(Allow)|��(Deny) �(Who) ��(Subscribe)|��(Publish) ����(Topics)

MQTT �������/������EMQ X ����������������� ACL �����������:

--------- --------- ---------Client -> | Rule1 | --nomatch--> | Rule2 | --nomatch--> | Rule3 | --> Default

--------- --------- ---------| | |

match match match\|/ \|/ \|/

allow | deny allow | deny allow | deny

��������

EMQ X ������������� etc/emqx.conf ���:

## ���� ACL ��������������## Value: allow | denyacl_nomatch = allow

## ���� ACL �������## Value: File Nameacl_file = etc/acl.conf

ACL ����� etc/acl.conf�EMQ X ��������:

%% �� 'dashboard' ���� '$SYS/#'{allow, {user, "dashboard"}, subscribe, ["$SYS/#"]}.

%% ��������������{allow, {ipaddr, "127.0.0.1"}, pubsub, ["$SYS/#", "#"]}.

%% ���������������� '$SYS/#' � '#' ��{deny, all, subscribe, ["$SYS/#", {eq, "#"}]}.

%% �������������{allow, all}.

EMQ X ���������:

3.3. ��/���� 23

EMQ X - ����� MQTT �����, �� 3.1.0

�� ��emqx_auth_clientid ClientId ��/����emqx_auth_username �������/����emqx_auth_jwt JWT ��/����emqx_auth_ldap LDAP ��/����emqx_auth_http HTTP ��/����emqx_auth_mysql MySQ L��/����emqx_auth_pgsql Postgre ��/����emqx_auth_redis Redis ��/����emqx_auth_mongo MongoDB ��/����

��������������������� ���� (Plugins) �������

��: auth ��������������������������������������������������

�� EMQ X ����� PSK (Pre-shared Key) ������������������������ ���� �������� SSL ������������� Pre-shared Key �emqx_psk_file

3.4 ���� (Shared Subscription)

EMQ X R3.0 ����������������������(Shared Subscription)����������:

---------| | --Msg1--> Subscriber1

Publisher--Msg1,Msg2,Msg3-->| EMQ X | --Msg2--> Subscriber2| | --Msg3--> Subscriber3---------

������������:

���� ����$queue/ mosquitto_sub -t ‘$queue/topic’$share/<group>/ mosquitto_sub -t ‘$share/group/topic’

��:

mosquitto_sub -t '$share/group/topic'

mosquitto_pub -t 'topic' -m msg -q 2

EMQ X ��������������

�� ��random �����������round_robin �����sticky ����������hash ������ ClientId

24 Chapter 3. ���� (User Guide)

EMQ X - ����� MQTT �����, �� 3.1.0

��: ��������������������������� Session ������

3.5 ���� (Bridge)

3.5.1 EMQ X �����

�� ���� EMQ X ������������������������ MQTT Broker�

�� � �� ����������������������������� MQTT ���

�� EMQ X ��������:

• RPC ���RPC ����� EMQ X Broker ����������������������

• MQTT ���MQTT ��������������������������

��������:

�� EMQ X ����������������:

--------- --------- ---------Publisher --> | Node1 | --Bridge Forward--> | Node2 | --Bridge Forward--> | Node3 | -->␣↪→Subscriber--------- --------- ---------

� EMQ X ������ etc/emqx.conf ��� bridge�EMQ X ����� name ������ bridge���:

## Bridge address: node name for local bridge, host:port for remote.bridge.aws.address = 127.0.0.1:1883

����������� aws � bridge ���� MQTT ������ 127.0.0.1:1883 �� MQTT ���

������� bridge ����������������������� name ������ bridge.$name.address �� $name ���� bridge ����

��������������� RPC/MQTT ����������������(sensor)����������������������� EMQ X ���

3.5. ���� (Bridge) 25

EMQ X - ����� MQTT �����, �� 3.1.0

�� �� MQTT ��emqx1 [email protected] 1883emqx2 [email protected] 1883

3.5.2 EMQ X �� RPC ����

��� RPC ������������ RPC ���������������:

## ����� ������nodename@host���� RPC ����� host:port �� MQTT ��bridge.emqx2.address = [email protected]

## �������bridge.emqx2.forwards = sensor1/#,sensor2/#

## ��� mountpoint(���)bridge.emqx2.mountpoint = bridge/emqx2/${node}/

forwards �������������� forwards ��������������������

mountpoint ��������������������������� sensor1/hello ����EMQX ����������������� bridge/emqx2/[email protected]/sensor1/hello�

RPC ������

1. RPC ������������������������������������������

2. RPC ������� EMQ X ���������� EMQ X ���� MQTT Broker ��

3. RPC ����� MQTT ���������� MQTT ���

3.5.3 EMQ X �� MQTT ����

EMQ X ���� MQTT Bridge ����� MQTT Broker �������� MQTT Broker ���������

EMQ X � MQTT Bridge ��: �� MQTT ��������� MQTT Broker���� MQTT Bridge ��������� MQTT �������������

## ����bridge.emqx2.address = 192.168.1.2:1883

## �������## ���: mqttv3 | mqttv4 | mqttv5bridge.emqx2.proto_ver = mqttv4

## ���� client_idbridge.emqx2.client_id = bridge_emq

## ���� clean_start ��## �: �� MQTT Broker ��� clean_start ��� `true`bridge.emqx2.clean_start = true

## ���� username ��bridge.emqx2.username = user

## ���� password ��bridge.emqx2.password = passwd

(����)

26 Chapter 3. ���� (User Guide)

EMQ X - ����� MQTT �����, �� 3.1.0

(���)

## ������� ssl ��������bridge.emqx2.ssl = off

## ��� SSL ��� CA �� (PEM��)bridge.emqx2.cacertfile = etc/certs/cacert.pem

## ��� SSL ��� SSL ��bridge.emqx2.certfile = etc/certs/client-cert.pem

## ��� SSL �������bridge.emqx2.keyfile = etc/certs/client-key.pem

## SSL ����bridge.emqx2.ciphers = ECDHE-ECDSA-AES256-GCM-SHA384,ECDHE-RSA-AES256-GCM-SHA384

## TLS PSK �����## �� 'listener.ssl.external.ciphers' � 'listener.ssl.external.psk_ciphers' ������#### See 'https://tools.ietf.org/html/rfc4279#section-2'.## bridge.emqx2.psk_ciphers = PSK-AES128-CBC-SHA,PSK-AES256-CBC-SHA,PSK-3DES-EDE-CBC-SHA,↪→PSK-RC4-SHA

## ��������bridge.emqx2.keepalive = 60s

## ��� TLS ��bridge.emqx2.tls_versions = tlsv1.2,tlsv1.1,tlsv1

## �����������bridge.emqx2.forwards = sensor1/#,sensor2/#

## ���(mountpoint)bridge.emqx2.mountpoint = bridge/emqx2/${node}/

## �������bridge.emqx2.subscription.1.topic = cmd/topic1

## ������� QoSbridge.emqx2.subscription.1.qos = 1

## �������## ��: 30�bridge.emqx2.reconnect_interval = 30s

## QoS1/QoS2 �������bridge.emqx2.retry_interval = 20s

## Inflight ��.bridge.emqx2.max_inflight_batches = 32

3.5. ���� (Bridge) 27

EMQ X - ����� MQTT �����, �� 3.1.0

3.5.4 EMQ X ������

EMQ X � Bridge ������������������ RPC ��� MQTT ���� Bridge ������������������� forwards����������������������������������������������������

## emqx_bridge ���� batch �����bridge.emqx2.queue.batch_count_limit = 32

## emqx_bridge ���� batch ������bridge.emqx2.queue.batch_bytes_limit = 1000MB

## �� replayq ��������������������� replayq## ��� `mem-only` �����������������bridge.emqx2.queue.replayq_dir = data/emqx_emqx2_bridge/

## Replayq �����bridge.emqx2.queue.replayq_seg_bytes = 10MB

bridge.emqx2.queue.replayq_dir ����� bridge �������������

bridge.emqx2.queue.replayq_seg_bytes ����������������������������������������������������������

3.5.5 EMQ X ��������

�� CLI ���

$ cd emqx1/ && ./bin/emqx_ctl bridgesbridges list # List bridgesbridges start <Name> # Start a bridgebridges stop <Name> # Stop a bridgebridges forwards <Name> # Show a bridge forward topicbridges add-forward <Name> <Topic> # Add bridge forward topicbridges del-forward <Name> <Topic> # Delete bridge forward topicbridges subscriptions <Name> # Show a bridge subscriptions topicbridges add-subscription <Name> <Topic> <Qos> # Add bridge subscriptions topic

���� bridge ��

$ ./bin/emqx_ctl bridges listname: emqx status: Stopped

���� bridge

$ ./bin/emqx_ctl bridges start emqxStart bridge successfully.

���� bridge

$ ./bin/emqx_ctl bridges stop emqxStop bridge successfully.

���� bridge �����

28 Chapter 3. ���� (User Guide)

EMQ X - ����� MQTT �����, �� 3.1.0

$ ./bin/emqx_ctl bridges forwards emqxtopic: topic1/#topic: topic2/#

���� bridge �����

$ ./bin/emqx_ctl bridges add-forwards emqx 'topic3/#'Add-forward topic successfully.

���� bridge �����

$ ./bin/emqx_ctl bridges del-forwards emqx 'topic3/#'Del-forward topic successfully.

���� bridge ���

$ ./bin/emqx_ctl bridges subscriptions emqxtopic: cmd/topic1, qos: 1topic: cmd/topic2, qos: 1

���� bridge �����

$ ./bin/emqx_ctl bridges add-subscription emqx 'cmd/topic3' 1Add-subscription topic successfully.

���� bridge �����

$ ./bin/emqx_ctl bridges del-subscription emqx 'cmd/topic3'Del-subscription topic successfully.

�: ������� Bridge ����������� Bridge ������� emqx.conf ��������� bridge.${name}.config �� name ���

3.6 HTTP ����

EMQ X ���������� HTTP ����������� Web ����������� MQTT ��:

HTTP POST http://host:8080/api/v3/mqtt/publish

Web ����� PHP/Java/Python/NodeJS � Ruby on Rails���� HTTP POST ���� MQTT ��:

curl -v --basic -u user:passwd -H "Content-Type: application/json" -d \'{"qos":1, "retain": false, "topic":"world", "payload":"test" , "client_id": "C_↪→1492145414740"}' \-k http://localhost:8080/api/v3/mqtt/publish

HTTP ����:

�� ��client_id MQTT ��� IDqos QoS: 0 | 1 | 2retain Retain: true | falsetopic ��(Topic)payload ����

3.6. HTTP ���� 29

EMQ X - ����� MQTT �����, �� 3.1.0

��: HTTP ������ Basic ������� user � password ���� Dashboard �� Applications �� AppId ���

3.7 MQTT WebSocket ��

EMQ X ��� WebSocket ���Web �������� WebSocket ������:

WebSocket URI: ws(s)://host:8083/mqttSec-WebSocket-Protocol: ‘mqttv3.1’ or ‘mqttv3.1.1’

Dashboard ������� MQTT WebSocket �������:

http://127.0.0.1:18083/#/websocket

3.8 $SYS-����

EMQ X ������������������������������� � $SYS/ �������

$SYS ����� $SYS/brokers/{node}/ ��� {node} ����� ��/�� ����������:

$SYS/brokers/[email protected]/version

$SYS/brokers/[email protected]/uptime

��: ����� localhost � MQTT ����� $SYS ������ etc/acl.config ���������

$SYS ����������� etc/emqx.conf ��:

## System interval of publishing $SYS messages.#### Value: Duration## Default: 1m, 1 minutebroker.sys_interval = 1m

3.8.1 ������

�� ��$SYS/brokers ������$SYS/brokers/${node}/version EMQ X �����$SYS/brokers/${node}/uptime EMQ X �������$SYS/brokers/${node}/datetime EMQ X �����$SYS/brokers/${node}/sysdescr EMQ X �����

30 Chapter 3. ���� (User Guide)

EMQ X - ����� MQTT �����, �� 3.1.0

3.8.2 ��������

$SYS ����: $SYS/brokers/${node}/clients/

��(Topic) ��${clientid}/connected ��������������������${clientid}/disconnected ��������������������

‘connected’ ����� Payload ���� JSON ��:

{"clientid":"id1","username":"u","ipaddress":"127.0.0.1","connack":0,"ts":1554047291,"proto_ver":3,"proto_name":"MQIsdp","clean_start":true,"keepalive":60

}

‘disconnected’ ����� Payload ���� JSON ��:

{"clientid":"id1","username":"u","reason":"normal","ts":1554047291

}

3.8.3 ����(Statistics)

������: $SYS/brokers/${node}/stats/

�����

��(Topic) ��connections/count �������connections/max �������

����

��(Topic) ��sessions/count ������sessions/max ������sessions/persistent/count ��������sessions/persistent/max ��������

3.8. $SYS-���� 31

EMQ X - ����� MQTT �����, �� 3.1.0

����

��(Topic) ��suboptions/count ��������suboptions/max ��������subscribers/max �������subscribers/count �������subscriptions/max ������subscriptions/count ������subscriptions/shared/count ��������subscriptions/shared/max ��������

����

��(Topic) ��topics/count �� Topic ��topics/max �� Topic ��

����

��(Topic) ��routes/count �� Routes ��routes/max �� Routes ��

��: topics/count � topics/max � routes/count � routes/max ��������

3.8.4 ����/��/����

����(Topic)��: $SYS/brokers/${node}/metrics/

������

��(Topic) ��bytes/received ������bytes/sent ������

32 Chapter 3. ���� (User Guide)

EMQ X - ����� MQTT �����, �� 3.1.0

MQTT������

��(Topic) ��packets/received ���� MQTT ��packets/sent ���� MQTT ��packets/connect ���� MQTT CONNECT ��packets/connack ���� MQTT CONNACK ��packets/publish/received ���� MQTT PUBLISH ��packets/publish/sent ���� MQTT PUBLISH ��packets/puback/received ���� MQTT PUBACK ��packets/puback/sent ���� MQTT PUBACK ��packets/puback/missed ���� MQTT PUBACK ��packets/pubrec/received ���� MQTT PUBREC ��packets/pubrec/sent ���� MQTT PUBREC ��packets/pubrec/missed ���� MQTT PUBREC ��packets/pubrel/received ���� MQTT PUBREL ��packets/pubrel/sent ���� MQTT PUBREL ��packets/pubrel/missed ���� MQTT PUBREL ��packets/pubcomp/received ���� MQTT PUBCOMP ��packets/pubcomp/sent ���� MQTT PUBCOMP ��packets/pubcomp/missed ���� MQTT PUBCOMP ��packets/subscribe ���� MQTT SUBSCRIBE ��packets/suback ���� MQTT SUBACK ��packets/unsubscribe ���� MQTT UNSUBSCRIBE ��packets/unsuback ���� MQTT UNSUBACK ��packets/pingreq ���� MQTT PINGREQ ��packets/pingresp ���� MQTT PINGRESP ��packets/disconnect/received ���� MQTT DISCONNECT ��packets/disconnect/sent ���� MQTT DISCONNECT ��packets/auth ���� Auth ��

MQTT ������

��(Topic) ��messages/received ������messages/sent ������messages/expired ������messages/retained Retained ����messages/dropped ������messages/forward ��������messages/qos0/received ���� QoS0 ��messages/qos0/sent ���� QoS0 ��messages/qos1/received ���� QoS1 ��messages/qos1/sent ���� QoS1 ��messages/qos2/received ���� QoS2 ��messages/qos2/sent ���� QoS2 ��messages/qos2/expired QoS2 ������messages/qos2/dropped QoS2 ������

3.8. $SYS-���� 33

EMQ X - ����� MQTT �����, �� 3.1.0

3.8.5 Alarms - ����

����(Topic)��: $SYS/brokers/${node}/alarms/

��(Topic) ��${alarmId}/alert ������${alarmId}/clear ������

3.8.6 Sysmon - ����

����(Topic)��: $SYS/brokers/${node}/sysmon/

��(Topic) ��long_gc GC ������long_schedule ��������large_heap Heap ������busy_port Port ���busy_dist_port Dist Port ���

3.9 ��

EMQ X ����������������(Client)����������(Topic)������

�������(Client)���:

$ ./bin/emqx_ctl log primary-level debug

$ ./bin/emqx_ctl trace start client "clientid" "trace_clientid.log" debug

�������(Topic)���:

$ ./bin/emqx_ctl log primary-level debug

$ ./bin/emqx_ctl trace start topic "t/#" "trace_topic.log" debug

����:

$ ./bin/emqx_ctl trace list

����:

$ ./bin/emqx_ctl trace stop client "clientid"

$ ./bin/emqx_ctl trace stop topic "topic"

34 Chapter 3. ���� (User Guide)

CHAPTER 4

���� (Configuration)

4.1 EMQ X ����

EMQ X ������� etc/ ��������������������:

���� ��etc/emqx.conf EMQ X ���������etc/acl.conf EMQ X ��ACL������etc/plugins/*.conf EMQ X ��������

4.2 EMQ X ������

��������������EMQ X �����������

1. EMQ X 1.x ���� Erlang �������� etc/emqttd.config:

{emqttd, [%% Authentication and Authorization{access, [

%% Authetication. Anonymous Default{auth, [

%% Authentication with username, password%{username, []},

%% Authentication with clientid%{clientid, [{password, no}, {file, "etc/clients.config"}]},

Erlang ��������������� Erlang �����������

2. EMQ X 2.0-beta.x ������� Erlang ��������� rebar.config � relx.config ��:

35

EMQ X - ����� MQTT �����, �� 3.1.0

%% Max ClientId Length Allowed.{mqtt_max_clientid_len, 512}.

%% Max Packet Size Allowed, 64K by default.{mqtt_max_packet_size, 65536}.

%% Client Idle Timeout.{mqtt_client_idle_timeout, 30}. % Second

���� Erlang ������������������������ gen_conf ������� appliaton:get_env �������

3. EMQ X 2.0-rc.2 ������ cuttlefish ������� sysctl � k = v ��������������� Erlang ������:

## Node namenode.name = [email protected]

## Max ClientId Length Allowed.mqtt.max_clientid_len = 1024

4. EMQ X 3.0-beta.1 ������� emqttd � emqx ����������������:

## Profileetc/emq.config ==> etc/emqx.config

## Node name��:node.name = [email protected]��:node.name = [email protected]

EMQ X �����������:

---------------------- 3.0/schema/*.schema ␣↪→-------------------| etc/emqx.conf | ----------------- \|/ ␣↪→| data/app.config || + | --> mergeconf --> | data/app.conf | --> cuttlefish generate -->␣↪→| || etc/plugins/*.conf | ----------------- ␣↪→| data/vm.args |---------------------- ␣↪→-------------------

4.3 EMQ X ����

EMQX_NODE_NAME Erlang �������: [email protected]_NODE_COOKIE Erlang ������� CookieEMQX_MAX_PORTS Erlang ����������� Socket �EMQX_TCP_PORT MQTT/TCP �������: 1883EMQX_SSL_PORT MQTT/SSL �������: 8883EMQX_WS_PORT MQTT/WebSocket �������: 8083EMQX_WSS_PORT MQTT/WebSocket with SSL �������: 8084

36 Chapter 4. ���� (Configuration)

EMQ X - ����� MQTT �����, �� 3.1.0

4.4 EMQ X ����

�����

cluster.name = emqxcl

�������

cluster.discovery = manual

�������

cluster.autoheal = on

�����������

cluster.autoclean = 5m

4.5 EMQ X ������

EMQ X ������������������:

�� ��manual ��������static ����������mcast UDP ��������dns DNS A ������etcd �� etcd ����k8s Kubernetes ������

manual ������

���������������� ./bin/emqx_ctl join <Node> ����:

cluster.discovery = manual

�� static ��������

������� static:

cluster.discovery = static

������:

cluster.static.seeds = [email protected],[email protected]

�� mcast ������

������� mcast:

cluster.discovery = mcast

IP ����:

4.4. EMQ X ���� 37

EMQ X - ����� MQTT �����, �� 3.1.0

cluster.mcast.addr = 239.192.0.1

������:

cluster.mcast.ports = 4369,4370

����:

cluster.mcast.iface = 0.0.0.0

�� TTL:

cluster.mcast.ttl = 255

����������:

cluster.mcast.loop = on

�� DNS A ������

������� dns:

cluster.discovery = dns

dns ��:

cluster.dns.name = localhost

��� IP ���������������:

cluster.dns.app = emqx

�� etcd ����

������� etcd:

cluster.discovery = etcd

etcd ������� , ����:

cluster.etcd.server = http://127.0.0.1:2379

�� etcd �������������������� etcd ������: v2/keys/<prefix>/<cluster.name>/<node.name>:

cluster.etcd.prefix = emqxcl

etcd ���� TTL:

cluster.etcd.node_ttl = 1m

������� PEM ���������:

cluster.etcd.ssl.keyfile = etc/certs/client-key.pem

������������:

38 Chapter 4. ���� (Configuration)

EMQ X - ����� MQTT �����, �� 3.1.0

cluster.etcd.ssl.certfile = etc/certs/client.pem

�� PEM ���CA�������:

cluster.etcd.ssl.cacertfile = etc/certs/ca.pem

�� Kubernetes ����

������� k8s:

cluster.discovery = k8s

Kubernetes API ������� , ����:

cluster.k8s.apiserver = http://10.110.111.204:8080

�������� EMQ X �������:

cluster.k8s.service_name = emqx

��� k8s ����� host �����:

cluster.k8s.address_type = ip

EMQ X �����:

cluster.k8s.app_name = emqx

Kubernetes �����:

cluster.k8s.namespace = default

4.6 EMQ X ��� Cookie

Erlang ����:

node.name = [email protected]

Erlang �������� Cookie:

node.cookie = emqxsecretcookie

��: Erlang/OTP ��������� Erlang ��(��)����� Erlang ��(��)������������������� ������� Erlang ��(��)�������� Cookie �������

4.7 EMQ X ������

EMQ X ���� Erlang/OTP ��� IPv4, IPv6 � TLS ����:

4.6. EMQ X ��� Cookie 39

EMQ X - ����� MQTT �����, �� 3.1.0

## �� Erlang �������: inet_tcp | inet6_tcp | inet_tlsnode.proto_dist = inet_tcp

## �� Erlang ����� SSL �����## node.ssl_dist_optfile = etc/ssl_dist.conf

4.8 Erlang �����

Erlang ������������������������������� on ��:

node.heartbeat = on

���������������� 0-1024:

node.async_threads = 32

Erlang �������������� MQTT ����� 2 � Erlang ��:

node.process_limit = 2048000

Erlang �������� Port ����� MQTT ���� 1 � Port:

node.max_ports = 1024000

���������:

node.dist_buffer_size = 8MB

ETS ����������mnesia � SSL ����� ETS �:

node.max_ets_tables = 256000

�� GC �������:

node.fullsweep_after = 1000

����������:

node.crash_dump = log/crash.dump

�� Erlang �����:

node.proto_dist = inet_tcp

Erlang ����� TLS ��� SSL/TLS �����:

node.ssl_dist_optfile = etc/ssl_dist.conf

����������:

node.dist_net_ticktime = 60

Erlang ���������� TCP �������:

40 Chapter 4. ���� (Configuration)

EMQ X - ����� MQTT �����, �� 3.1.0

node.dist_listen_min = 6396node.dist_listen_max = 6396

4.9 RPC ����

RPC ����� TCP ��:

rpc.tcp_server_port = 5369

RPC ����� TCP ��:

rpc.tcp_client_port = 5369

RPC ������:

rpc.connect_timeout = 5s

RPC ������:

rpc.send_timeout = 5s

������:

rpc.authentication_timeout = 5s

��������:

rpc.call_receive_timeout = 15s

socket �����������:

rpc.socket_keepalive_idle = 900

socket ������:

rpc.socket_keepalive_interval = 75s

���������������:

rpc.socket_keepalive_count = 9

4.10 ������

�������������������:

log.to = both

������:

log.level = error

4.9. RPC ���� 41

EMQ X - ����� MQTT �����, �� 3.1.0

�� primary logger level������������ logger handlers ������

�����������:

log.dir = log

���� “log.level” ������:

log.file = emqx.log

�������������:

log.rotation.size = 10MB

���������������:

log.rotation.count = 5

��������� file logger handlers���������������������� log.$level.file = $filename.

���������������� info ��������� info.log ���:

log.info.file = info.log

4.11 ����� ACL ��

����������������:

allow_anonymous = true

EMQ X ������ ACL �� MySQL� PostgreSQL ���� ACL�

���� ACL ��������������:

acl_nomatch = allow

���� ACL �������:

acl_file = etc/acl.conf

������ ACL ��:

enable_acl_cache = on

������� ACL ������:

acl_cache_max_size = 32

�� ACL �������:

acl_cache_ttl = 1m

etc/acl.conf ��������:

��|�� ��|IP��|ClientID ��|�� ����

42 Chapter 4. ���� (Configuration)

EMQ X - ����� MQTT �����, �� 3.1.0

�������� Erlang �����������������:

--------- --------- ---------Client -> | Rule1 | --nomatch--> | Rule2 | --nomatch--> | Rule3 | --> Default

--------- --------- ---------| | |

match match match\|/ \|/ \|/

allow | deny allow | deny allow | deny

etc/acl.conf ��������:

�� dashboard ���� $SYS/#:

{allow, {user, "dashboard"}, subscribe, ["$SYS/#"]}.

��������������:

{allow, {ipaddr, "127.0.0.1"}, pubsub, ["$SYS/#", "#"]}.

���������������� $SYS/# � # ��:

{deny, all, subscribe, ["$SYS/#", {eq, "#"}]}.

�������������:

{allow, all}.

��: ������������� $SYS/# � #�

EMQ X �������� MQTT �����(Publish)���(Subscribe)��������� ACL ����������� allow � deny�

4.12 MQTT ������

MQTT ������:

mqtt.max_packet_size = 1MB

ClientId ����:

mqtt.max_clientid_len = 65535

Topic �����0 ������:

mqtt.max_topic_levels = 0

����� QoS:

mqtt.max_qos_allowed = 2

Topic Alias �����0 ����� Topic Alias:

4.12. MQTT ������ 43

EMQ X - ����� MQTT �����, �� 3.1.0

mqtt.max_topic_alias = 0

���� MQTT ����:

mqtt.retain_available = true

���� MQTT �����:

mqtt.wildcard_subscription = true

���� MQTT ����:

mqtt.shared_subscription = true

������� loop deliver:

mqtt.ignore_loop_deliver = false

������ MQTT v3.1.1 ������ MQTT 5 � No Local ����

4.13 MQTT Zones ����

EMQ X �� Zone ��������� Zone �������� (��������)�Listener �������� Zone����� Zone ��������� Listener ������� Zone�

Listener ���������������� Zone > Global > Default:

--------- ---------- -----------Listeners -------> | Zone | --nomatch--> | Global | --nomatch--> | Default |

--------- ---------- -----------| | |

match match match\|/ \|/ \|/

Zone Configs Global Configs Default Configs

EMQ X �� zone.$name.xxx ������ $name ����� zone.external.xxx � zone.internal.xxx �� $name �������������������name � zone.$name.xxx�

4.13.1 External Zone ����

TCP ������� MQTT CONNECT �������:

zone.external.idle_timeout = 15s

��������:

## zone.external.publish_limit = 10,100

�������:

zone.external.enable_ban = on

�� ACL ��:

44 Chapter 4. ���� (Configuration)

EMQ X - ����� MQTT �����, �� 3.1.0

zone.external.enable_acl = on

�����������:

zone.external.enable_stats = on

����/������������������� GC:

zone.external.force_gc_policy = 1000|1MB

����/���������������������������������:

## zone.external.force_shutdown_policy = 8000|800MB

MQTT ������:

## zone.external.max_packet_size = 64KB

ClientId ����:

## zone.external.max_clientid_len = 1024

Topic �����0 ������:

## zone.external.max_topic_levels = 7

����� QoS:

## zone.external.max_qos_allowed = 2

Topic Alias �����0 ����� Topic Alias:

## zone.external.max_topic_alias = 0

���� MQTT ����:

## zone.external.retain_available = true

���� MQTT �����:

## zone.external.wildcard_subscription = false

���� MQTT ����:

## zone.external.shared_subscription = false

�������������������������������:

## zone.external.server_keepalive = 0

Keepalive * backoff * 2 ����������:

zone.external.keepalive_backoff = 0.75

������������0 ������:

4.13. MQTT Zones ���� 45

EMQ X - ����� MQTT �����, �� 3.1.0

zone.external.max_subscriptions = 0

���� QoS ��:

zone.external.upgrade_qos = off

���������:

zone.external.max_inflight = 32

QoS1/2 �������:

zone.external.retry_interval = 20s

�� PUBREL � QoS2 ������(Client -> Broker)�0 ������:

zone.external.max_awaiting_rel = 100

QoS2 ��(Client -> Broker)������ PUBREL �����

zone.external.await_rel_timeout = 300s

MQTT v3.1.1 ��������������:

zone.external.session_expiry_interval = 2h

������:

zone.external.mqueue_type = simple

��������:

zone.external.max_mqueue_len = 1000

�����:

## zone.external.mqueue_priorities = topic/1=10,topic/2=8

�������� QoS0 ��:

zone.external.mqueue_store_qos0 = true

���� flapping ��:

zone.external.enable_flapping_detect = off

����������������:

zone.external.flapping_threshold = 10, 1m

flapping ����:

zone.external.flapping_banned_expiry_interval = 1h

46 Chapter 4. ���� (Configuration)

EMQ X - ����� MQTT �����, �� 3.1.0

4.13.2 Internal Zone ����

������:

zone.internal.allow_anonymous = true

�����������:

zone.internal.enable_stats = on

�� ACL ��:

zone.internal.enable_acl = off

���� MQTT �����:

## zone.internal.wildcard_subscription = true

���� MQTT ����:

## zone.internal.shared_subscription = true

������������0 ������:

zone.internal.max_subscriptions = 0

���������:

zone.internal.max_inflight = 32

�� PUBREL � QoS2 ������(Client -> Broker)�0 ������:

zone.internal.max_awaiting_rel = 100

��������:

zone.internal.max_mqueue_len = 1000

�������� QoS0 ��:

zone.internal.mqueue_store_qos0 = true

���� flapping ��:

zone.internal.enable_flapping_detect = off

����������������:

zone.internal.flapping_threshold = 10, 1m

flapping ����:

zone.internal.flapping_banned_expiry_interval = 1h

4.13. MQTT Zones ���� 47

EMQ X - ����� MQTT �����, �� 3.1.0

4.14 MQTT Listeners ����

EMQ X ������� MQTT�MQTT/SSL�MQTT/WS ��������� listener.tcp|ssl|ws|wss|.* ����������������

EMQ X ���������� TCP ������:

1883 MQTT TCP ����8883 MQTT/TCP SSL ��8083 MQTT/WebSocket ��8080 HTTP �� API ��8084 MQTT/WebSocket with SSL ��

Listener ����:

listener.tcp.${name}.acceptors TCP Acceptor �listener.tcp.${name}.max_connections ���� TCP ���listener.tcp.${name}.max_conn_rate �����������1000/�: “1000”listener.tcp.${name}.zone ������� Zonelistener.tcp.${name}.rate_limit �����������10B/�: “100,200”

4.15 MQTT/TCP ��� - 1883

EMQ X �������� MQTT ������������ external�internal �����:

TCP ���:

listener.tcp.external = 0.0.0.0:1883

�����:

listener.tcp.external.acceptors = 8

�������:

listener.tcp.external.max_connections = 1024000

���������:

listener.tcp.external.max_conn_rate = 1000

������ Zone:

listener.tcp.external.zone = external

���:

## listener.tcp.external.mountpoint = devicebound/

TCP ��������:

## listener.tcp.external.rate_limit = 1024,4096

������:

48 Chapter 4. ���� (Configuration)

EMQ X - ����� MQTT �����, �� 3.1.0

## listener.tcp.external.access.1 = allow 192.168.0.0/24

listener.tcp.external.access.1 = allow all

EMQ X ����� HAProxy � Nginx ���������� V1/2:

## listener.tcp.external.proxy_protocol = on

���������:

## listener.tcp.external.proxy_protocol_timeout = 3s

���� X.509 ����������EMQ X ������������ MQTT ���:

## listener.tcp.external.peer_cert_as_username = cn

������������:

listener.tcp.external.backlog = 1024

TCP ������:

listener.tcp.external.send_timeout = 15s

��������� TCP ��:

listener.tcp.external.send_timeout_close = on

�� MQTT ��� TCP �����(os��):

#listener.tcp.external.recbuf = 2KB

�� MQTT ��� TCP �����(os��):

#listener.tcp.external.sndbuf = 2KB

������������������������ sndbuf � recbuf ��� ������������������ val(buffer) >= max(val(sndbuf)�val(recbuf)) ��������������������sndbuf � recbuf ���val(buffer) ����������:

#listener.tcp.external.buffer = 2KB

���� buffer = max(sndbuf, recbuf):

## listener.tcp.external.tune_buffer = off

���� TCP_NODELAY ���������������������������:

listener.tcp.external.nodelay = true

���� SO_REUSEADDR ��:

listener.tcp.external.reuseaddr = true

4.15. MQTT/TCP ��� - 1883 49

EMQ X - ����� MQTT �����, �� 3.1.0

4.16 MQTT/SSL ��� - 8883

SSL ����:

listener.ssl.external = 8883

�����:

listener.ssl.external.acceptors = 16

�������:

listener.ssl.external.max_connections = 102400

���������:

listener.ssl.external.max_conn_rate = 500

������ Zone:

listener.ssl.external.zone = external

���:

## listener.ssl.external.mountpoint = devicebound/

������:

listener.ssl.external.access.1 = allow all

TCP ��������:

## listener.ssl.external.rate_limit = 1024,4096

EMQ X ����� HAProxy � Nginx ���������� V1/2:

## listener.ssl.external.proxy_protocol = on

���������:

## listener.ssl.external.proxy_protocol_timeout = 3s

TLS ����� POODLE ��:

## listener.ssl.external.tls_versions = tlsv1.2,tlsv1.1,tlsv1

TLS ������:

listener.ssl.external.handshake_timeout = 15s

������������:

listener.ssl.external.keyfile = etc/certs/key.pem

������������:

50 Chapter 4. ���� (Configuration)

EMQ X - ����� MQTT �����, �� 3.1.0

listener.ssl.external.certfile = etc/certs/cert.pem

�� CA ��������:

## listener.ssl.external.cacertfile = etc/certs/cacert.pem

�� dh-params ������:

## listener.ssl.external.dhfile = etc/certs/dh-params.pem

�� verify �������� verify_peer ����� x509 ������������������:

## listener.ssl.external.verify = verify_peer

���� verify_peer ���������������������������:

## listener.ssl.external.fail_if_no_peer_cert = true

SSL cipher suites:

listener.ssl.external.ciphers = ECDHE-ECDSA-AES256-GCM-SHA384,ECDHE-RSA-AES256-GCM-↪→SHA384,ECDHE-ECDSA-AES256-SHA384,ECDHE-RSA-AES256-SHA384,ECDHE-ECDSA-DES-CBC3-SHA,ECDH-↪→ECDSA-AES256-GCM-SHA384,ECDH-RSA-AES256-GCM-SHA384,ECDH-ECDSA-AES256-SHA384,ECDH-RSA-↪→AES256-SHA384,DHE-DSS-AES256-GCM-SHA384,DHE-DSS-AES256-SHA256,AES256-GCM-SHA384,AES256-↪→SHA256,ECDHE-ECDSA-AES128-GCM-SHA256,ECDHE-RSA-AES128-GCM-SHA256,ECDHE-ECDSA-AES128-↪→SHA256,ECDHE-RSA-AES128-SHA256,ECDH-ECDSA-AES128-GCM-SHA256,ECDH-RSA-AES128-GCM-SHA256,↪→ECDH-ECDSA-AES128-SHA256,ECDH-RSA-AES128-SHA256,DHE-DSS-AES128-GCM-SHA256,DHE-DSS-↪→AES128-SHA256,AES128-GCM-SHA256,AES128-SHA256,ECDHE-ECDSA-AES256-SHA,ECDHE-RSA-AES256-↪→SHA,DHE-DSS-AES256-SHA,ECDH-ECDSA-AES256-SHA,ECDH-RSA-AES256-SHA,AES256-SHA,ECDHE-↪→ECDSA-AES128-SHA,ECDHE-RSA-AES128-SHA,DHE-DSS-AES128-SHA,ECDH-ECDSA-AES128-SHA,ECDH-↪→RSA-AES128-SHA,AES128-SHA

�������� renegotiation ��:

## listener.ssl.external.secure_renegotiate = off

�����������������:

## listener.ssl.external.reuse_sessions = on

�����������������������������:

## listener.ssl.external.honor_cipher_order = on

��������� CN�EN � CRT �����������“verify” ����� “verify_peer”:

## listener.ssl.external.peer_cert_as_username = cn

������������:

## listener.ssl.external.backlog = 1024

TCP ������:

4.16. MQTT/SSL ��� - 8883 51

EMQ X - ����� MQTT �����, �� 3.1.0

## listener.ssl.external.send_timeout = 15s

��������� TCP ��:

## listener.ssl.external.send_timeout_close = on

�� MQTT ��� TCP �����(os��):

#listener.ssl.external.recbuf = 2KB

�� MQTT ��� TCP �����(os��):

## listener.ssl.external.sndbuf = 4KB

������������������������ sndbuf � recbuf ��� ������������������ val(buffer) >= max(val(sndbuf)�val(recbuf)) ��������������������sndbuf � recbuf ���val(buffer) ����������:

## listener.ssl.external.buffer = 4KB

���� buffer = max(sndbuf, recbuf):

## listener.ssl.external.tune_buffer = off

���� TCP_NODELAY ���������������������������:

## listener.ssl.external.nodelay = true

���� SO_REUSEADDR ��:

listener.ssl.external.reuseaddr = true

4.17 MQTT/WebSocket ��� - 8083

MQTT/WebSocket ����:

listener.ws.external = 8083

�����:

listener.ws.external.acceptors = 4

�������:

listener.ws.external.max_connections = 102400

���������:

listener.ws.external.max_conn_rate = 1000

TCP ��������:

## listener.ws.external.rate_limit = 1024,4096

������ Zone:

52 Chapter 4. ���� (Configuration)

EMQ X - ����� MQTT �����, �� 3.1.0

listener.ws.external.zone = external

���:

## listener.ws.external.mountpoint = devicebound/

������:

listener.ws.external.access.1 = allow all

�����������:

listener.ws.external.verify_protocol_header = on

EMQ X ����� NGINX � HAProxy ����� X-Forward-For ����� IP:

## listener.ws.external.proxy_address_header = X-Forwarded-For

EMQ X ����� NGINX � HAProxy ����� X-Forward-Port �������:

## listener.ws.external.proxy_port_header = X-Forwarded-Port

EMQ X ����� HAProxy � Nginx ���������� V1/2:

## listener.ws.external.proxy_protocol = on

��������:

## listener.ws.external.proxy_protocol_timeout = 3s

������������:

listener.ws.external.backlog = 1024

TCP ������:

listener.ws.external.send_timeout = 15s

��������� TCP ��:

listener.ws.external.send_timeout_close = on

�� MQTT ��� TCP �����(os��):

## listener.ws.external.recbuf = 2KB

�� MQTT ��� TCP �����(os��):

## listener.ws.external.sndbuf = 2KB

������������������������ sndbuf � recbuf ��� ������������������ val(buffer) >= max(val(sndbuf)�val(recbuf)) ��������������������sndbuf � recbuf ���val(buffer) ����������:

## listener.ws.external.buffer = 2KB

���� buffer = max(sndbuf, recbuf):

4.17. MQTT/WebSocket ��� - 8083 53

EMQ X - ����� MQTT �����, �� 3.1.0

## listener.ws.external.tune_buffer = off

���� TCP_NODELAY ���������������������������:

listener.ws.external.nodelay = true

���� Websocket ��:

## listener.ws.external.compress = true

Websocket deflate ��:

## listener.ws.external.deflate_opts.level = default## listener.ws.external.deflate_opts.mem_level = 8## listener.ws.external.deflate_opts.strategy = default## listener.ws.external.deflate_opts.server_context_takeover = takeover## listener.ws.external.deflate_opts.client_context_takeover = takeover## listener.ws.external.deflate_opts.server_max_window_bits = 15## listener.ws.external.deflate_opts.client_max_window_bits = 15

������:

## listener.ws.external.idle_timeout = 2h

�������0 ������:

## listener.ws.external.max_frame_size = 0

4.18 MQTT/WebSocket with SSL ��� - 8084

MQTT/WebSocket with SSL ����:

listener.wss.external = 8084

�����:

listener.wss.external.acceptors = 4

�������:

listener.wss.external.max_connections = 16

���������:

listener.wss.external.max_conn_rate = 1000

TCP ��������:

## listener.wss.external.rate_limit = 1024,4096

������ Zone:

54 Chapter 4. ���� (Configuration)

EMQ X - ����� MQTT �����, �� 3.1.0

listener.wss.external.zone = external

���:

## listener.wss.external.mountpoint = devicebound/

������:

listener.wss.external.access.1 = allow all

�����������:

listener.wss.external.verify_protocol_header = on

EMQ X ����� NGINX � HAProxy ����� X-Forward-For ����� IP:

## listener.wss.external.proxy_address_header = X-Forwarded-For

EMQ X ����� NGINX � HAProxy ����� X-Forward-Port �������:

## listener.wss.external.proxy_port_header = X-Forwarded-Port

EMQ X ����� HAProxy � Nginx ���������� V1/2:

## listener.wss.external.proxy_protocol = on

��������:

## listener.wss.external.proxy_protocol_timeout = 3s

TLS ����� POODLE ��:

## listener.wss.external.tls_versions = tlsv1.2,tlsv1.1,tlsv1

������������:

listener.wss.external.keyfile = etc/certs/key.pem

������������:

listener.wss.external.certfile = etc/certs/cert.pem

�� CA ��������:

## listener.wss.external.cacertfile = etc/certs/cacert.pem

�� dh-params ������:

## listener.ssl.external.dhfile = etc/certs/dh-params.pem

�� verify �������� verify_peer ����� x509 ������������������:

## listener.wss.external.verify = verify_peer

���� verify_peer ���������������������������:

4.18. MQTT/WebSocket with SSL ��� - 8084 55

EMQ X - ����� MQTT �����, �� 3.1.0

## listener.wss.external.fail_if_no_peer_cert = true

SSL cipher suites:

## listener.wss.external.ciphers = ECDHE-ECDSA-AES256-GCM-SHA384,ECDHE-RSA-AES256-GCM-↪→SHA384,ECDHE-ECDSA-AES256-SHA384,ECDHE-RSA-AES256-SHA384,ECDHE-ECDSA-DES-CBC3-SHA,ECDH-↪→ECDSA-AES256-GCM-SHA384,ECDH-RSA-AES256-GCM-SHA384,ECDH-ECDSA-AES256-SHA384,ECDH-RSA-↪→AES256-SHA384,DHE-DSS-AES256-GCM-SHA384,DHE-DSS-AES256-SHA256,AES256-GCM-SHA384,AES256-↪→SHA256,ECDHE-ECDSA-AES128-GCM-SHA256,ECDHE-RSA-AES128-GCM-SHA256,ECDHE-ECDSA-AES128-↪→SHA256,ECDHE-RSA-AES128-SHA256,ECDH-ECDSA-AES128-GCM-SHA256,ECDH-RSA-AES128-GCM-SHA256,↪→ECDH-ECDSA-AES128-SHA256,ECDH-RSA-AES128-SHA256,DHE-DSS-AES128-GCM-SHA256,DHE-DSS-↪→AES128-SHA256,AES128-GCM-SHA256,AES128-SHA256,ECDHE-ECDSA-AES256-SHA,ECDHE-RSA-AES256-↪→SHA,DHE-DSS-AES256-SHA,ECDH-ECDSA-AES256-SHA,ECDH-RSA-AES256-SHA,AES256-SHA,ECDHE-↪→ECDSA-AES128-SHA,ECDHE-RSA-AES128-SHA,DHE-DSS-AES128-SHA,ECDH-ECDSA-AES128-SHA,ECDH-↪→RSA-AES128-SHA,AES128-SHA

�������� renegotiation ��:

## listener.wss.external.secure_renegotiate = off

�����������������:

## listener.wss.external.reuse_sessions = on

�����������������������������:

## listener.wss.external.honor_cipher_order = on

��������� CN�EN � CRT �����������“verify” ����� “verify_peer”:

## listener.wss.external.peer_cert_as_username = cn

������������:

listener.wss.external.backlog = 1024

TCP ������:

listener.wss.external.send_timeout = 15s

��������� TCP ��:

listener.wss.external.send_timeout_close = on

�� MQTT ��� TCP �����(os��):

## listener.wss.external.recbuf = 4KB

�� MQTT ��� TCP �����(os��):

## listener.wss.external.sndbuf = 4KB

������������������������ sndbuf � recbuf ��� ������������������ val(buffer) >= max(val(sndbuf)�val(recbuf)) ��������������������sndbuf � recbuf ���val(buffer) ����������:

56 Chapter 4. ���� (Configuration)

EMQ X - ����� MQTT �����, �� 3.1.0

## listener.wss.external.buffer = 4KB

���� TCP_NODELAY ���������������������������:

## listener.wss.external.nodelay = true

���� Websocket ��:

## listener.wss.external.compress = true

Websocket deflate ��:

## listener.wss.external.deflate_opts.level = default## listener.wss.external.deflate_opts.mem_level = 8## listener.wss.external.deflate_opts.strategy = default## listener.wss.external.deflate_opts.server_context_takeover = takeover## listener.wss.external.deflate_opts.client_context_takeover = takeover## listener.wss.external.deflate_opts.server_max_window_bits = 15## listener.wss.external.deflate_opts.client_max_window_bits = 15

������:

## listener.wss.external.idle_timeout = 2h

�������0 ������:

## listener.wss.external.max_frame_size = 0

4.19 Bridges ��

4.19.1 Bridges ����

������������ rpc ����� host:port �� mqtt ��:

bridge.aws.address = 127.0.0.1:1883

�������:

bridge.aws.proto_ver = mqttv4

���� client_id:

bridge.aws.client_id = bridge_aws

���� clean_start ��:

bridge.aws.clean_start = true

���� username ��:

bridge.aws.username = user

���� password ��:

4.19. Bridges �� 57

EMQ X - ����� MQTT �����, �� 3.1.0

bridge.aws.password = passwd

������:

bridge.aws.mountpoint = bridge/aws/${node}/

���������:

bridge.aws.forwards = topic1/#,topic2/#

������� SSL ��������:

bridge.aws.ssl = off

SSL ��� CA �� (PEM��)

bridge.aws.cacertfile = etc/certs/cacert.pem

SSL ��� SSL ��:

bridge.aws.certfile = etc/certs/client-cert.pem

SSL �������:

bridge.aws.keyfile = etc/certs/client-key.pem

SSL ����:

#bridge.aws.ciphers = ECDHE-ECDSA-AES256-GCM-SHA384,ECDHE-RSA-AES256-GCM-SHA384

TLS PSK ���:

#bridge.aws.psk_ciphers = PSK-AES128-CBC-SHA,PSK-AES256-CBC-SHA,PSK-3DES-EDE-CBC-SHA,PSK-↪→RC4-SHA

��������:

bridge.aws.keepalive = 60s

��� TLS ��:

bridge.aws.tls_versions = tlsv1.2,tlsv1.1,tlsv1

�������:

bridge.aws.subscription.1.topic = cmd/topic1

����� qos:

bridge.aws.subscription.1.qos = 1

������:

bridge.aws.start_type = manual

�������:

58 Chapter 4. ���� (Configuration)

EMQ X - ����� MQTT �����, �� 3.1.0

bridge.aws.reconnect_interval = 30s

QoS1/2 �������:

bridge.aws.retry_interval = 20s

������:

bridge.aws.max_inflight_batches = 32

emqx_bridge ���� batch �����:

bridge.aws.queue.batch_count_limit = 32

emqx_bridge ���� batch ������:

bridge.aws.queue.batch_bytes_limit = 1000MB

�� replayq ��������������������� replayq ��� mem-only ����������������:

bridge.aws.queue.replayq_dir = {{ platform_data_dir }}/emqx_aws_bridge/

replayq �����:

bridge.aws.queue.replayq_seg_bytes = 10MB

4.20 Modules ��

EMQ X ��������������������������������������(Topic)�����

4.20.1 �����������

���������������:

module.presence = on

������������� MQTT ������ QoS:

module.presence.qos = 1

4.20.2 ������

����������:

module.subscription = off

�������������� QoS:

4.20. Modules �� 59

EMQ X - ����� MQTT �����, �� 3.1.0

## Subscribe the Topics's qos## module.subscription.1.topic = $client/%c## module.subscription.1.qos = 0## module.subscription.2.topic = $user/%u## module.subscription.2.qos = 1

4.20.3 ������

����������:

module.rewrite = off

������:

## module.rewrite.rule.1 = x/# ^x/y/(.+)$ z/y/$1## module.rewrite.rule.2 = y/+/z/# ^y/(.+)/z/(.+)$ y/z/$2

4.21 ��������

�����������:

plugins.etc_dir = etc/plugins/

����������������������:

plugins.loaded_file = data/loaded_plugins

EMQ X ���������� etc/plugins/ ������ plugins.etc_dir ������

4.22 Broker ����

���������:

broker.sys_interval = 1m

��������:

broker.enable_session_registry = on

�����:

broker.session_locking_strategy = quorum

���������:

broker.shared_subscription_strategy = random

��������� ACK:

60 Chapter 4. ���� (Configuration)

EMQ X - ����� MQTT �����, �� 3.1.0

broker.shared_dispatch_ack_enabled = false

������������:

broker.route_batch_clean = on

4.23 Erlang �������

���� long_gc ���������������� long_gc ������ 0 ��������:

sysmon.long_gc = 0

��������������������� long_schedule ������ 0 ��������:

sysmon.long_schedule = 240

������������������� large_heap ��:

sysmon.large_heap = 8MB

����������������������� busy_port ��:

sysmon.busy_port = false

���� Erlang ���������:

sysmon.busy_dist_port = true

cpu ��������:

os_mon.cpu_check_interval = 60s

cpu ������������:

os_mon.cpu_high_watermark = 80%

cpu ������������:

os_mon.cpu_low_watermark = 60%

����������:

os_mon.mem_check_interval = 60s

����������������:

os_mon.sysmem_high_watermark = 70%

������������������:

os_mon.procmem_high_watermark = 5%

���������:

4.23. Erlang ������� 61

EMQ X - ����� MQTT �����, �� 3.1.0

vm_mon.check_interval = 30s

���������������������������:

vm_mon.process_high_watermark = 80%

���������������������������:

vm_mon.process_low_watermark = 60%

62 Chapter 4. ���� (Configuration)

CHAPTER 5

���� (Plugins)

EMQ X ��������������(Hooks)����������������������������

EMQ X ����������

�� ���� ��emqx_dashboard etc/plugins/emqx_dashbord.conf Web �����(����)

emqx_auth_clientid etc/plugins/emqx_auth_clientid.confClientId ����

emqx_auth_username etc/plugins/emqx_auth_username.conf����������

emqx_auth_jwt etc/plugins/emqx_auth_jwt.conf JWT ��/����

emqx_auth_ldap etc/plugins/emqx_auth_ldap.conf LDAP ��/����

emqx_auth_http etc/plugins/emqx_auth_http.conf HTTP ��/����

emqx_auth_mongo etc/plugins/emqx_auth_mongo.confMongoDB ��/����

emqx_auth_mysql etc/plugins/emqx_auth_mysql.confMySQL ��/����

emqx_auth_pgsql etc/plugins/emqx_auth_pgsql.confPostgreSQL ��/����

emqx_auth_redis etc/plugins/emqx_auth_redis.conf Redis ��/����

emqx_psk_file etc/plugins/emqx_psk_file.conf PSK ��

emqx_web_hook etc/plugins/emqx_web_hook.conf Web Hook ��

emqx_lua_hook etc/plugins/emqx_lua_hook.conf Lua Hook ��

����

63

EMQ X - ����� MQTT �����, �� 3.1.0

� 1 – ����� ���� ��emqx_retainer etc/plugins/emqx_retainer.conf Retain ������

emqx_rule_engine etc/plugins/emqx_rule_engine.conf����

emqx_delayed_publish etc/plugins/emqx_delayed_publish.conf�����������

emqx_coap etc/plugins/emqx_coap.conf CoAP ����

emqx_lwm2m etc/plugins/emqx_lwm2m.conf LwM2M ����

emqx_sn etc/plugins/emqx_sn.conf MQTT-SN ����

emqx_stomp etc/plugins/emqx_stomp.conf Stomp ����

emqx_recon etc/plugins/emqx_recon.conf Recon ����

emqx_reloader etc/plugins/emqx_reloader.conf Reloader �������

emqx_plugin_template etc/plugins/emqx_plugin_template.conf������

�������������

1. ����

2. �������

3. �� Dashboard ����

4. ���� API ����

������

��������������������� data/loaded_plugins �������������������������

emqx_management.emqx_rule_engine.emqx_recon.emqx_retainer.emqx_dashboard.

�������

������������� CLI ����������������������

## �����������./bin/emqx_ctl plugins list

## �����./bin/emqx_ctl plugins load emqx_auth_username

## �����./bin/emqx_ctl plugins unload emqx_auth_username

(����)

64 Chapter 5. ���� (Plugins)

EMQ X - ����� MQTT �����, �� 3.1.0

(���)

## �������./bin/emqx_ctl plugins reload emqx_auth_username

�� Dashboard ����

�� EMQ X ��� Dashbord ���(����) ��������� http://localhost:18083/plugins ������������������

5.1 Dashboard ��

emqx_dashboard � EMQ X ������ Web �����, ��������� EMQ X ��������� http://localhost:18083 ����������/��: ad-min/public�

Dashboard ���� EMQ X �����������������������������(Connections)���(Sessions)����(Topics)�����(Subscriptions) ������

�����Dashboard ��������� REST API ������������� Dashboard -> HTTP API ���

5.1.1 Dashboard ����

etc/plugins/emqx_dashboard.conf:

## Dashboard �����/��dashboard.default_user.login = admindashboard.default_user.password = public

## Dashboard HTTP ������dashboard.listener.http = 18083dashboard.listener.http.acceptors = 2dashboard.listener.http.max_clients = 512

## Dashboard HTTPS ������## dashboard.listener.https = 18084

(����)

5.1. Dashboard �� 65

EMQ X - ����� MQTT �����, �� 3.1.0

(���)

## dashboard.listener.https.acceptors = 2## dashboard.listener.https.max_clients = 512## dashboard.listener.https.handshake_timeout = 15s## dashboard.listener.https.certfile = etc/certs/cert.pem## dashboard.listener.https.keyfile = etc/certs/key.pem## dashboard.listener.https.cacertfile = etc/certs/cacert.pem## dashboard.listener.https.verify = verify_peer## dashboard.listener.https.fail_if_no_peer_cert = true

5.2 ClientID ����

emqx_auth_clientid ����� ������� clientid � password ��������������������� hash �����������

��: � EMQ X 3.1 ������ REST API/CLI �� clientid���������������� clientid�

5.2.1 ClientID ����

etc/plugins/emqx_auth_clientid.conf:

## ������## ���: plain | md5 | sha | sha256auth.client.password_hash = sha256

5.3 Username ����

emqx_auth_username ����� ������� username � password ��������������������� hash �����������

��: � EMQ X 3.1 ������ REST API/CLI �� username���������������� username�

5.3.1 �������

etc/plugins/emqx_auth_username.conf:

## ������## ���: plain | md5 | sha | sha256auth.user.password_hash = sha256

5.4 JWT ����

emqx_auth_jwt ���� JWT ������������������� ���� ���������� Token �����������������

66 Chapter 5. ���� (Plugins)

EMQ X - ����� MQTT �����, �� 3.1.0

5.4.1 JWT ����

etc/plugins/emqx_auth_jwt.conf:

## HMAC Hash ����auth.jwt.secret = emqxsecret

## RSA � ECDSA �����## auth.jwt.pubkey = etc/certs/jwt_public_key.pem

## JWT ����## ���: username | passwordauth.jwt.from = password

5.5 LDAP ��/������

emqx_auth_ldap ���� LDAP �� ��������� ���

5.5.1 LDAP ������

etc/plugins/emqx_auth_ldap.conf:

auth.ldap.servers = 127.0.0.1

auth.ldap.port = 389

auth.ldap.pool = 8

auth.ldap.bind_dn = cn=root,dc=emqx,dc=io

auth.ldap.bind_password = public

auth.ldap.timeout = 30s

auth.ldap.device_dn = ou=device,dc=emqx,dc=io

auth.ldap.match_objectclass = mqttUser

auth.ldap.username.attributetype = uid

auth.ldap.password.attributetype = userPassword

auth.ldap.ssl = false

## auth.ldap.ssl.certfile = etc/certs/cert.pem

## auth.ldap.ssl.keyfile = etc/certs/key.pem

## auth.ldap.ssl.cacertfile = etc/certs/cacert.pem

(����)

5.5. LDAP ��/������ 67

EMQ X - ����� MQTT �����, �� 3.1.0

(���)

## auth.ldap.ssl.verify = verify_peer

## auth.ldap.ssl.fail_if_no_peer_cert = true

5.6 HTTP ��/������

emqx_auth_http ���� ���� � ���� ����������������� HTTP ���������������������

���������������

1. auth.http.auth_req: ����

2. auth.http.super_req: ���������

3. auth.http.acl_req: ��������

������������������� Username, IP ���������

��: ��� 3.1 ������ %cn %dn ����

5.6.1 HTTP ������

etc/plugins/emqx_auth_http.conf:

## ���:## - %u: username## - %c: clientid## - %a: ipaddress## - %P: password## - %cn: common name of client TLS cert## - %dn: subject of client TLS certauth.http.auth_req = http://127.0.0.1:8080/mqtt/auth

## AUTH ��� HTTP �������auth.http.auth_req.method = postauth.http.auth_req.params = clientid=%c,username=%u,password=%P

auth.http.super_req = http://127.0.0.1:8080/mqtt/superuserauth.http.super_req.method = postauth.http.super_req.params = clientid=%c,username=%u

## ���:## - %A: 1 | 2, 1 = sub, 2 = pub## - %u: username## - %c: clientid## - %a: ipaddress## - %t: topicauth.http.acl_req = http://127.0.0.1:8080/mqtt/aclauth.http.acl_req.method = getauth.http.acl_req.params = access=%A,username=%u,clientid=%c,ipaddr=%a,topic=%t

68 Chapter 5. ���� (Plugins)

EMQ X - ����� MQTT �����, �� 3.1.0

5.6.2 HTTP API �����

�����

## ����HTTP Status Code: 200

## ������HTTP Status Code: 200Body: ignore

## ����HTTP Status Code: Except 200

�����

## �������HTTP Status Code: 200

## �����HTTP Status Code: Except 200

�����

## �� Publish/Subscribe�HTTP Status Code: 200

## ������:HTTP Status Code: 200Body: ignore

## ���� Publish/Subscribe:HTTP Status Code: Except 200

5.7 MySQL ��/������

emqx_auth_mysql ���� MySQL �� ��������� ���������������� MySQL �������������

5.7.1 MQTT ���

CREATE TABLE `mqtt_user` (`id` int(11) unsigned NOT NULL AUTO_INCREMENT,`username` varchar(100) DEFAULT NULL,`password` varchar(100) DEFAULT NULL,`salt` varchar(35) DEFAULT NULL,`is_superuser` tinyint(1) DEFAULT 0,`created` datetime DEFAULT NULL,PRIMARY KEY (`id`),UNIQUE KEY `mqtt_username` (`username`)

) ENGINE=MyISAM DEFAULT CHARSET=utf8;

5.7. MySQL ��/������ 69

EMQ X - ����� MQTT �����, �� 3.1.0

��: ������������������ auth_query ���������

5.7.2 MQTT �����

CREATE TABLE `mqtt_acl` (`id` int(11) unsigned NOT NULL AUTO_INCREMENT,`allow` int(1) DEFAULT NULL COMMENT '0: deny, 1: allow',`ipaddr` varchar(60) DEFAULT NULL COMMENT 'IpAddress',`username` varchar(100) DEFAULT NULL COMMENT 'Username',`clientid` varchar(100) DEFAULT NULL COMMENT 'ClientId',`access` int(2) NOT NULL COMMENT '1: subscribe, 2: publish, 3: pubsub',`topic` varchar(100) NOT NULL DEFAULT '' COMMENT 'Topic Filter',PRIMARY KEY (`id`)

) ENGINE=InnoDB DEFAULT CHARSET=utf8;

INSERT INTO `mqtt_acl` (`id`, `allow`, `ipaddr`, `username`, `clientid`, `access`,␣↪→`topic`)VALUES

(1,1,NULL,'$all',NULL,2,'#'),(2,0,NULL,'$all',NULL,1,'$SYS/#'),(3,0,NULL,'$all',NULL,1,'eq #'),(5,1,'127.0.0.1',NULL,NULL,2,'$SYS/#'),(6,1,'127.0.0.1',NULL,NULL,2,'#'),(7,1,NULL,'dashboard',NULL,1,'$SYS/#');

5.7.3 �� MySQL ������

etc/plugins/emqx_auth_mysql.conf:

## Mysql �����auth.mysql.server = 127.0.0.1:3306

## Mysql �����auth.mysql.pool = 8

## Mysql �����## auth.mysql.username =

## Mysql ����## auth.mysql.password =

## Mysql ������auth.mysql.database = mqtt

## �����:## - %u: username## - %c: clientid## - %cn: common name of client TLS cert## - %dn: subject of client TLS cert

(����)

70 Chapter 5. ���� (Plugins)

EMQ X - ����� MQTT �����, �� 3.1.0

(���)

## �: �� SQL ������� `password` ��auth.mysql.auth_query = select password from mqtt_user where username = '%u' limit 1

## ������: plain, md5, sha, sha256, pbkdf2auth.mysql.password_hash = sha256

## ��������auth.mysql.super_query = select is_superuser from mqtt_user where username = '%u' limit 1

## ACL ����auth.mysql.acl_query = select allow, ipaddr, username, clientid, access, topic from mqtt_↪→acl where ipaddr = '%a' or username = '%u' or username = '$all' or clientid = '%c'

�������������������������������������

## ������## auth.mysql.password_hash = salt,sha256## auth.mysql.password_hash = salt,bcrypt## auth.mysql.password_hash = sha256,salt

## pbkdf2 � macfun ��## macfun: md4, md5, ripemd160, sha, sha224, sha256, sha384, sha512## auth.mysql.password_hash = pbkdf2,sha256,1000,20

��: 3.1 ���� %cn %dn ���

5.8 Postgres ����

emqx_auth_pgsql ���� Postgres �� ��������� ���������������

5.8.1 Postgres MQTT ���

CREATE TABLE mqtt_user (id SERIAL primary key,is_superuser boolean,username character varying(100),password character varying(100),salt character varying(40)

);

5.8.2 Postgres MQTT �����

CREATE TABLE mqtt_acl (id SERIAL primary key,allow integer,

(����)

5.8. Postgres ���� 71

EMQ X - ����� MQTT �����, �� 3.1.0

(���)

ipaddr character varying(60),username character varying(100),clientid character varying(100),access integer,topic character varying(100)

);

INSERT INTO mqtt_acl (id, allow, ipaddr, username, clientid, access, topic)VALUES

(1,1,NULL,'$all',NULL,2,'#'),(2,0,NULL,'$all',NULL,1,'$SYS/#'),(3,0,NULL,'$all',NULL,1,'eq #'),(5,1,'127.0.0.1',NULL,NULL,2,'$SYS/#'),(6,1,'127.0.0.1',NULL,NULL,2,'#'),(7,1,NULL,'dashboard',NULL,1,'$SYS/#');

5.8.3 �� Postgres ������

etc/plugins/emqx_auth_pgsql.conf:

## PostgreSQL ����auth.pgsql.server = 127.0.0.1:5432

## PostgreSQL �����auth.pgsql.pool = 8

auth.pgsql.username = root

## auth.pgsql.password =

auth.pgsql.database = mqtt

auth.pgsql.encoding = utf8

## ������ SQL## ���:## - %u: username## - %c: clientid## - %cn: common name of client TLS cert## - %dn: subject of client TLS certauth.pgsql.auth_query = select password from mqtt_user where username = '%u' limit 1

## ����: plain | md5 | sha | sha256 | bcryptauth.pgsql.password_hash = sha256

## �������� (��������)auth.pgsql.super_query = select is_superuser from mqtt_user where username = '%u' limit 1

## ACL ����#### ���:

(����)

72 Chapter 5. ���� (Plugins)

EMQ X - ����� MQTT �����, �� 3.1.0

(���)

## - %a: ipaddress## - %u: username## - %c: clientidauth.pgsql.acl_query = select allow, ipaddr, username, clientid, access, topic from mqtt_↪→acl where ipaddr = '%a' or username = '%u' or username = '$all' or clientid = '%c'

��� password_hash �������������

## ������## auth.pgsql.password_hash = salt,sha256## auth.pgsql.password_hash = sha256,salt## auth.pgsql.password_hash = salt,bcrypt

## pbkdf2 macfun ��## macfun: md4, md5, ripemd160, sha, sha224, sha256, sha384, sha512## auth.pgsql.password_hash = pbkdf2,sha256,1000,20

����������� TLS ��� Postgres�

## ���� SSLauth.pgsql.ssl = false

## ����## auth.pgsql.ssl_opts.keyfile =## auth.pgsql.ssl_opts.certfile =## auth.pgsql.ssl_opts.cacertfile =

��: 3.1 ���� %cn %dn ���

5.9 Redis ��/������

emqx_auth_redis ���� Redis ����� ���� � ���� ����

5.9.1 �� Redis ����

etc/plugins/emqx_auth_redis.conf:

## Redis ������## ���: single | sentinel | clusterauth.redis.type = single

## Redis �����#### Single Redis Server: 127.0.0.1:6379, localhost:6379## Redis Sentinel: 127.0.0.1:26379,127.0.0.2:26379,127.0.0.3:26379## Redis Cluster: 127.0.0.1:6379,127.0.0.2:6379,127.0.0.3:6379auth.redis.server = 127.0.0.1:6379

(����)

5.9. Redis ��/������ 73

EMQ X - ����� MQTT �����, �� 3.1.0

(���)

## Redis sentinel ��## auth.redis.sentinel = mymaster

## Redis �����auth.redis.pool = 8

## Redis database ��auth.redis.database = 0

## Redis password.## auth.redis.password =

## ������## ���:## - %u: username## - %c: clientid## - %cn: common name of client TLS cert## - %dn: subject of client TLS certauth.redis.auth_cmd = HMGET mqtt_user:%u password

## ������.## ��: plain | md5 | sha | sha256 | bcryptauth.redis.password_hash = plain

## �������� (��������)auth.redis.super_cmd = HGET mqtt_user:%u is_superuser

## ACL ����## ���:## - %u: username## - %c: clientidauth.redis.acl_cmd = HGETALL mqtt_acl:%u

�����������������

## ������## auth.redis.password_hash = salt,sha256## auth.redis.password_hash = sha256,salt## auth.redis.password_hash = salt,bcrypt

## pbkdf2 macfun ��## macfun: md4, md5, ripemd160, sha, sha224, sha256, sha384, sha512## auth.redis.password_hash = pbkdf2,sha256,1000,20

��: 3.1 ���� %cn %dn ���

5.9.2 Redis �� Hash

������ Hash ���

74 Chapter 5. ���� (Plugins)

EMQ X - ����� MQTT �����, �� 3.1.0

HSET mqtt_user:<username> is_superuser 1HSET mqtt_user:<username> password "passwd"HSET mqtt_user:<username> salt "salt"

5.9.3 Redis ACL �� Hash

���� Hash �� ACL ���

HSET mqtt_acl:<username> topic1 1HSET mqtt_acl:<username> topic2 2HSET mqtt_acl:<username> topic3 3

��: 1: subscribe, 2: publish, 3: pubsub

5.10 MongoDB ��/������

emqx_auth_mongo ���� MongoDB �� ���� � ���� ���

5.10.1 �� MongoDB ����

etc/plugins/emqx_auth_mongo.conf:

## MongoDB ����## ��: single | unknown | sharded | rsauth.mongo.type = single

## rs ���� `set name`## auth.mongo.rs_set_name =

## MongoDB ����auth.mongo.server = 127.0.0.1:27017

## MongoDB �����auth.mongo.pool = 8

## ������## auth.mongo.login =## auth.mongo.password =## auth.mongo.auth_source = admin

## ������auth.mongo.database = mqtt

## ������auth.mongo.auth_query.collection = mqtt_userauth.mongo.auth_query.password_field = passwordauth.mongo.auth_query.password_hash = sha256

(����)

5.10. MongoDB ��/������ 75

EMQ X - ����� MQTT �����, �� 3.1.0

(���)

## ����������## ���:## - %u: username## - %c: clientid## - %cn: common name of client TLS cert## - %dn: subject of client TLS certauth.mongo.auth_query.selector = username=%u

## ������auth.mongo.super_query = onauth.mongo.super_query.collection = mqtt_userauth.mongo.super_query.super_field = is_superuserauth.mongo.super_query.selector = username=%u

## ACL ����auth.mongo.acl_query = onauth.mongo.acl_query.collection = mqtt_acl

auth.mongo.acl_query.selector = username=%u

��: 3.1 ���� %cn %dn ���

5.10.2 MongoDB ���

use mqttdb.createCollection("mqtt_user")db.createCollection("mqtt_acl")db.mqtt_user.ensureIndex({"username":1})

��: �������������

5.10.3 MongoDB ����

{username: "user",password: "password hash",is_superuser: boolean (true, false),created: "datetime"

}

���

db.mqtt_user.insert({username: "test", password: "password hash", is_superuser: false})db.mqtt_user:insert({username: "root", is_superuser: true})

76 Chapter 5. ���� (Plugins)

EMQ X - ����� MQTT �����, �� 3.1.0

5.10.4 MongoDB ACL ��

{username: "username",clientid: "clientid",publish: ["topic1", "topic2", ...],subscribe: ["subtop1", "subtop2", ...],pubsub: ["topic/#", "topic1", ...]

}

���

db.mqtt_acl.insert({username: "test", publish: ["t/1", "t/2"], subscribe: ["user/%u",↪→"client/%c"]})db.mqtt_acl.insert({username: "admin", pubsub: ["#"]})

5.11 PSK ����

emqx_psk_file ������� PSK ��������������� TLS/DTLS ������ PSK ���� ���� ����

5.11.1 �� PSK ����

etc/plugins/emqx_psk_file.conf:

psk.file.path = etc/psk.txt

5.12 WebHook ��

emqx_web_hook ������� EMQ X ������������� HTTP ����

5.12.1 �� WebHook ��

etc/plugins/emqx_web_hook.conf:

## ��� Web Server ��web.hook.api.url = http://127.0.0.1:8080

## �� Payload ��## ���: undefined | base64 | base62## ���: undefined (�����)## web.hook.encode_payload = base64

## �������web.hook.rule.client.connected.1 = {"action": "on_client_connected"}web.hook.rule.client.disconnected.1 = {"action": "on_client_disconnected"}web.hook.rule.client.subscribe.1 = {"action": "on_client_subscribe"}web.hook.rule.client.unsubscribe.1 = {"action": "on_client_unsubscribe"}

(����)

5.11. PSK ���� 77

EMQ X - ����� MQTT �����, �� 3.1.0

(���)

web.hook.rule.session.created.1 = {"action": "on_session_created"}web.hook.rule.session.subscribed.1 = {"action": "on_session_subscribed"}web.hook.rule.session.unsubscribed.1 = {"action": "on_session_unsubscribed"}web.hook.rule.session.terminated.1 = {"action": "on_session_terminated"}web.hook.rule.message.publish.1 = {"action": "on_message_publish"}web.hook.rule.message.deliver.1 = {"action": "on_message_deliver"}web.hook.rule.message.acked.1 = {"action": "on_message_acked"}

5.13 Lua ��

emqx_lua_hook ������������������ Lua ������������ README�

5.14 Retainer ��

emqx_retainer ������������ EMQ X �� Retained ���������������� Retained ������������������������������������

5.14.1 �� Retainer ��

etc/plugins/emqx_retainer.conf:

## retained ������## - ram: ���## - disc: �����## - disc_only: ���retainer.storage_type = ram

## ����� (0�����)retainer.max_retained_messages = 0

## �����������retainer.max_payload_size = 1MB

## ����, 0 ������## ��: h ��; m ��; s ��� 60m �� 60 ��retainer.expiry_interval = 0

5.15 Delayed Publish ��

emqx_delayed_publish ������������������������� $delayed/<seconds>/ ����� EMQ X ��EMQ X �� <seconds> ����������

5.16 CoAP ����

emqx_coap ��� CoAP ��(RFC 7252)����

78 Chapter 5. ���� (Plugins)

EMQ X - ����� MQTT �����, �� 3.1.0

5.16.1 �� CoAP ����

etc/plugins/emqx_coap.conf:

coap.port = 5683

coap.keepalive = 120s

coap.enable_stats = off

��������������� DTLS�

coap.keyfile = etc/certs/key.pem

coap.certfile = etc/certs/cert.pem

5.16.2 �� CoAP ��

�������� libcoap ��� EMQ X � CoAP ��������

yum install libcoap

% coap client publish messagecoap-client -m put -e "qos=0&retain=0&message=payload&topic=hello" coap://localhost/mqtt

5.17 LwM2M ����

emqx_lwm2m ��� LwM2M ������

5.17.1 �� LwM2M ��

etc/plugins/emqx_lwm2m.conf:

## LwM2M ����lwm2m.port = 5683

## Lifetime ��lwm2m.lifetime_min = 1slwm2m.lifetime_max = 86400s

## Q Mode ��� `time window` ��, ����## ��� window ��������#lwm2m.qmode_time_window = 22

## LwM2M ����� coaproxy �#lwm2m.lb = coaproxy

## �������� observe ��� objects#lwm2m.auto_observe = off

(����)

5.17. LwM2M ���� 79

EMQ X - ����� MQTT �����, �� 3.1.0

(���)

## client register ������ EMQ X �����## ���:## '%e': Endpoint Name## '%a': IP Addresslwm2m.topics.command = lwm2m/%e/dn/#

## client ����(response) � EMQ X ���lwm2m.topics.response = lwm2m/%e/up/resp

## client �����(noify message) � EMQ X ���lwm2m.topics.notify = lwm2m/%e/up/notify

## client �����(register message) � EMQ X ���lwm2m.topics.register = lwm2m/%e/up/resp

# client �����(update message) � EMQ X ���lwm2m.topics.update = lwm2m/%e/up/resp

# Object ��� xml ����lwm2m.xml_dir = etc/lwm2m_xml

������������ DTLS ���

# DTLS ����lwm2m.certfile = etc/certs/cert.pemlwm2m.keyfile = etc/certs/key.pem

5.18 MQTT-SN ����

emqx_sn ����� MQTT-SN ������

5.18.1 �� MQTT-SN ����

etc/plugins/emqx_sn.conf:

mqtt.sn.port = 1884

5.19 Stomp ����

emqx_stomp ��� Stomp ������������� Stomp 1.0/1.1/1.2 ���� EMQ X����� MQTT ���

5.19.1 �� Stomp ��

��: Stomp ����: 61613

80 Chapter 5. ���� (Plugins)

EMQ X - ����� MQTT �����, �� 3.1.0

etc/plugins/emqx_stomp.conf:

stomp.default_user.login = guest

stomp.default_user.passcode = guest

stomp.allow_anonymous = true

stomp.frame.max_headers = 10

stomp.frame.max_header_length = 1024

stomp.frame.max_body_length = 8192

stomp.listener = 61613

stomp.listener.acceptors = 4

stomp.listener.max_clients = 512

5.20 Recon ������

emqx_recon ����� recon ��������������������������

./bin/emqx_ctl recon

recon memory #recon_alloc:memory/2recon allocated #recon_alloc:memory(allocated_types, current|max)recon bin_leak #recon:bin_leak(100)recon node_stats #recon:node_stats(10, 1000)recon remote_load Mod #recon:remote_load(Mod)

5.20.1 �� Recon ��

etc/plugins/emqx_recon.conf:

%% Garbage Collection: 10 minutesrecon.gc_interval = 600

5.21 Reloader �����

emqx_reloader ��������������������� EMQ X ��������������������

������� CLI ����� reload ������

./bin/emqx_ctl reload <Module>

��: ���������������

5.20. Recon ������ 81

EMQ X - ����� MQTT �����, �� 3.1.0

5.21.1 �� Reloader ��

etc/plugins/emqx_reloader.conf:

reloader.interval = 60

reloader.logfile = log/reloader.log

5.22 ������

emqx_plugin_template ��� EMQ X ����������������

������������������������������������� EMQ X ������������� Erlang Application�������: etc/${PluginName}.config�

5.23 EMQ X R3.1 ����

5.23.1 ������

�� emqx_plugin_template �������������

��: � <plugin name>_app.erl ��������� -emqx_plugin(?MODULE). ������� EMQ X ����

5.23.2 ����/������

������ - emqx_auth_demo.erl

-module(emqx_auth_demo).

-export([ init/1, check/2, description/0]).

init(Opts) -> {ok, Opts}.

check(_Credentials = #{client_id := ClientId, username := Username, password := Password}↪→, _State) ->

io:format("Auth Demo: clientId=~p, username=~p, password=~p~n", [ClientId, Username,␣↪→Password]),

ok.

description() -> "Auth Demo Module".

�������� - emqx_acl_demo.erl

-module(emqx_acl_demo).

-include_lib("emqx/include/emqx.hrl").(����)

82 Chapter 5. ���� (Plugins)

EMQ X - ����� MQTT �����, �� 3.1.0

(���)

%% ACL callbacks-export([ init/1

, check_acl/5, reload_acl/1, description/0]).

init(Opts) ->{ok, Opts}.

check_acl({Credentials, PubSub, _NoMatchAction, Topic}, _State) ->io:format("ACL Demo: ~p ~p ~p~n", [Credentials, PubSub, Topic]),allow.

reload_acl(_State) ->ok.

description() -> "ACL Demo Module".

����������� - emqx_plugin_template_app.erl

ok = emqx:hook('client.authenticate', fun emqx_auth_demo:check/2, []),ok = emqx:hook('client.check_acl', fun emqx_acl_demo:check_acl/5, []).

5.23.3 ����(Hooks)

����(Hook)�������������������

emqx_plugin_template.erl:

%% Called when the plugin application startload(Env) ->

emqx:hook('client.authenticate', fun ?MODULE:on_client_authenticate/2, [Env]),emqx:hook('client.check_acl', fun ?MODULE:on_client_check_acl/5, [Env]),emqx:hook('client.connected', fun ?MODULE:on_client_connected/4, [Env]),emqx:hook('client.disconnected', fun ?MODULE:on_client_disconnected/3, [Env]),emqx:hook('client.subscribe', fun ?MODULE:on_client_subscribe/3, [Env]),emqx:hook('client.unsubscribe', fun ?MODULE:on_client_unsubscribe/3, [Env]),emqx:hook('session.created', fun ?MODULE:on_session_created/3, [Env]),emqx:hook('session.resumed', fun ?MODULE:on_session_resumed/3, [Env]),emqx:hook('session.subscribed', fun ?MODULE:on_session_subscribed/4, [Env]),emqx:hook('session.unsubscribed', fun ?MODULE:on_session_unsubscribed/4, [Env]),emqx:hook('session.terminated', fun ?MODULE:on_session_terminated/3, [Env]),emqx:hook('message.publish', fun ?MODULE:on_message_publish/2, [Env]),emqx:hook('message.deliver', fun ?MODULE:on_message_deliver/3, [Env]),emqx:hook('message.acked', fun ?MODULE:on_message_acked/3, [Env]),emqx:hook('message.dropped', fun ?MODULE:on_message_dropped/3, [Env]).

������(Hook)��:

5.23. EMQ X R3.1 ���� 83

EMQ X - ����� MQTT �����, �� 3.1.0

�� ��client.authenticate ����client.check_acl ACL ��client.connected �����client.disconnected �������client.subscribe �������client.unsubscribe ���������session.created ����session.resumed ����session.subscribed �������session.unsubscribed ���������session.terminated ����message.publish MQTT ����message.deliver MQTT ������message.acked MQTT ����message.dropped MQTT ����

5.23.4 �� CLI ��

��������� - emqx_cli_demo.erl

-module(emqx_cli_demo).

-export([cmd/1]).

cmd(["arg1", "arg2"]) ->emqx_cli:print("ok");

cmd(_) ->emqx_cli:usage([{"cmd arg1 arg2", "cmd demo"}]).

������� - emqx_plugin_template_app.erl

ok = emqx_ctl:register_command(cmd, {emqx_cli_demo, cmd}, []),

������./bin/emqx_ctl ������

./bin/emqx_ctl cmd arg1 arg2

5.23.5 ������

����������� etc/${plugin_name}.conf|config�EMQ X ����������:

1. Erlang �������� - ${plugin_name}.config:

[{plugin_name, [{key, value}

]}].

2. sysctl � k = v ���� - ${plugin_name}.conf:

84 Chapter 5. ���� (Plugins)

EMQ X - ����� MQTT �����, �� 3.1.0

plugin_name.key = value

��: k = v ������������� priv/plugin_name.schema �����

5.23.6 ������

1. clone emqx-rel ���

git clone https://github.com/emqx/emqx-rel.git

2. Makefile �� DEPS�

DEPS += plugin_namedep_plugin_name = git url_of_plugin

3. relx.config � release �����

{plugin_name, load},

5.23. EMQ X R3.1 ���� 85

EMQ X - ����� MQTT �����, �� 3.1.0

86 Chapter 5. ���� (Plugins)

CHAPTER 6

���� (Commands)

EMQ X �������� ./bin/emqx_ctl �������

6.1 status ��

�� EMQ X ���������:

$ ./bin/emqx_ctl status

Node '[email protected]' is startedemqx v3.1.0 is running

6.2 mgmt ��

mgmt ���������

mgmt list ��������mgmt insert <AppId> <Name> �� REST API �����mgmt update <AppId> <status> �� REST API �����mgmt lookup <AppId> �� REST API �������mgmt delete <AppId> �� REST API �����

6.2.1 mgmt list

��������:

87

EMQ X - ����� MQTT �����, �� 3.1.0

$ ./bin/emqx_ctl mgmt listapp_id: 901abdba8eb8c, secret: MjgzMzQ5MjM1MzUzMTc4MjgyMjE3NzU4ODcwMDg0NjQ4OTG, name:␣↪→hello, desc: , status: true, expired: undefined

6.2.2 mgmt insert <AppId> <Name>

��REST API�����:

$ ./bin/emqx_ctl mgmt insert dbcb6e023370b worldAppSecret: MjgzMzQ5MjYyMTY3ODk4MjA5NzMwODExODMxMDM1NDk0NDA

6.2.3 mgmt update <AppId> <status>

�� REST API �����:

$ ./bin/emqx_ctl mgmt update dbcb6e023370b stopupdate successfully.

6.2.4 mgmt lookup <AppId>

�� REST API �������:

$ ./bin/emqx_ctl mgmt lookup dbcb6e023370bapp_id: dbcb6e023370bsecret: MjgzMzQ5MjYyMTY3ODk4MjA5NzMwODExODMxMDM1NDk0NDAname: worlddesc: Application userstatus: stopexpired: undefined

6.2.5 mgmt delete <AppId>

��REST API�����:

$ ./bin/emqx_ctl mgmt delete dbcb6e023370bok

6.3 broker ��

broker ���������������������������

broker �� EMQ X ���������������broker stats ����(Connection)���(Session)���(Topic)� ��(Subscription)���(Route)����broker metrics �� MQTT ��(Packet)���(Message)����

�� EMQ X �������������������:

88 Chapter 6. ���� (Commands)

EMQ X - ����� MQTT �����, �� 3.1.0

$ ./bin/emqx_ctl broker

sysdescr : EMQ X Brokerversion : v3.1.0uptime : 25 secondsdatetime : 2019-04-29 10:42:10

6.3.1 broker stats

����������(Connections)���(Sessions)���(Topics)���(Subscriptions)���(Routes)��:

$ ./bin/emqx_ctl broker stats

actions/max : 2connections/count : 1connections/max : 1resources/max : 0retained/count : 2retained/max : 2routes/count : 0routes/max : 0rules/max : 0sessions/count : 0sessions/max : 0sessions/persistent/count : 0sessions/persistent/max : 0suboptions/max : 0subscribers/count : 0subscribers/max : 1subscriptions/count : 1subscriptions/max : 0subscriptions/shared/count : 0subscriptions/shared/max : 0topics/count : 0topics/max : 0

6.3.2 broker metrics

�������(Bytes)�MQTT��(Packets)���(Messages)����:

$ ./bin/emqx_ctl broker metrics

bytes/received : 0bytes/sent : 0messages/dropped : 0messages/expired : 0messages/forward : 0messages/qos0/received : 0messages/qos0/sent : 0messages/qos1/received : 0

(����)

6.3. broker �� 89

EMQ X - ����� MQTT �����, �� 3.1.0

(���)

messages/qos1/sent : 0messages/qos2/dropped : 0messages/qos2/expired : 0messages/qos2/received : 0messages/qos2/sent : 0messages/received : 0messages/retained : 3messages/sent : 0packets/auth : 0packets/connack : 0packets/connect : 0packets/disconnect/recei: 0packets/disconnect/sent : 0packets/pingreq : 0packets/pingresp : 0packets/puback/missed : 0packets/puback/received : 0packets/puback/sent : 0packets/pubcomp/missed : 0packets/pubcomp/received: 0packets/pubcomp/sent : 0packets/publish/received: 0packets/publish/sent : 0packets/pubrec/missed : 0packets/pubrec/received : 0packets/pubrec/sent : 0packets/pubrel/missed : 0packets/pubrel/received : 0packets/pubrel/sent : 0packets/received : 0packets/sent : 0packets/suback : 0packets/subscribe : 0packets/unsuback : 0packets/unsubscribe : 0

6.4 cluster ��

cluster ������ EMQ X �������(��):

cluster join <Node> ����cluster leave ����cluster force-leave <Node> �������cluster status ������

cluster �������� EMQ X ����:

�� ��� MQTT ��emqx1 [email protected] 1883emqx2 [email protected] 2883

90 Chapter 6. ���� (Commands)

EMQ X - ����� MQTT �����, �� 3.1.0

�� emqx1

$ cd emqx1 && ./bin/emqx start

�� emqx2

$ cd emqx2 && ./bin/emqx start

emqx2 ��� emqx1 ���emqx2 ���:

$ ./bin/emqx_ctl cluster join [email protected]

Join the cluster successfully.Cluster status: [{running_nodes,['[email protected]','[email protected]']}]

�������������:

$ ./bin/emqx_ctl cluster status

Cluster status: [{running_nodes,['[email protected]','[email protected]']}]

��������:

# emqx1�����x$ mosquitto_sub -t x -q 1 -p 1883

# emqx2����x����$ mosquitto_pub -t x -q 1 -p 2883 -m hello

emqx2 ������:

$ cd emqx2 && ./bin/emqx_ctl cluster leave

emqx1 ����� emqx2:

$ cd emqx1 && ./bin/emqx_ctl cluster force-leave [email protected]

6.5 acl ��

���� acl ����:

$ ./bin/emqx_ctl acl reload

6.6 clients ��

clients ������� MQTT ����

clients list ���������clients show <ClientId> �� ClientId �����clients kick <ClientId> �� ClientId �����

6.5. acl �� 91

EMQ X - ����� MQTT �����, �� 3.1.0

6.6.1 clients list

���������:

$ ./bin/emqx_ctl clients list

Connection(mosqsub/43832-airlee.lo, clean_start=true, username=test, peername=127.0.0.↪→1:64896, connected_at=1452929113)Connection(mosqsub/44011-airlee.lo, clean_start=true, username=test, peername=127.0.0.↪→1:64961, connected_at=1452929275)...

�� Client �����:

clean_start ������username ���peername �� TCP ��connected_at �������

6.6.2 clients show <ClientId>

�� ClientId �����:

$ ./bin/emqx_ctl clients show "mosqsub/43832-airlee.lo"

Connection(mosqsub/43832-airlee.lo, clean_sess=true, username=test, peername=127.0.0.↪→1:64896, connected_at=1452929113)

6.6.3 clients kick <ClientId>

�� ClientId �����:

$ ./bin/emqx_ctl clients kick "clientid"

6.7 sessions ��

sessions ���� MQTT ����� EMQ X ����������������clean_session �� true�����(transient)���clean_session ���false�������(persistent)�

sessions list ������sessions show <ClientId> �� ClientID ����

6.7.1 sessions list

������:

92 Chapter 6. ���� (Commands)

EMQ X - ����� MQTT �����, �� 3.1.0

$ ./bin/emqx_ctl sessions list

Session(clientid, clean_start=true, expiry_interval=0, subscriptions_count=0, max_↪→inflight=32, inflight=0, mqueue_len=0, mqueue_dropped=0, awaiting_rel=0, deliver_msg=0,↪→ enqueue_msg=0, created_at=1553760799)Session(mosqsub/44101-airlee.lo, clean_start=true, expiry_interval=0, subscriptions_↪→count=0, max_inflight=32, inflight=0, mqueue_len=0, mqueue_dropped=0, awaiting_rel=0,␣↪→deliver_msg=0, enqueue_msg=0, created_at=1553760314)

�� Session ����:

clean_start ��������������expiry_interval ������subscriptions_count ������max_inflight ����(�����������)inflight ����������mqueue_len �������mqueue_dropped ��������awaiting_rel ������� PUBREL � QoS2 ���deliver_msg ������(����)enqueue_msg �������created_at �������

6.7.2 sessions show <ClientId>

�� ClientId ����:

$ ./bin/emqx_ctl sessions show clientid

Session(clientid, clean_start=true, expiry_interval=0, subscriptions_count=0, max_↪→inflight=32, inflight=0, mqueue_len=0, mqueue_dropped=0, awaiting_rel=0, deliver_msg=0,↪→ enqueue_msg=0, created_at=1553760799)

6.8 routes ��

routes ��������

routes list ������routes show <Topic> �� Topic ����

6.8.1 routes list

������:

$ ./bin/emqx_ctl routes list

t2/# -> [email protected]/+/x -> [email protected],[email protected]

6.8. routes �� 93

EMQ X - ����� MQTT �����, �� 3.1.0

6.8.2 routes show <Topic>

�� Topic ������:

$ ./bin/emqx_ctl routes show t/+/x

t/+/x -> [email protected],[email protected]

6.9 subscriptions ��

subscriptions ������������(Subscription)��

subscriptions list ������subscriptions show <ClientId> ���� ClientId ���subscriptions add <ClientId> <Topic> <QoS> ��������subscriptions del <ClientId> <Topic> ��������

6.9.1 subscriptions list

������:

$ ./bin/emqx_ctl subscriptions list

mosqsub/91042-airlee.lo -> t/y:1mosqsub/90475-airlee.lo -> t/+/x:2

6.9.2 subscriptions show <ClientId>

���� Client ���:

$ ./bin/emqx_ctl subscriptions show 'mosqsub/90475-airlee.lo'

mosqsub/90475-airlee.lo -> t/+/x:2

6.9.3 subscriptions add <ClientId> <Topic> <QoS>

��������:

$ ./bin/emqx_ctl subscriptions add 'mosqsub/90475-airlee.lo' '/world' 1

ok

6.9.4 subscriptions del <ClientId> <Topic>

��������:

94 Chapter 6. ���� (Commands)

EMQ X - ����� MQTT �����, �� 3.1.0

$ ./bin/emqx_ctl subscriptions del 'mosqsub/90475-airlee.lo' '/world'

ok

6.10 plugins ��

plugins ����������������� EMQ X ����������������������� plugins/ ����

plugins list ������(Plugin)plugins load <Plugin> ����(Plugin)plugins unload <Plugin> ����(Plugin)plugins reload <Plugin> ����(Plugin)

��: ��������������������������� reload ����� unload/load ������������

6.10.1 plugins list

������:

$ ./bin/emqx_ctl plugins list

Plugin(emqx_auth_clientid, version=v3.1.0, description=EMQ X Authentication with␣↪→ClientId/Password, active=false)Plugin(emqx_auth_http, version=v3.1.0, description=EMQ X Authentication/ACL with HTTP␣↪→API, active=false)Plugin(emqx_auth_jwt, version=v3.1.0, description=EMQ X Authentication with JWT,␣↪→active=false)Plugin(emqx_auth_ldap, version=v3.1.0, description=EMQ X Authentication/ACL with LDAP,␣↪→active=false)Plugin(emqx_auth_mongo, version=v3.1.0, description=EMQ X Authentication/ACL with␣↪→MongoDB, active=false)Plugin(emqx_auth_mysql, version=v3.1.0, description=EMQ X Authentication/ACL with MySQL,␣↪→active=false)Plugin(emqx_auth_pgsql, version=v3.1.0, description=EMQ X Authentication/ACL with␣↪→PostgreSQL, active=false)Plugin(emqx_auth_redis, version=v3.1.0, description=EMQ X Authentication/ACL with Redis,␣↪→active=false)Plugin(emqx_auth_username, version=v3.1.0, description=EMQ X Authentication with␣↪→Username and Password, active=false)Plugin(emqx_coap, version=v3.1.0, description=EMQ X CoAP Gateway, active=false)Plugin(emqx_dashboard, version=v3.1.0, description=EMQ X Web Dashboard, active=true)Plugin(emqx_delayed_publish, version=v3.1.0, description=EMQ X Delayed Publish,␣↪→active=false)Plugin(emqx_lua_hook, version=v3.1.0, description=EMQ X Lua Hooks, active=false)Plugin(emqx_lwm2m, version=v3.1.0, description=EMQ X LwM2M Gateway, active=false)Plugin(emqx_management, version=v3.1.0, description=EMQ X Management API and CLI,␣↪→active=true)

(����)

6.10. plugins �� 95

EMQ X - ����� MQTT �����, �� 3.1.0

(���)

Plugin(emqx_plugin_template, version=v3.1.0, description=EMQ X Plugin Template,␣↪→active=false)Plugin(emqx_psk_file, version=v3.1.0, description=EMQX PSK Plugin from File,␣↪→active=false)Plugin(emqx_recon, version=v3.1.0, description=EMQ X Recon Plugin, active=true)Plugin(emqx_reloader, version=v3.1.0, description=EMQ X Reloader Plugin, active=false)Plugin(emqx_retainer, version=v3.1.0, description=EMQ X Retainer, active=true)Plugin(emqx_rule_engine, version=v3.1.0, description=EMQ X Rule Engine, active=true)Plugin(emqx_sn, version=v3.1.0, description=EMQ X MQTT SN Plugin, active=false)Plugin(emqx_statsd, version=v3.1.0, description=Statsd for EMQ X, active=false)Plugin(emqx_stomp, version=v3.1.0, description=EMQ X Stomp Protocol Plugin, active=false)Plugin(emqx_web_hook, version=v3.1.0, description=EMQ X Webhook Plugin, active=false)

����:

version ����description ����active �����

6.10.2 plugins load <Plugin>

����:

$ ./bin/emqx_ctl plugins load emqx_lua_hook

Start apps: [emqx_lua_hook]Plugin emqx_lua_hook loaded successfully.

6.10.3 plugins unload <Plugin>

����:

$ ./bin/emqx_ctl plugins unload emqx_lua_hook

Plugin emqx_lua_hook unloaded successfully.

6.10.4 plugins reload <Plugin>

����:

$ ./bin/emqx_ctl plugins reload emqx_lua_hook

Plugin emqx_lua_hook reloaded successfully.

6.11 bridges ��

bridges ������� EMQ X ����������:

96 Chapter 6. ���� (Commands)

EMQ X - ����� MQTT �����, �� 3.1.0

--------- ---------Publisher --> | node1 | --Bridge Forward--> | node2 | --> Subscriber

--------- ---------

bridges list ������bridges start <Name> ������bridges stop <Name> ������bridges forwards <Name> ���� bridge �����bridges add-forward <Name> <Topic> ��� bridge ������bridges del-forward <Name> <Topic> ��� bridge ������bridges subscriptions <Name> ���� bridge �����bridges add-subscription <Name> <Topic> <QoS> ��� bridge ������bridges del-subscription <Name> <Topic> ��� bridge ������

�� bridges ����� emqx/emqx.config����

6.11.1 bridges list

������:

$ ./bin/emqx_ctl bridges list

name: emqx status: Stopped

6.11.2 bridges start <Name>

������:

$ ./bin/emqx_ctl bridges start emqx

Start bridge successfully.

6.11.3 bridges stop <Name>

������:

$ ./bin/emqx_ctl bridges stop emqx

Stop bridge successfully.

6.11.4 bridges forwards <Name>

���� bridge �����:

$ ./bin/emqx_ctl bridges forwards emqx

topic: sensor/#

6.11. bridges �� 97

EMQ X - ����� MQTT �����, �� 3.1.0

6.11.5 bridges add-forward <Name> <Topic>

��� bridge ������:

$ ./bin/emqx_ctl bridges add-forward emqx device_status/#

Add-forward topic successfully.

6.11.6 bridges del-forward <Name> <Topic>

��� bridge ������:

$ ./bin/emqx_ctl bridges del-forward emqx device_status/#

Del-forward topic successfully.

6.11.7 bridges add-subscription <Name> <Topic> <QoS>

��� bridge ������:

$ ./bin/emqx_ctl bridges add-subscription emqx cmd/topic 1

Add-subscription topic successfully.

6.11.8 bridges subscriptions <Name>

���� bridge ���:

$ ./bin/emqx_ctl bridges subscriptions emqx

topic: cmd/topic, qos: 1

6.11.9 bridges del-subscription <Name> <Topic>

��� bridge ������:

$ ./bin/emqx_ctl bridges del-subscription emqx cmd/topic

Del-subscription topic successfully.

6.12 vm ��

vm ������ Erlang ������������IO ���

98 Chapter 6. ���� (Commands)

EMQ X - ����� MQTT �����, �� 3.1.0

vm ��� vm allvm all �� VM ����vm load �� VM ��vm memory �� VM ��vm process �� VM Erlang ����vm io �� VM io ������vm ports �� VM ���

6.12.1 vm all

�� VM �������������Erlang �����:

cpu/load1 : 4.22cpu/load5 : 3.29cpu/load15 : 3.16memory/total : 99995208memory/processes : 38998248memory/processes_used : 38938520memory/system : 60996960memory/atom : 1189073memory/atom_used : 1173808memory/binary : 100336memory/code : 25439961memory/ets : 7161128process/limit : 2097152process/count : 315io/max_fds : 10240io/active_fds : 0ports/count : 18ports/limit : 1048576

6.12.2 vm load

�� VM ��:

$ ./bin/emqx_ctl vm load

cpu/load1 : 2.21cpu/load5 : 2.60cpu/load15 : 2.36

6.12.3 vm memory

�� VM ��:

$ ./bin/emqx_ctl vm memory

memory/total : 23967736memory/processes : 3594216

(����)

6.12. vm �� 99

EMQ X - ����� MQTT �����, �� 3.1.0

(���)

memory/processes_used : 3593112memory/system : 20373520memory/atom : 512601memory/atom_used : 491955memory/binary : 51432memory/code : 13401565memory/ets : 1082848

6.12.4 vm process

�� Erlang ����:

$ ./bin/emqx_ctl vm process

process/limit : 2097152process/count : 314

6.12.5 vm io

�� IO �����:

$ ./bin/emqx_ctl vm io

io/max_fds : 10240io/active_fds : 0

6.12.6 vm ports

�� VM ���:

$ ./bin/emqx_ctl vm ports

ports/count : 18ports/limit : 1048576

6.13 mnesia ��

�� mnesia ��������

6.14 log ��

log ������������� Documentation of logger �������

100 Chapter 6. ���� (Commands)

EMQ X - ����� MQTT �����, �� 3.1.0

log set-level <Level> ���������� Handlers ����log primary-level �������log primary-lelvel <Level> �������log handlers list ��������� Hanlderslog handlers set-level <HandlerId> <Level> ���� Hanlder �����

6.14.1 log set-level <Level>

���������� Handlers ����:

$ ./bin/emqx_ctl log set-level debug

debug

6.14.2 log primary-level

�������:

$ ./bin/emqx_ctl log primary-level

debug

6.14.3 log primary-level <Level>

�������:

$ ./bin/emqx_ctl log primary-level info

info

6.14.4 log handlers list

��������� Hanlders:

$ ./bin/emqx_ctl log handlers list

LogHandler(id=emqx_logger_handler, level=debug, destination=unknown)LogHandler(id=file, level=debug, destination=log/emqx.log)LogHandler(id=default, level=debug, destination=console)

6.14.5 log handlers set-level <HandlerId> <Level>

���� Hanlder �����:

$ ./bin/emqx_ctl log handlers set-level emqx_logger_handler error

error

6.14. log �� 101

EMQ X - ����� MQTT �����, �� 3.1.0

6.15 trace ��

trace ������������ Topic�����������

trace list ���������trace start client <ClientId> <File> [<Level>] �� Client ���������������trace stop client <ClientId> �� Client ��trace start topic <Topic> <File> [<Level>] �� Topic ���������������trace stop topic <Topic> �� Topic ��

��: �� trace �����������(primary logger level) ���������������������������� error�

6.15.1 trace start client <ClientId> <File> [<Level>]

�� Client ��:

$ ./bin/emqx_ctl log primary-level debug

debug

$ ./bin/emqx_ctl trace start client clientid log/clientid_trace.log

trace client clientid successfully

$ ./bin/emqx_ctl trace start client clientid2 log/clientid2_trace.log error

trace client_id clientid2 successfully

6.15.2 trace stop client <ClientId>

�� Client ��:

$ ./bin/emqx_ctl trace stop client clientid

stop tracing client_id clientid successfully

6.15.3 trace start topic <Topic> <File> [<Level>]

�� Topic ��:

$ ./bin/emqx_ctl log primary-level debug

debug

$ ./bin/emqx_ctl trace start topic topic log/topic_trace.log

trace topic topic successfully(����)

102 Chapter 6. ���� (Commands)

EMQ X - ����� MQTT �����, �� 3.1.0

(���)

$ ./bin/emqx_ctl trace start topic topic2 log/topic2_trace.log error

trace topic topic2 successfully

6.15.4 trace stop topic <Topic>

�� Topic ��:

$ ./bin/emqx_ctl trace topic topic off

stop tracing topic topic successfully

6.15.5 trace list

���������:

$ ./bin/emqx_ctl trace list

Trace(client_id=clientid2, level=error, destination="log/clientid2_trace.log")Trace(topic=topic2, level=error, destination="log/topic2_trace.log")

6.16 listeners

listeners ��������� TCP �����

listeners ����� TCP �����listeners stop <Proto> <Port> ������

6.16.1 listeners list

����� TCP �����:

$ ./bin/emqx_ctl listeners

listener on mqtt:ssl:8883acceptors : 16max_conns : 102400current_conn : 0shutdown_count : []

listener on mqtt:tcp:0.0.0.0:1883acceptors : 8max_conns : 1024000current_conn : 0shutdown_count : []

listener on mqtt:tcp:127.0.0.1:11883(����)

6.16. listeners 103

EMQ X - ����� MQTT �����, �� 3.1.0

(���)

acceptors : 4max_conns : 1024000current_conn : 2shutdown_count : []

listener on http:dashboard:18083acceptors : 2max_conns : 512current_conn : 0shutdown_count : []

listener on http:management:8080acceptors : 2max_conns : 512current_conn : 0shutdown_count : []

listener on mqtt:ws:8083acceptors : 2max_conns : 102400current_conn : 0shutdown_count : []

listener on mqtt:wss:8084acceptors : 2max_conns : 16current_conn : 0shutdown_count : []

listener ����:

acceptors TCP Acceptor �max_conns �������current_conns �����shutdown_count Socket ������

6.16.2 listeners stop <Proto> <Port>

������:

$ ./bin/emqx_ctl listeners stop mqtt:tcp 0.0.0.0:1883

Stop mqtt:tcp listener on 0.0.0.0:1883 successfully.

6.17 ����(rule engine) ��

6.18 rules ��

rules list List all rulesrules show <RuleId> Show a rulerules create <name> <hook> <sql> <actions> [-d [<descr>]] Create a rulerules delete <RuleId> Delete a rule

104 Chapter 6. ���� (Commands)

EMQ X - ����� MQTT �����, �� 3.1.0

6.18.1 rules create

��������:

## ������������������ 't/a' �������$ ./bin/emqx_ctl rules create \'test1' \'message.publish' \'select * from "t/a"' \'[{"name":"built_in:inspect_action", "params": {"a": 1}}]' \-d 'Rule for debug'

Rule test1:1556242324634254201 created

��: ������������ ID ������������������������� ID ������

6.18.2 rules list

���������:

$ ./bin/emqx_ctl rules list

rule(id='test1:1556242324634254201', name='test1', for='message.publish', rawsql='select␣↪→* from "t/a"', actions=[{"name":"built_in:inspect_action","params":{"a":1}}], enabled=↪→'true', description='Rule for debug')

6.18.3 rules show

����:

## �� RuleID � 'test1:1556242324634254201' ���$ ./bin/emqx_ctl rules show 'test1:1556242324634254201'

rule(id='test1:1556242324634254201', name='test1', for='message.publish', rawsql='select␣↪→* from "t/a"', actions=[{"name":"built_in:inspect_action","params":{"a":1}}], enabled=↪→'true', description='Rule for debug')

6.18.4 rules delete

����:

## �� RuleID � 'test1:1556242324634254201' ���$ ./bin/emqx_ctl rules delete 'test1:1556242324634254201'

ok

6.18. rules �� 105

EMQ X - ����� MQTT �����, �� 3.1.0

6.19 rule-actions ��

rule-actions list [-t [<type>]] [-k [<hook>]] List all actionsrule-actions show <ActionId> Show a rule action

��: ����� emqx ��(��������)���� emqx ���������� CLI/API ������

6.19.1 rule-actions show

����:

## ���� 'built_in:inspect_action' ��$ ./bin/emqx_ctl rule-actions show 'built_in:inspect_action'

action(name='built_in:inspect_action', app='emqx_rule_engine', for='$any', type='built_in↪→', params=#{}, description='Inspect the details of action params for debug purpose')

6.19.2 rule-actions list

���������:

## ���������$ ./bin/emqx_ctl rule-actions list

action(name='built_in:republish_action', app='emqx_rule_engine', for='message.publish',␣↪→type='built_in', params=#{target_topic => #{description => <<"Repubilsh the message to␣↪→which topic">>,format => topic,required => true,title => <<"To Which Topic">>,type =>␣↪→string}}, description='Republish a MQTT message to a another topic')action(name='web_hook:event_action', app='emqx_web_hook', for='$events', type='web_hook',↪→ params=#{'$resource' => #{description => <<"Bind a resource to this action">>,↪→required => true,title => <<"Resource ID">>,type => string},template => #{description␣↪→=> <<"The payload template to be filled with variables before sending messages">>,↪→required => false,schema => #{},title => <<"Payload Template">>,type => object}},␣↪→description='Forward Events to Web Server')action(name='web_hook:publish_action', app='emqx_web_hook', for='message.publish', type=↪→'web_hook', params=#{'$resource' => #{description => <<"Bind a resource to this action↪→">>,required => true,title => <<"Resource ID">>,type => string}}, description='Forward␣↪→Messages to Web Server')action(name='built_in:inspect_action', app='emqx_rule_engine', for='$any', type='built_in↪→', params=#{}, description='Inspect the details of action params for debug purpose')

## ��������� web_hook ���$ ./bin/emqx_ctl rule-actions list -t web_hook

action(name='web_hook:event_action', app='emqx_web_hook', for='$events', type='web_hook',↪→ params=#{'$resource' => #{description => <<"Bind a resource to this action">>,↪→required => true,title => <<"Resource ID">>,type => string},template => #{description␣↪→=> <<"The payload template to be filled with variables before sending messages">>,↪→required => false,schema => #{},title => <<"Payload Template">>,type => object}},␣↪→description='Forward Events to Web Server')

(����)

106 Chapter 6. ���� (Commands)

EMQ X - ����� MQTT �����, �� 3.1.0

(���)

action(name='web_hook:publish_action', app='emqx_web_hook', for='message.publish', type=↪→'web_hook', params=#{'$resource' => #{description => <<"Bind a resource to this action↪→">>,required => true,title => <<"Resource ID">>,type => string}}, description='Forward␣↪→Messages to Web Server')

## ���� Hook ���� 'client.connected' ���$ ./bin/emqx_ctl rule-actions list -k 'client.connected'

action(name='built_in:inspect_action', app='emqx_rule_engine', for='$any', type='built_in↪→', params=#{}, description='Inspect the details of action params for debug purpose')

6.20 resources ��

emqx_ctl resources create <name> <type> [-c [<config>]] [-d [<descr>]] Create a resourceresources list [-t <ResourceType>] List all resourcesresources show <ResourceId> Show a resourceresources delete <ResourceId> Delete a resource

6.20.1 resources create

��������:

$ ./bin/emqx_ctl resources create 'webhook1' 'web_hook' -c '{"url": "http://host-name/↪→chats"}' -d 'forward msgs to host-name/chats'

Resource web_hook:webhook1 created

6.20.2 resources list

���������:

$ ./bin/emqx_ctl resources list

resource(id='web_hook:webhook1', name='webhook1', type='web_hook', config=#{<<"url">> =>↪→<<"http://host-name/chats">>}, attrs=undefined, description='forward msgs to host-name/↪→chats')

6.20.3 resources list by type

���������:

$ ./bin/emqx_ctl resources list --type 'debug_resource_type'

resource(id='web_hook:webhook1', name='webhook1', type='web_hook', config=#{<<"url">> =>↪→<<"http://host-name/chats">>}, attrs=undefined, description='forward msgs to host-name/↪→chats')

6.20. resources �� 107

EMQ X - ����� MQTT �����, �� 3.1.0

6.20.4 resources show

����:

$ ./bin/emqx_ctl resources show 'web_hook:webhook1'

resource(id='web_hook:webhook1', name='webhook1', type='web_hook', config=#{<<"url">> =>↪→<<"http://host-name/chats">>}, attrs=undefined, description='forward msgs to host-name/↪→chats')

6.20.5 resources delete

����:

$ ./bin/emqx_ctl resources delete 'web_hook:webhook1'

ok

6.21 resource-types ��

resource-types list List all resource-typesresource-types show <Type> Show a resource-type

��: ������� emqx ��(����������)���� emqx ���������� CLI/API ������

6.21.1 resource-types list

�����������:

./bin/emqx_ctl resource-types list

resource_type(name='built_in', provider='emqx_rule_engine', params=#{}, on_create={emqx_↪→rule_actions,on_resource_create}, description='The built in resource type for debug␣↪→purpose')resource_type(name='web_hook', provider='emqx_web_hook', params=#{headers => #{default =>↪→ #{},description => <<"Request Header">>,schema => #{},title => <<"Request Header">>,↪→type => object},method => #{default => <<"POST">>,description => <<"Request Method">>,↪→enum => [<<"PUT">>,<<"POST">>],title => <<"Request Method">>,type => string},url => #↪→{description => <<"Request URL">>,format => url,required => true,title => <<"Request␣↪→URL">>,type => string}}, on_create={emqx_web_hook_actions,on_resource_create},␣↪→description='WebHook Resource')

6.21.2 resource-types show

������:

108 Chapter 6. ���� (Commands)

EMQ X - ����� MQTT �����, �� 3.1.0

$ ./bin/emqx_ctl resource-types show built_in

resource_type(name='built_in', provider='emqx_rule_engine', params=#{}, on_create={emqx_↪→rule_actions,on_resource_create}, description='The built in resource type for debug␣↪→purpose')

6.22 recon ��

recon memory recon_alloc:memory/2recon allocated recon_alloc:memory(allocated_types, current/max)recon bin_leak recon:bin_leak(100)recon node_stats recon:node_stats(10, 1000)recon remote_load Mod recon:remote_load(Mod)

�� Documentation for recon ��������

6.22.1 recon memory

recon_alloc:memory/2:

$ ./bin/emqx_ctl recon memory

usage/current : 0.810331960305788usage/max : 0.7992495929358717used/current : 84922296used/max : 122519208allocated/current : 104345600allocated/max : 153292800unused/current : 19631520unused/max : 30773592

6.22.2 recon allocated

recon_alloc:memory(allocated_types, current/max):

$ ./bin/emqx_ctl recon allocated

binary_alloc/current: 425984driver_alloc/current: 425984eheap_alloc/current : 4063232ets_alloc/current : 3833856fix_alloc/current : 1474560ll_alloc/current : 90439680sl_alloc/current : 163840std_alloc/current : 2260992temp_alloc/current : 655360binary_alloc/max : 4907008

(����)

6.22. recon �� 109

EMQ X - ����� MQTT �����, �� 3.1.0

(���)

driver_alloc/max : 425984eheap_alloc/max : 25538560ets_alloc/max : 5931008fix_alloc/max : 1736704ll_alloc/max : 90439680sl_alloc/max : 20348928std_alloc/max : 2260992temp_alloc/max : 1703936

6.22.3 recon bin_leak

recon:bin_leak(100):

$ ./bin/emqx_ctl recon bin_leak

{<10623.1352.0>,-3,[cowboy_clock,{current_function,{gen_server,loop,7}},{initial_call,{proc_lib,init_p,5}}]}

{<10623.3865.0>,0,[{current_function,{recon_lib,proc_attrs,2}},{initial_call,{erlang,apply,2}}]}

{<10623.3863.0>,0,[{current_function,{dist_util,con_loop,2}},{initial_call,{inet_tcp_dist,do_accept,7}}]}...

6.22.4 recon node_stats

recon:node_stats(10, 1000):

$ ./bin/emqx_ctl recon node_stats

{[{process_count,302},{run_queue,0},{memory_total,88925536},{memory_procs,27999296},{memory_atoms,1182843},{memory_bin,24536},{memory_ets,7163216}],

[{bytes_in,62},{bytes_out,458},{gc_count,4},{gc_words_reclaimed,3803},{reductions,3036},{scheduler_usage,[{1,9.473889959272245e-4},

{2,5.085983030767205e-5},{3,5.3851477624711046e-5},{4,7.579021269127057e-5},

(����)

110 Chapter 6. ���� (Commands)

EMQ X - ����� MQTT �����, �� 3.1.0

(���)

{5,0.0},{6,0.0},{7,0.0},{8,0.0}]}]}

...

6.22.5 recon remote_load Mod

recon:remote_load(Mod):

$ ./bin/emqx_ctl recon remote_load

6.23 retainer ��

retainer info ���������retainer topics �����������retainer clean ���������

6.23.1 retainer info

���������:

$ ./bin/emqx_ctl retainer info

retained/total: 3

6.23.2 retainer topics

�����������:

$ ./bin/emqx_ctl retainer topics

$SYS/brokers/[email protected]/version$SYS/brokers/[email protected]/sysdescr$SYS/brokers

6.23.3 retainer clean

���������:

$ ./bin/emqx_ctl retainer clean

Cleaned 3 retained messages

6.23. retainer �� 111

EMQ X - ����� MQTT �����, �� 3.1.0

6.24 admins ��

Dashboard ������� admins ������������������������

admins add <Username> <Password> <Tags> �� admin ��admins passwd <Username> <Password> �� admin ��admins del <Username> �� admin ��

6.24.1 admins add <Username> <Password> <Tags>

�� admin ��:

$ ./bin/emqx_ctl admins add root public test

ok

6.24.2 admins passwd <Username> <Password>

�� admin ����:

$ ./bin/emqx_ctl admins passwd root private

ok

6.24.3 admins del <Username>

�� admin ��:

$ ./bin/emqx_ctl admins del root

ok

112 Chapter 6. ���� (Commands)

CHAPTER 7

����API (REST API)

������ REST API �� MQTT �����(Connections)���(Sessions)���(Subscriptions)���(Routes)�������������������������

7.1 URL ��

REST API ��URL��:

http(s)://host:8080/api/v3/

7.2 Basic ��

�� REST API ���� HTTP Basic �����(Authentication)���������� Dashboard ����� AppID � AppSecret ����:

# �����������curl -v --basic -u <appid>:<appsecret> -k http://localhost:8080/api/v3/brokers

7.3 API ��

7.3.1 ���� REST API ��

API ��:

GET api/v3/

����:

113

EMQ X - ����� MQTT �����, �� 3.1.0

GET api/v3/

����:

{"code": 0,"data": [{

"name": "list_clientid","method": "GET","path": "/auth_clientid","descr": "List available clientid in the cluster"

},{

"name": "lookup_clientid","method": "GET","path": "/auth_clientid/:clientid","descr": "Lookup clientid in the cluster"

},{

"name": "add_clientid","method": "POST","path": "/auth_clientid","descr": "Add clientid in the cluster"

},{

"name": "update_clientid","method": "PUT","path": "/auth_clientid/:clientid","descr": "Update clientid in the cluster"

},{

"name": "delete_clientid","method": "DELETE","path": "/auth_clientid/:clientid","descr": "Delete clientid in the cluster"

},{

"name": "list_username","method": "GET","path": "/auth_username","descr": "List available username in the cluster"

},{

"name": "lookup_username","method": "GET","path": "/auth_username/:username","descr": "Lookup username in the cluster"

},{

"name": "add_username","method": "POST","path": "/auth_username",

(����)

114 Chapter 7. ����API (REST API)

EMQ X - ����� MQTT �����, �� 3.1.0

(���)

"descr": "Add username in the cluster"},{

"name": "update_username","method": "PUT","path": "/auth_username/:username","descr": "Update username in the cluster"

},{

"name": "delete_username","method": "DELETE","path": "/auth_username/:username","descr": "Delete username in the cluster"

},{

"name": "list_all_alarms","method": "GET","path": "/alarms/","descr": "List all alarms"

},{

"name": "list_node_alarms","method": "GET","path": "/alarms/:node","descr": "List alarms of a node"

},{

"name": "list_banned","method": "GET","path": "/banned/","descr": "List banned"

},{

"name": "create_banned","method": "POST","path": "/banned/","descr": "Create banned"

},{

"name": "delete_banned","method": "DELETE","path": "/banned/:who","descr": "Delete banned"

},{

"name": "list_brokers","method": "GET","path": "/brokers/","descr": "A list of brokers in the cluster"

},{

"name": "get_broker",(����)

7.3. API �� 115

EMQ X - ����� MQTT �����, �� 3.1.0

(���)

"method": "GET","path": "/brokers/:node","descr": "Get broker info of a node"

},{

"name": "get_all_configs","method": "GET","path": "/configs/","descr": "Get all configs"

},{

"name": "get_all_configs","method": "GET","path": "/nodes/:node/configs/","descr": "Get all configs of a node"

},{

"name": "update_config","method": "PUT","path": "/configs/:app","descr": "Update config of an application in the cluster"

},{

"name": "update_node_config","method": "PUT","path": "/nodes/:node/configs/:app","descr": "Update config of an application on a node"

},{

"name": "get_plugin_configs","method": "GET","path": "/nodes/:node/plugin_configs/:plugin","descr": "Get configurations of a plugin on the node"

},{

"name": "update_plugin_configs","method": "PUT","path": "/nodes/:node/plugin_configs/:plugin","descr": "Update configurations of a plugin on the node"

},{

"name": "list_connections","method": "GET","path": "/connections/","descr": "A list of connections in the cluster"

},{

"name": "list_node_connections","method": "GET","path": "nodes/:node/connections/","descr": "A list of connections on a node"

},(����)

116 Chapter 7. ����API (REST API)

EMQ X - ����� MQTT �����, �� 3.1.0

(���)

{"name": "lookup_node_connections","method": "GET","path": "nodes/:node/connections/:clientid","descr": "Lookup a connection on node"

},{

"name": "lookup_connections","method": "GET","path": "/connections/:clientid","descr": "Lookup a connection in the cluster"

},{

"name": "lookup_node_connection_via_username","method": "GET","path": "/nodes/:node/connection/username/:username","descr": "Lookup a connection via username in the cluster "

},{

"name": "lookup_connection_via_username","method": "GET","path": "/connection/username/:username","descr": "Lookup a connection via username on a node "

},{

"name": "kickout_connection","method": "DELETE","path": "/connections/:clientid","descr": "Kick out a connection"

},{

"name": "list_listeners","method": "GET","path": "/listeners/","descr": "A list of listeners in the cluster"

},{

"name": "list_node_listeners","method": "GET","path": "/nodes/:node/listeners","descr": "A list of listeners on the node"

},{

"name": "list_all_metrics","method": "GET","path": "/metrics/","descr": "A list of metrics of all nodes in the cluster"

},{

"name": "list_node_metrics","method": "GET","path": "/nodes/:node/metrics/",

(����)

7.3. API �� 117

EMQ X - ����� MQTT �����, �� 3.1.0

(���)

"descr": "A list of metrics of a node"},{

"name": "list_nodes","method": "GET","path": "/nodes/","descr": "A list of nodes in the cluster"

},{

"name": "get_node","method": "GET","path": "/nodes/:node","descr": "Lookup a node in the cluster"

},{

"name": "list_all_plugins","method": "GET","path": "/plugins/","descr": "List all plugins in the cluster"

},{

"name": "list_node_plugins","method": "GET","path": "/nodes/:node/plugins/","descr": "List all plugins on a node"

},{

"name": "load_plugin","method": "PUT","path": "/nodes/:node/plugins/:plugin/load","descr": "Load a plugin"

},{

"name": "unload_plugin","method": "PUT","path": "/nodes/:node/plugins/:plugin/unload","descr": "Unload a plugin"

},{

"name": "mqtt_subscribe","method": "POST","path": "/mqtt/subscribe","descr": "Subscribe a topic"

},{

"name": "mqtt_publish","method": "POST","path": "/mqtt/publish","descr": "Publish a MQTT message"

},{

"name": "mqtt_unsubscribe",(����)

118 Chapter 7. ����API (REST API)

EMQ X - ����� MQTT �����, �� 3.1.0

(���)

"method": "POST","path": "/mqtt/unsubscribe","descr": "Unsubscribe a topic"

},{

"name": "list_routes","method": "GET","path": "/routes/","descr": "List routes"

},{

"name": "lookup_routes","method": "GET","path": "/routes/:topic","descr": "Lookup routes to a topic"

},{

"name": "list_sessions","method": "GET","path": "/sessions/","descr": "A list of sessions in the cluster"

},{

"name": "list_node_sessions","method": "GET","path": "nodes/:node/sessions/","descr": "A list of sessions on a node"

},{

"name": "lookup_session","method": "GET","path": "/sessions/:clientid","descr": "Lookup a session in the cluster"

},{

"name": "lookup_node_session","method": "GET","path": "nodes/:node/sessions/:clientid","descr": "Lookup a session on the node"

},{

"name": "list_stats","method": "GET","path": "/stats/","descr": "A list of stats of all nodes in the cluster"

},{

"name": "lookup_node_stats","method": "GET","path": "/nodes/:node/stats/","descr": "A list of stats of a node"

},(����)

7.3. API �� 119

EMQ X - ����� MQTT �����, �� 3.1.0

(���)

{"name": "list_subscriptions","method": "GET","path": "/subscriptions/","descr": "A list of subscriptions in the cluster"

},{

"name": "list_node_subscriptions","method": "GET","path": "/nodes/:node/subscriptions/","descr": "A list of subscriptions on a node"

},{

"name": "lookup_client_subscriptions","method": "GET","path": "/subscriptions/:clientid","descr": "A list of subscriptions of a client"

},{

"name": "lookup_client_subscriptions_with_node","method": "GET","path": "/nodes/:node/subscriptions/:clientid","descr": "A list of subscriptions of a client on the node"

},{

"name": "create_rule","method": "POST","path": "/rules/","descr": "Create a rule"

},{

"name": "list_rules","method": "GET","path": "/rules/","descr": "A list of all rules"

},{

"name": "show_rule","method": "GET","path": "/rules/:id","descr": "Show a rule"

},{

"name": "delete_rule","method": "DELETE","path": "/rules/:id","descr": "Delete a rule"

},{

"name": "list_actions","method": "GET","path": "/actions/",

(����)

120 Chapter 7. ����API (REST API)

EMQ X - ����� MQTT �����, �� 3.1.0

(���)

"descr": "A list of all actions"},{

"name": "show_action","method": "GET","path": "/actions/:name","descr": "Show an action"

},{

"name": "list_resources","method": "GET","path": "/resources/","descr": "A list of all resources"

},{

"name": "create_resource","method": "POST","path": "/resources/","descr": "Create a resource"

},{

"name": "show_resource","method": "GET","path": "/resources/:id","descr": "Show a resource"

},{

"name": "delete_resource","method": "DELETE","path": "/resources/:id","descr": "Delete a resource"

},{

"name": "list_resource_types","method": "GET","path": "/resource_types/","descr": "List all resource types"

},{

"name": "show_resource_type","method": "GET","path": "/resource_types/:name","descr": "Show a resource type"

},{

"name": "list_resources_by_type","method": "GET","path": "/resource_types/:type/resources","descr": "List all resources of a resource type"

},{

"name": "list_actions_by_type",(����)

7.3. API �� 121

EMQ X - ����� MQTT �����, �� 3.1.0

(���)

"method": "GET","path": "/resource_types/:type/actions","descr": "List all actions of a resource type"

}]}

7.4 �����

7.4.1 ��������

API ��:

GET api/v3/brokers/

����:

GET api/v3/brokers/

����:

{"code": 0,"data": [{"datetime": "2019-04-29 10:56:41","node": "[email protected]","node_status": "Running","otp_release": "R21/10.3.2","sysdescr": "EMQ X Broker","uptime": "3 minutes, 59 seconds","version": "v3.1.0"

}]

}

7.4.2 ��������

API ��:

GET api/v3/brokers/${node}

����:

GET api/v3/brokers/[email protected]

����:

{"code": 0,

(����)

122 Chapter 7. ����API (REST API)

EMQ X - ����� MQTT �����, �� 3.1.0

(���)

"data": {"datetime": "2019-04-29 10:59:59","node_status": "Running","otp_release": "R21/10.3.2","sysdescr": "EMQ X Broker","uptime": "7 minutes, 16 seconds","version": "v3.1.0"

}}

7.4.3 ��������

API ��:

GET api/v3/nodes/

����:

GET api/v3/nodes/

����:

{"code": 0,"data": [{"connections": 2,"load1": "2.75","load15": "2.87","load5": "2.57","max_fds": 7168,"memory_total": "76.45M","memory_used": "59.48M","name": "[email protected]","node": "[email protected]","node_status": "Running","otp_release": "R21/10.3.2","process_available": 262144,"process_used": 331,"uptime": "1 days,18 hours, 45 minutes, 1 seconds","version": "v3.1.0"

}]

}

7.4.4 ��������

API ��:

GET api/v3/nodes/${node}

7.4. ����� 123

EMQ X - ����� MQTT �����, �� 3.1.0

����:

GET api/v3/nodes/[email protected]

����:

{"code": 0,"data": {"connections": 1,"load1": "2.75","load15": "2.87","load5": "2.57","max_fds": 7168,"memory_total": 80162816,"memory_used": 62254160,"name": "[email protected]","node_status": "Running","otp_release": "R21/10.3.2","process_available": 262144,"process_used": 331,"uptime": "1 days,18 hours, 45 minutes, 1 seconds","version": "v3.1.0"

}}

7.5 ����(Connections)

7.5.1 ��������

API ��:

GET api/v3/connections/

����:

GET api/v3/connections/?_page=1&_limit=10000

����:

{"code": 0,"data": [{"clean_start": true,"client_id": "mosquitto_mqtt","conn_mod": "emqx_connection","connected_at": "2019-04-29 11:05:01","heap_size": 2586,"ipaddress": "127.0.0.1","is_bridge": false,"keepalive": 60,

(����)

124 Chapter 7. ����API (REST API)

EMQ X - ����� MQTT �����, �� 3.1.0

(���)

"mailbox_len": 0,"node": "[email protected]","peercert": "nossl","port": 64899,"proto_name": "MQIsdp","proto_ver": 3,"recv_cnt": 2,"recv_msg": 0,"recv_oct": 47,"recv_pkt": 2,"reductions": 3588,"send_cnt": 2,"send_msg": 0,"send_oct": 9,"send_pend": 0,"send_pkt": 2,"username": "undefined","zone": "external"

}],"meta": {"page": 1,"limit": 10000,"count": 1

}}

7.5.2 ��������

API ��:

GET api/v3/nodes/${node}/connections/

����:

GET api/v3/nodes/[email protected]/connections/?_page=1&_limit=10000

����:

{"code": 0,"data": [{

"clean_start": true,"client_id": "mosquitto_mqtt","conn_mod": "emqx_connection","connected_at": "2019-04-29 11:05:01","heap_size": 610,"ipaddress": "127.0.0.1","is_bridge": false,"keepalive": 60,

(����)

7.5. ����(Connections) 125

EMQ X - ����� MQTT �����, �� 3.1.0

(���)

"mailbox_len": 0,"node": "[email protected]","peercert": "nossl","port": 64899,"proto_name": "MQIsdp","proto_ver": 3,"recv_cnt": 5,"recv_msg": 0,"recv_oct": 53,"recv_pkt": 5,"reductions": 6081,"send_cnt": 5,"send_msg": 0,"send_oct": 15,"send_pend": 0,"send_pkt": 5,"username": "undefined","zone": "external"

}],"meta": {

"page": 1,"limit": 10000,"count": 1

}}

7.5.3 ����������

API ��:

GET api/v3/connections/${clientid}

����:

GET api/v3/connections/mosquitto_mqtt

����:

{"code": 0,"data": [{

"clean_start": true,"client_id": "mosquitto_mqtt","conn_mod": "emqx_connection","connected_at": "2019-04-29 11:05:01","heap_size": 610,"ipaddress": "127.0.0.1","is_bridge": false,"keepalive": 60,

(����)

126 Chapter 7. ����API (REST API)

EMQ X - ����� MQTT �����, �� 3.1.0

(���)

"mailbox_len": 0,"node": "[email protected]","peercert": "nossl","port": 64899,"proto_name": "MQIsdp","proto_ver": 3,"recv_cnt": 8,"recv_msg": 0,"recv_oct": 59,"recv_pkt": 8,"reductions": 8560,"send_cnt": 8,"send_msg": 0,"send_oct": 21,"send_pend": 0,"send_pkt": 8,"username": "undefined","zone": "external"

}]

}

7.5.4 ����������

API ��:

GET api/v3/nodes/${node}/connections/${clientid}

����:

GET api/v3/nodes/[email protected]/connections/mosquitto_mqtt

����:

{"code": 0,"data": [{

"clean_start": true,"client_id": "mosquitto_mqtt","conn_mod": "emqx_connection","connected_at": "2019-04-29 11:05:01","heap_size": 610,"ipaddress": "127.0.0.1","is_bridge": false,"keepalive": 60,"mailbox_len": 0,"node": "[email protected]","peercert": "nossl","port": 64899,"proto_name": "MQIsdp",

(����)

7.5. ����(Connections) 127

EMQ X - ����� MQTT �����, �� 3.1.0

(���)

"proto_ver": 3,"recv_cnt": 14,"recv_msg": 0,"recv_oct": 71,"recv_pkt": 14,"reductions": 13534,"send_cnt": 14,"send_msg": 0,"send_oct": 33,"send_pend": 0,"send_pkt": 14,"username": "undefined","zone": "external"

}]

}

7.5.5 ������

API ��:

DELETE api/v3/connections/${clientid}

����:

DELETE api/v3/connections/mosquitto_mqtt

����:

{"code": 0

}

7.6 ��(Sessions)

7.6.1 ��������

API ��:

GET api/v3/sessions/

����:

GET api/v3/sessions/?_page=1&_limit=10000

����:

{"code": 0,

(����)

128 Chapter 7. ����API (REST API)

EMQ X - ����� MQTT �����, �� 3.1.0

(���)

"data": [{

"awaiting_rel_len": 0,"binding": "local","clean_start": true,"client_id": "mqttjs_f79fbc5a4b","created_at": "2019-04-29 11:28:04","deliver_msg": 0,"enqueue_msg": 0,"expiry_interval": 0,"heap_size": 233,"inflight_len": 0,"mailbox_len": 0,"max_awaiting_rel": 100,"max_inflight": 32,"max_mqueue": 1000,"max_subscriptions": 0,"mqueue_dropped": 0,"mqueue_len": 0,"node": "[email protected]","reductions": 211,"subscriptions_count": 0,"username": ""

},{

"awaiting_rel_len": 0,"binding": "local","clean_start": true,"client_id": "mosquitto_mqtt","created_at": "2019-04-29 11:28:28","deliver_msg": 0,"enqueue_msg": 0,"expiry_interval": 0,"heap_size": 376,"inflight_len": 0,"mailbox_len": 0,"max_awaiting_rel": 100,"max_inflight": 32,"max_mqueue": 1000,"max_subscriptions": 0,"mqueue_dropped": 0,"mqueue_len": 0,"node": "[email protected]","reductions": 202,"subscriptions_count": 0,"username": "undefined"

}],"meta": {

"page": 1,"limit": 10000,"count": 2

(����)

7.6. ��(Sessions) 129

EMQ X - ����� MQTT �����, �� 3.1.0

(���)

}}

7.6.2 ����������

API ��:

GET api/v3/sessions/${clientid}

����:

GET api/v3/sessions/mosquitto_mqtt

����:

{"code": 0,"data": [{

"awaiting_rel_len": 0,"binding": "local","clean_start": true,"client_id": "mosquitto_mqtt","created_at": "2019-04-29 11:28:28","deliver_msg": 0,"enqueue_msg": 0,"expiry_interval": 0,"heap_size": 376,"inflight_len": 0,"mailbox_len": 0,"max_awaiting_rel": 100,"max_inflight": 32,"max_mqueue": 1000,"max_subscriptions": 0,"mqueue_dropped": 0,"mqueue_len": 0,"node": "[email protected]","reductions": 453,"subscriptions_count": 1,"username": "undefined"

}]

}

7.6.3 ��������

API ��:

GET api/v3/nodes/${node}/sessions/

����:

130 Chapter 7. ����API (REST API)

EMQ X - ����� MQTT �����, �� 3.1.0

GET api/v3/nodes/[email protected]/sessions/?_page=1&_limit=10000

����:

{"code": 0,"data": [{

"awaiting_rel_len": 0,"binding": "local","clean_start": true,"client_id": "mqttjs_f79fbc5a4b","created_at": "2019-04-29 11:28:04","deliver_msg": 0,"enqueue_msg": 0,"expiry_interval": 0,"heap_size": 233,"inflight_len": 0,"mailbox_len": 0,"max_awaiting_rel": 100,"max_inflight": 32,"max_mqueue": 1000,"max_subscriptions": 0,"mqueue_dropped": 0,"mqueue_len": 0,"node": "[email protected]","reductions": 211,"subscriptions_count": 0,"username": ""

},{

"awaiting_rel_len": 0,"binding": "local","clean_start": true,"client_id": "mosquitto_mqtt","created_at": "2019-04-29 11:28:28","deliver_msg": 0,"enqueue_msg": 0,"expiry_interval": 0,"heap_size": 376,"inflight_len": 0,"mailbox_len": 0,"max_awaiting_rel": 100,"max_inflight": 32,"max_mqueue": 1000,"max_subscriptions": 0,"mqueue_dropped": 0,"mqueue_len": 0,"node": "[email protected]","reductions": 453,"subscriptions_count": 1,"username": "undefined"

}(����)

7.6. ��(Sessions) 131

EMQ X - ����� MQTT �����, �� 3.1.0

(���)

],"meta": {

"page": 1,"limit": 10000,"count": 2

}}

7.6.4 ����������

API ��:

GET api/v3/nodes/${node}/sessions/${clientid}

����:

GET api/v3/nodes/[email protected]/sessions/mosquitto_mqtt

����:

{"topic": "test_topic","payload": "hello","qos": 1,"retain": false,"client_id": "mqttjs_ab9069449e"

}

����:

{"code": 0,"data": [{

"awaiting_rel_len": 0,"binding": "local","clean_start": true,"client_id": "mosquitto_mqtt","created_at": "2018-09-12 10:42:57","deliver_msg": 0,"enqueue_msg": 0,"expiry_interval": 7200,"heap_size": 376,"inflight_len": 0,"mailbox_len": 0,"max_awaiting_rel": 100,"max_inflight": 32,"max_mqueue": 1000,"max_subscriptions": 0,"mqueue_dropped": 0,"mqueue_len": 0,

(����)

132 Chapter 7. ����API (REST API)

EMQ X - ����� MQTT �����, �� 3.1.0

(���)

"node": "[email protected]","reductions": 203,"subscriptions_count": 0,"username": "mosquitto_mqtt"

}]

}

7.7 ��(Subscriptions)

7.7.1 ��������

API ��:

GET api/v3/subscriptions/

����:

GET api/v3/subscriptions/?_page=1&_limit=10000

����:

{"code": 0,"data": [{

"client_id": "mqttjs_f79fbc5a4b","node": "[email protected]","qos": 0,"topic": "testtopic/#"

},{

"client_id": "mosquitto_mqtt","node": "[email protected]","qos": 0,"topic": "t"

}],"meta": {

"page": 1,"limit": 10000,"count": 2

}}

7.7.2 ������������

API ��:

7.7. ��(Subscriptions) 133

EMQ X - ����� MQTT �����, �� 3.1.0

GET api/v3/subscriptions/${clientid}

����:

GET api/v3/subscriptions/mosquitto_mqtt

����:

{"code": 0,"data": [{

"client_id": "mosquitto_mqtt","node": "[email protected]","qos": 0,"topic": "t"

}]

}

7.7.3 ��������

API ��:

GET api/v3/nodes/${node}/subscriptions/

����:

GET api/v3/nodes/[email protected]/subscriptions/?_page=1&_limit=10000

����:

{"code": 0,"data": [{

"client_id": "mqttjs_f79fbc5a4b","node": "[email protected]","qos": 0,"topic": "testtopic/#"

},{

"client_id": "mosquitto_mqtt","node": "[email protected]","qos": 0,"topic": "t"

}],"meta": {

"page": 1,"limit": 10000,"count": 2

(����)

134 Chapter 7. ����API (REST API)

EMQ X - ����� MQTT �����, �� 3.1.0

(���)

}}

7.7.4 ������������

API ��:

GET api/v3/nodes/${node}/subscriptions/${clientid}

����:

GET api/v3/nodes/[email protected]/subscriptions/mosquitto_mqtt

����:

{"code": 0,"data": [{

"client_id": "mosquitto_mqtt","node": "[email protected]","qos": 0,"topic": "t"

}]

}

7.8 ��(Routes)

7.8.1 �������

API ��:

GET api/v3/routes/

����:

GET api/v3/routes/

����:

{"code": 0,"data": [{

"node": "[email protected]","topic": "testtopic/#"

},{

(����)

7.8. ��(Routes) 135

EMQ X - ����� MQTT �����, �� 3.1.0

(���)

"node": "[email protected]","topic": "t"

}],"meta": {

"page": 1,"limit": 10000,"count": 2

}}

7.8.2 �������������

API ��:

GET api/v3/routes/${topic}

����:

GET api/v3/routes/t

����:

{"code": 0,"data": [{

"node": "[email protected]","topic": "t"

}]

}

7.9 ��/��/����

7.9.1 ����

API ��:

POST api/v3/mqtt/publish

����:

{"topic": "test_topic","payload": "hello","qos": 1,"retain": false,"client_id": "mqttjs_ab9069449e"

}

136 Chapter 7. ����API (REST API)

EMQ X - ����� MQTT �����, �� 3.1.0

����:

POST api/v3/mqtt/publish

����:

{"code": 0

}

7.9.2 ����

API ��:

POST api/v3/mqtt/subscribe

����:

{"topic": "test_topic","qos": 1,"client_id": "mqttjs_ab9069449e"

}

����:

POST api/v3/mqtt/subscribe

����:

{"code": 0

}

7.9.3 ����

API ��:

POST api/v3/mqtt/unsubscribe

����:

{"topic": "test_topic","client_id": "mqttjs_ab9069449e"

}

����:

POST api/v3/mqtt/unsubscribe

����:

7.9. ��/��/���� 137

EMQ X - ����� MQTT �����, �� 3.1.0

{"code": 0

}

7.10 ��(Plugins)

7.10.1 ����������

API ��:

GET api/v3/plugins/

����:

GET api/v3/plugins/

����:

{"code": 0,"data": [{

"node": "[email protected]","plugins": [{

"name": "emqx_auth_clientid","version": "v3.1.0","description": "EMQ X Authentication with ClientId/Password","active": false

},{

"name": "emqx_auth_http","version": "v3.1.0","description": "EMQ X Authentication/ACL with HTTP API","active": false

},{

"name": "emqx_auth_jwt","version": "v3.1.0","description": "EMQ X Authentication with JWT","active": false

},{

"name": "emqx_auth_ldap","version": "v3.1.0","description": "EMQ X Authentication/ACL with LDAP","active": false

},{

"name": "emqx_auth_mongo","version": "v3.1.0",

(����)

138 Chapter 7. ����API (REST API)

EMQ X - ����� MQTT �����, �� 3.1.0

(���)

"description": "EMQ X Authentication/ACL with MongoDB","active": false

},{

"name": "emqx_auth_mysql","version": "v3.1.0","description": "EMQ X Authentication/ACL with MySQL","active": false

},{

"name": "emqx_auth_pgsql","version": "v3.1.0","description": "EMQ X Authentication/ACL with PostgreSQL","active": false

},{

"name": "emqx_auth_redis","version": "v3.1.0","description": "EMQ X Authentication/ACL with Redis","active": false

},{

"name": "emqx_auth_username","version": "v3.1.0","description": "EMQ X Authentication with Username and Password","active": false

},{

"name": "emqx_coap","version": "v3.1.0","description": "EMQ X CoAP Gateway","active": false

},{

"name": "emqx_dashboard","version": "v3.1.0","description": "EMQ X Web Dashboard","active": true

},{

"name": "emqx_delayed_publish","version": "v3.1.0","description": "EMQ X Delayed Publish","active": false

},{

"name": "emqx_lua_hook","version": "v3.1.0","description": "EMQ X Lua Hooks","active": false

},{

(����)

7.10. ��(Plugins) 139

EMQ X - ����� MQTT �����, �� 3.1.0

(���)

"name": "emqx_lwm2m","version": "v3.1.0","description": "EMQ X LwM2M Gateway","active": false

},{

"name": "emqx_management","version": "v3.1.0","description": "EMQ X Management API and CLI","active": true

},{

"name": "emqx_plugin_template","version": "v3.1.0","description": "EMQ X Plugin Template","active": false

},{

"name": "emqx_psk_file","version": "v3.1.0","description": "EMQX PSK Plugin from File","active": false

},{

"name": "emqx_recon","version": "v3.1.0","description": "EMQ X Recon Plugin","active": true

},{

"name": "emqx_reloader","version": "v3.1.0","description": "EMQ X Reloader Plugin","active": false

},{

"name": "emqx_retainer","version": "v3.1.0","description": "EMQ X Retainer","active": true

},{

"name": "emqx_rule_engine","version": "v3.1.0","description": "EMQ X Rule Engine","active": true

},{

"name": "emqx_sn","version": "v3.1.0","description": "EMQ X MQTT SN Plugin","active": false

(����)

140 Chapter 7. ����API (REST API)

EMQ X - ����� MQTT �����, �� 3.1.0

(���)

},{

"name": "emqx_statsd","version": "v3.1.0","description": "Statsd for EMQ X","active": false

},{

"name": "emqx_stomp","version": "v3.1.0","description": "EMQ X Stomp Protocol Plugin","active": false

},{

"name": "emqx_web_hook","version": "v3.1.0","description": "EMQ X Webhook Plugin","active": false

}]

}]

}

7.10.2 ��������

API ��:

GET api/v3/nodes/${node}/plugins/

����:

GET api/v3/nodes/[email protected]/plugins/

����:

{"code": 0,"data": [{"name": "emqx_auth_clientid","version": "v3.1.0","description": "EMQ X Authentication with ClientId/Password","active": false

},{"name": "emqx_auth_http","version": "v3.1.0","description": "EMQ X Authentication/ACL with HTTP API","active": false

},(����)

7.10. ��(Plugins) 141

EMQ X - ����� MQTT �����, �� 3.1.0

(���)

{"name": "emqx_auth_jwt","version": "v3.1.0","description": "EMQ X Authentication with JWT","active": false

},{"name": "emqx_auth_ldap","version": "v3.1.0","description": "EMQ X Authentication/ACL with LDAP","active": false

},{"name": "emqx_auth_mongo","version": "v3.1.0","description": "EMQ X Authentication/ACL with MongoDB","active": false

},{"name": "emqx_auth_mysql","version": "v3.1.0","description": "EMQ X Authentication/ACL with MySQL","active": false

},{"name": "emqx_auth_pgsql","version": "v3.1.0","description": "EMQ X Authentication/ACL with PostgreSQL","active": false

},{"name": "emqx_auth_redis","version": "v3.1.0","description": "EMQ X Authentication/ACL with Redis","active": false

},{"name": "emqx_auth_username","version": "v3.1.0","description": "EMQ X Authentication with Username and Password","active": false

},{"name": "emqx_coap","version": "v3.1.0","description": "EMQ X CoAP Gateway","active": false

},{"name": "emqx_dashboard","version": "v3.1.0","description": "EMQ X Web Dashboard",

(����)

142 Chapter 7. ����API (REST API)

EMQ X - ����� MQTT �����, �� 3.1.0

(���)

"active": true},{"name": "emqx_delayed_publish","version": "v3.1.0","description": "EMQ X Delayed Publish","active": false

},{"name": "emqx_lua_hook","version": "v3.1.0","description": "EMQ X Lua Hooks","active": false

},{"name": "emqx_lwm2m","version": "v3.1.0","description": "EMQ X LwM2M Gateway","active": false

},{"name": "emqx_management","version": "v3.1.0","description": "EMQ X Management API and CLI","active": true

},{"name": "emqx_plugin_template","version": "v3.1.0","description": "EMQ X Plugin Template","active": false

},{"name": "emqx_psk_file","version": "v3.1.0","description": "EMQX PSK Plugin from File","active": false

},{"name": "emqx_recon","version": "v3.1.0","description": "EMQ X Recon Plugin","active": true

},{"name": "emqx_reloader","version": "v3.1.0","description": "EMQ X Reloader Plugin","active": false

},{"name": "emqx_retainer",

(����)

7.10. ��(Plugins) 143

EMQ X - ����� MQTT �����, �� 3.1.0

(���)

"version": "v3.1.0","description": "EMQ X Retainer","active": true

},{"name": "emqx_rule_engine","version": "v3.1.0","description": "EMQ X Rule Engine","active": true

},{"name": "emqx_sn","version": "v3.1.0","description": "EMQ X MQTT SN Plugin","active": false

},{"name": "emqx_statsd","version": "v3.1.0","description": "Statsd for EMQ X","active": false

},{"name": "emqx_stomp","version": "v3.1.0","description": "EMQ X Stomp Protocol Plugin","active": false

},{"name": "emqx_web_hook","version": "v3.1.0","description": "EMQ X Webhook Plugin","active": false

}]

}

7.10.3 ��������

API ��:

PUT api/v3/nodes/${node}/plugins/${plugin}/load

����:

PUT api/v3/nodes/[email protected]/plugins/emqx_auth_clientid/load

����:

{"code": 0

(����)

144 Chapter 7. ����API (REST API)

EMQ X - ����� MQTT �����, �� 3.1.0

(���)

}

7.10.4 ��������

API ��:

PUT api/v3/nodes/${node}/plugins/${plugin}/unload

����:

PUT api/v3/nodes/[email protected]/plugins/emqx_auth_clientid/unload

����:

{"code": 0

}

7.11 ���(Listeners)

7.11.1 ���������

API ��:

GET api/v3/listeners/

����:

GET api/v3/listeners/

����:

{"code": 0,"data": [{

"listeners": [{

"acceptors": 16,"current_conns": 0,"listen_on": "8883","max_conns": 102400,"protocol": "mqtt:ssl","shutdown_count": [ ]

},{

"acceptors": 8,"current_conns": 2,"listen_on": "0.0.0.0:1883",

(����)

7.11. ���(Listeners) 145

EMQ X - ����� MQTT �����, �� 3.1.0

(���)

"max_conns": 1024000,"protocol": "mqtt:tcp","shutdown_count": {

"closed": 2,"kicked": 1

}},{

"acceptors": 4,"current_conns": 0,"listen_on": "127.0.0.1:11883","max_conns": 10240000,"protocol": "mqtt:tcp","shutdown_count": [ ]

},{

"acceptors": 4,"current_conns": 1,"listen_on": "18083","max_conns": 512,"protocol": "http:dashboard","shutdown_count": [ ]

},{

"acceptors": 2,"current_conns": 0,"listen_on": "8080","max_conns": 512,"protocol": "http:management","shutdown_count": [ ]

},{

"acceptors": 4,"current_conns": 0,"listen_on": "8083","max_conns": 102400,"protocol": "mqtt:ws","shutdown_count": [ ]

},{

"acceptors": 4,"current_conns": 0,"listen_on": "8084","max_conns": 16,"protocol": "mqtt:wss","shutdown_count": [ ]

}],"node": "[email protected]"

}]

}

146 Chapter 7. ����API (REST API)

EMQ X - ����� MQTT �����, �� 3.1.0

7.11.2 ���������

API ��:

GET api/v3/nodes/${node}/listeners

����:

GET api/v3/nodes/[email protected]/listeners

����:

{"code": 0,"data": [{

"acceptors": 16,"current_conns": 0,"listen_on": "8883","max_conns": 102400,"protocol": "mqtt:ssl","shutdown_count": [ ]

},{

"acceptors": 8,"current_conns": 2,"listen_on": "0.0.0.0:1883","max_conns": 1024000,"protocol": "mqtt:tcp","shutdown_count": {

"closed": 2,"kicked": 1

}},{

"acceptors": 4,"current_conns": 0,"listen_on": "127.0.0.1:11883","max_conns": 10240000,"protocol": "mqtt:tcp","shutdown_count": [ ]

},{

"acceptors": 4,"current_conns": 1,"listen_on": "18083","max_conns": 512,"protocol": "http:dashboard","shutdown_count": [ ]

},{

"acceptors": 2,"current_conns": 0,"listen_on": "8080",

(����)

7.11. ���(Listeners) 147

EMQ X - ����� MQTT �����, �� 3.1.0

(���)

"max_conns": 512,"protocol": "http:management","shutdown_count": [ ]

},{

"acceptors": 4,"current_conns": 0,"listen_on": "8083","max_conns": 102400,"protocol": "mqtt:ws","shutdown_count": [ ]

},{

"acceptors": 4,"current_conns": 0,"listen_on": "8084","max_conns": 16,"protocol": "mqtt:wss","shutdown_count": [ ]

}]

}

7.12 ������

7.12.1 ����������

API ��:

GET api/v3/metrics/

����:

GET api/v3/metrics/

����:

{"code": 0,"data": [{

"node": "[email protected]","metrics": {

"bytes/received": 342,"packets/pubrel/sent": 0,"packets/pubcomp/missed": 0,"packets/sent": 13,"packets/pubrel/received": 0,"messages/qos1/received": 0,"packets/publish/received": 2,

(����)

148 Chapter 7. ����API (REST API)

EMQ X - ����� MQTT �����, �� 3.1.0

(���)

"packets/auth": 0,"messages/qos0/received": 2,"packets/pubcomp/received": 0,"packets/unsuback": 0,"packets/pubrec/missed": 0,"messages/qos1/sent": 0,"messages/qos2/sent": 0,"bytes/sent": 116,"messages/received": 2,"messages/dropped": 1,"messages/qos2/received": 0,"packets/connect": 5,"messages/qos0/sent": 4,"packets/disconnect/received": 0,"packets/pubrec/sent": 0,"packets/publish/sent": 4,"packets/pubrec/received": 0,"packets/received": 11,"packets/unsubscribe": 0,"packets/subscribe": 4,"packets/disconnect/sent": 0,"packets/pingresp": 0,"messages/qos2/dropped": 0,"packets/puback/missed": 0,"packets/pingreq": 0,"packets/connack": 5,"packets/pubrel/missed": 0,"messages/sent": 4,"packets/suback": 4,"messages/retained": 3,"packets/puback/sent": 0,"packets/puback/received": 0,"messages/qos2/expired": 0,"messages/forward": 0,"messages/expired": 0,"packets/pubcomp/sent": 0

}}

]}

7.12.2 ����������

API ��:

GET api/v3/nodes/${node}/metrics/

����:

GET api/v3/nodes/[email protected]/metrics/

����:

7.12. ������ 149

EMQ X - ����� MQTT �����, �� 3.1.0

{"code": 0,"data": {

"bytes/received": 342,"packets/pubrel/sent": 0,"packets/pubcomp/missed": 0,"packets/sent": 13,"packets/pubrel/received": 0,"messages/qos1/received": 0,"packets/publish/received": 2,"packets/auth": 0,"messages/qos0/received": 2,"packets/pubcomp/received": 0,"packets/unsuback": 0,"packets/pubrec/missed": 0,"messages/qos1/sent": 0,"messages/qos2/sent": 0,"bytes/sent": 116,"messages/received": 2,"messages/dropped": 1,"messages/qos2/received": 0,"packets/connect": 5,"messages/qos0/sent": 4,"packets/disconnect/received": 0,"packets/pubrec/sent": 0,"packets/publish/sent": 4,"packets/pubrec/received": 0,"packets/received": 11,"packets/unsubscribe": 0,"packets/subscribe": 4,"packets/disconnect/sent": 0,"packets/pingresp": 0,"messages/qos2/dropped": 0,"packets/puback/missed": 0,"packets/pingreq": 0,"packets/connack": 5,"packets/pubrel/missed": 0,"messages/sent": 4,"packets/suback": 4,"messages/retained": 3,"packets/puback/sent": 0,"packets/puback/received": 0,"messages/qos2/expired": 0,"messages/forward": 0,"messages/expired": 0,"packets/pubcomp/sent": 0

}}

150 Chapter 7. ����API (REST API)

EMQ X - ����� MQTT �����, �� 3.1.0

7.13 ������

7.13.1 ����������

API ��:

GET api/v3/stats/

����:

GET api/v3/stats/

����:

{"code": 0,"data": [{

"node": "[email protected]","subscriptions/shared/max": 0,"subscriptions/max": 2,"subscribers/max": 2,"topics/count": 0,"subscriptions/count": 0,"topics/max": 1,"sessions/persistent/max": 2,"connections/max": 2,"subscriptions/shared/count": 0,"sessions/persistent/count": 0,"retained/count": 3,"routes/count": 0,"sessions/count": 0,"retained/max": 3,"sessions/max": 2,"routes/max": 1,"subscribers/count": 0,"connections/count": 0

}]

}

7.13.2 ����������

API ��:

GET api/v3/nodes/${node}/stats/

����:

GET api/v3/nodes/[email protected]/stats/

����:

7.13. ������ 151

EMQ X - ����� MQTT �����, �� 3.1.0

{"code": 0,"data": {

"subscriptions/shared/max": 0,"subscriptions/max": 2,"subscribers/max": 2,"topics/count": 0,"subscriptions/count": 0,"topics/max": 1,"sessions/persistent/max": 2,"connections/max": 2,"subscriptions/shared/count": 0,"sessions/persistent/count": 0,"retained/count": 3,"routes/count": 0,"sessions/count": 0,"retained/max": 3,"sessions/max": 2,"routes/max": 1,"subscribers/count": 0,"connections/count": 0

}}

7.14 ����

7.14.1 ��������

API ��:

GET api/v3/alarms/

����:

GET api/v3/alarms/

����:

{"code": 0,"data": [{

"alarms": [],"node": "[email protected]"

}]

}

152 Chapter 7. ����API (REST API)

EMQ X - ����� MQTT �����, �� 3.1.0

7.14.2 ��������

API ��:

GET api/v3/alarms/${node}

����:

GET api/v3/alarms/[email protected]

����:

{"code": 0,"data": []

}

7.15 ���

7.15.1 �������

API ��:

GET api/v3/banned/

����:

GET api/v3/banned/?_page=1&_limit=10000

����:

{"code": 0,"data": [],"meta": {

"count": 0,"limit": 10000,"page": 1

}}

7.15.2 �����

API ��:

POST api/v3/banned/

����:

7.15. ��� 153

EMQ X - ����� MQTT �����, �� 3.1.0

{"who": "mqttjs_ab9069449e","as": "client_id","reason": "banned the clientId","desc": "normal banned","until": 1536146187

}

����:

POST api/v3/banned/

����:

{"code": 0,"data": {

"who": "mqttjs_ab9069449e","as": "client_id","reason": "banned the clientId","desc": "normal banned","until": 1536146187

}}

7.15.3 �������

API ��:

DELETE api/v3/banned/${who}?as=${as}

����:

DELETE api/v3/banned/mqttjs_ab9069449e?as=client_id

����:

{"code": 0

}

7.16 ���������

7.16.1 HTTP ����� 500 �����������

����:

PUT api/v3/nodes/[email protected]/plugins/emqx_recon/load

����:

154 Chapter 7. ����API (REST API)

EMQ X - ����� MQTT �����, �� 3.1.0

{"code": 102,"message": "already_started"

}

7.16.2 ���������

�������� ?_page=1&_limit=10000 ����������:

_page: ����_limit: ����

����:

{"code": 0,"data": [],"meta": {

"page": 1,"limit": 10000,"count": 0

}}

7.17 ����(rule engine)

7.17.1 ����

API ��:

POST api/v3/rules

����:

name String�����for String�Hook �������: “message.publish”�”client.connected” … �� ���� (Plu-

gins)rawsql String������������� SQL ��actions JSON Array�����

• name String, ����

• params JSON Object, ����

description String��������

������:

7.17. ����(rule engine) 155

EMQ X - ����� MQTT �����, �� 3.1.0

{"name": "test-rule","for": "message.publish","rawsql": "select * from \"t/a\"","actions": [{

"name": "built_in:inspect_action","params": {

"a": 1}

}],"description": "test-rule"

}

������:

{"code": 0,"data": {

"actions": [{"name": "built_in:inspect_action","params": {

"$resource": "built_in:test-resource","a": 1

}}],"description": "test-rule","enabled": true,"for": "message.publish","id": "test-rule:1556263150688255821","name": "test-rule","rawsql": "select * from \"t/a\""

}}

7.17.2 ����

API ��:

GET api/v3/rules/${rule_id}

������:

GET api/v3/rules/test-rule:1556263150688255821

������:

{"code": 0,"data": {

"actions": [{"name": "built_in:inspect_action","params": {

(����)

156 Chapter 7. ����API (REST API)

EMQ X - ����� MQTT �����, �� 3.1.0

(���)

"$resource": "built_in:test-resource","a": 1

}}],"description": "test-rule","enabled": true,"for": "message.publish","id": "test-rule:1556263150688255821","name": "test-rule","rawsql": "select * from \"t/a\""

}}

7.17.3 ��������

API ��:

GET api/v3/rules

������:

{"code": 0,"data": [{

"actions": [{"name": "built_in:inspect_action","params": {

"$resource": "built_in:test-resource","a": 1

}}],"description": "test-rule","enabled": true,"for": "message.publish","id": "test-rule:1556263150688255821","name": "test-rule","rawsql": "select * from \"t/a\""

}]}

7.17.4 ����

API ��:

DELETE api/v3/rules/${rule_id}

������:

DELETE api/v3/rules/test-rule:1556263150688255821

������:

7.17. ����(rule engine) 157

EMQ X - ����� MQTT �����, �� 3.1.0

{"code": 0

}

7.17.5 ��������

API ��:

GET api/v3/actions?for=${hook_type}

�����:

GET api/v3/actions

������:

{"code": 0,"data": [{

"app": "emqx_rule_engine","description": "Republish a MQTT message to a another topic","for": "message.publish","name": "built_in:republish_action","params": {

"target_topic": {"description": "Repubilsh the message to which topic","format": "topic","required": true,"title": "To Which Topic","type": "string"

}},"type": "built_in"

}, {"app": "emqx_web_hook","description": "Forward Events to Web Server","for": "$events","name": "web_hook:event_action","params": {

"$resource": {"description": "Bind a resource to this action","required": true,"title": "Resource ID","type": "string"

},"template": {

"description": "The payload template to be filled with variables before␣↪→sending messages",

"required": false,"schema": {},"title": "Payload Template","type": "object"

(����)

158 Chapter 7. ����API (REST API)

EMQ X - ����� MQTT �����, �� 3.1.0

(���)

}},"type": "web_hook"

}, {"app": "emqx_web_hook","description": "Forward Messages to Web Server","for": "message.publish","name": "web_hook:publish_action","params": {

"$resource": {"description": "Bind a resource to this action","required": true,"title": "Resource ID","type": "string"

}},"type": "web_hook"

}, {"app": "emqx_rule_engine","description": "Inspect the details of action params for debug purpose","for": "$any","name": "built_in:inspect_action","params": {},"type": "built_in"

}]}

������:

GET api/v3/actions?for=client.connected

������:

{"code": 0,"data": [{

"app": "emqx_rule_engine","description": "Inspect the details of action params for debug purpose","for": "$any","name": "built_in:inspect_action","params": {},"type": "built_in"

}]}

7.17.6 ����

API ��:

GET api/v3/actions/:action_name

������:

7.17. ����(rule engine) 159

EMQ X - ����� MQTT �����, �� 3.1.0

GET api/v3/actions/built_in:inspect_action

������:

{"code": 0,"data": {

"app": "emqx_rule_engine","description": "Inspect the details of action params for debug purpose","for": "$any","name": "built_in:inspect_action","params": {},"type": "built_in"

}}

7.17.7 ����������

API ��:

GET api/v3/resource_types

������:

{"code": 0,"data": [{

"attrs": "undefined","config": {

"url": "http://host-name/chats"},"description": "forward msgs to host-name/chats","id": "web_hook:webhook1","name": "webhook1","type": "web_hook"

}, {"attrs": "undefined","config": {

"a": 1},"description": "test-resource","id": "built_in:test-resource","name": "test-resource","type": "built_in"

}]}

7.17.8 ������

API ��:

160 Chapter 7. ����API (REST API)

EMQ X - ����� MQTT �����, �� 3.1.0

GET api/v3/resource_types/${type}

������:

GET api/v3/resource_types/built_in

������:

{"code": 0,"data": {

"description": "The built in resource type for debug purpose","name": "built_in","params": {},"provider": "emqx_rule_engine"

}}

7.17.9 ���������

API ��:

GET api/v3/resource_types/${type}/resources

������:

GET api/v3/resource_types/built_in/resources

������:

{"code": 0,"data": [{

"attrs": "undefined","config": {

"a": 1},"description": "test-resource","id": "built_in:test-resource","name": "test-resource","type": "built_in"

}]}

7.17.10 ���������

API ��:

GET api/v3/resource_types/${type}/actions

������:

7.17. ����(rule engine) 161

EMQ X - ����� MQTT �����, �� 3.1.0

GET api/v3/resource_types/built_in/actions

������:

{"code": 0,"data": [{

"app": "emqx_rule_engine","description": "Inspect the details of action params for debug purpose","for": "$any","name": "built_in:inspect_action","params": {},"type": "built_in"

}, {"app": "emqx_rule_engine","description": "Republish a MQTT message to a another topic","for": "message.publish","name": "built_in:republish_action","params": {

"target_topic": {"description": "Repubilsh the message to which topic","format": "topic","required": true,"title": "To Which Topic","type": "string"

}},"type": "built_in"

}]}

7.17.11 ����

API ��:

POST api/v3/resources

����:

name String, ����type String, ����config JSON Object, ����description String��������

����:

{"name": "test-resource","type": "built_in","config": {

"a": 1(����)

162 Chapter 7. ����API (REST API)

EMQ X - ����� MQTT �����, �� 3.1.0

(���)

},"description": "test-resource"

}

������:

{"code": 0,"data": {

"attrs": "undefined","config": {

"a": 1},"description": "test-resource","id": "built_in:test-resource","name": "test-resource","type": "built_in"

}}

7.17.12 ������

API ��:

GET api/v3/resources

������:

{"code": 0,"data": [{

"attrs": "undefined","config": {

"url": "http://host-name/chats"},"description": "forward msgs to host-name/chats","id": "web_hook:webhook1","name": "webhook1","type": "web_hook"

}, {"attrs": "undefined","config": {

"a": 1},"description": "test-resource","id": "built_in:test-resource","name": "test-resource","type": "built_in"

}]}

7.17. ����(rule engine) 163

EMQ X - ����� MQTT �����, �� 3.1.0

7.17.13 ����

API ��:

GET api/v3/resources/:resource_id

������:

GET api/v3/resources/built_in:test-resource

������:

{"code": 0,"data": {

"attrs": "undefined","config": {

"a": 1},"description": "test-resource","id": "built_in:test-resource","name": "test-resource","type": "built_in"

}}

7.17.14 ����

API ��:

DELETE api/v3/resources/:resource_id

������:

DELETE api/v3/resources/built_in:test-resource

������:

{"code": 0

}

164 Chapter 7. ����API (REST API)

CHAPTER 8

���� (Design)

8.1 ��

EMQ X �������������������(FrontEnd)�����(Backend)������������(Flow Plane)�������(Monitor/Control Plane):

Control Plane--------------------

| |FrontEnd -> | Flow Plane | -> BackEnd

| |Session Router

---------------------Monitor Plane

8.1.1 100���

������������������������100� TCP ���������������������

EMQ X ����������������������100�����������������������TCP ����Erlang �������: http://docs.emqtt.cn/zh_CN/latest/tune.html

8.1.2 �����

EMQ X �������� Erlang/OTP ������������ TCP ���������(Topic)������������������������������ TCP ����� Mnesia ��������

EMQ X 3.0 ������ MQTT ������(Publisher)����(Subscriber)�� EMQ X �������������� Erlang �� Mailbox:

-------------- ----------- --------------Publisher --Msg-->| Connection | ----> | Session | ----> | Connection | --Msg-->␣↪→Subscriber

-------------- ----------- --------------

165

EMQ X - ����� MQTT �����, �� 3.1.0

8.1.3 �����

EMQ X ��������������������������������EMQ X ���������������������������������

���������� MQ ����������� JMS ��� ActiveMQ������������������������������������:

1. ������������������������������������

2. ���������������� Queue ���� Queue ����

Kafka ��������������������������� Commit Log �������

EMQ X ����������������������������������������������

EMQ X ���������������������������� Redis�MongoDB�Cassandra�MySQL�PostgreSQL ������� RabbitMQ�Kafka ������

8.2 ����

8.2.1 ����

EMQ X �����������������(Router)����(Switch)��������������(MQ)��������� IP ��� MPLS �������EMQ X ����(TopicTrie)�������������� MQTT ��:

8.2.2 ����

1. EMQ X �������������������� MQTT ��������

2. ���� Erlang/OTP ����������������������

3. ��(Connection)���(Session)���(Router)���(Cluster)���

4. ������(Flow Plane)�������(Control Plane)���

166 Chapter 8. ���� (Design)

EMQ X - ����� MQTT �����, �� 3.1.0

5. �������� NoSQL ������������������

8.2.3 ����

1. ���(Connection Layer)��� TCP ����� MQTT ������

2. ���(Session Layer)��� MQTT �������������

3. ���(Route Layer)�������� MQTT ���

4. ���(Distributed Layer)�������� MQTT ���

5. �������(ACL)��������������������

6. ��(Hooks)���(Plugins)��������������������������

8.3 �����

�������� Socket ��� MQTT ������

1. �� eSockd ����� TCP ���

2. TCP Acceptor ���� TCP Accept

3. TCP/SSL, WebSocket/SSL ����

4. ���������

5. �� IP ��(CIDR)����

6. �� Leaky Bucket ���

7. MQTT �����

8. MQTT ������

9. MQTT ������

8.4 �����

����� MQTT ������(Publish/Subscribe)�������

1. �� MQTT ��������(Subscription)������ QoS

2. �� Qos0/1/2 ���������������������

3. ����(Inflight Window)��������������

4. �������������������� Qos1/2 ��

5. ���������������� PUBREL � QoS2 ��

6. ���������������� Qos1/2 ��

8.3. ����� 167

EMQ X - ����� MQTT �����, �� 3.1.0

8.4.1 ���������

������������������������

|<----------------- Max Len ----------------->|-----------------------------------------------

IN -> | Messages Queue | Inflight Window | -> Out-----------------------------------------------

|<--- Win Size --->|

����(Inflight Window)������������ Qos1/2 ����������������������������

������������(Inflight Window)���������������������� Qos0 �������������

8.4.2 �� ID ��� ID

MQTT ������� 16bits ��� ID(PacketId)�������������������MQTT ����(PUBLISH)��������������������� 128bits ��ID(MessageId)�

���������� ID ���

1. 64bits ���: erlang:system_time if Erlang >= R18, otherwise os:timestamp

2. Erlang �� ID: ���2��

3. Erlang �� PID: ���4��

4. �������: 2����������

���������(Pub/Sub)�������� ID ��� QoS ���������� ID ��� MQTT ����������:

PktId <-- Session --> MsgId <-- Router --> MsgId <-- Session --> PktId

8.5 �����

��������(subscriber)������(subscription)��������������(Dispatch)��:

�������(Session)���������� QoS �����

168 Chapter 8. ���� (Design)

EMQ X - ����� MQTT �����, �� 3.1.0

8.6 �����

����������(Topic Trie)����(Route Table)����������������������:

-------------------------| t || / \ || + # || / \ || x y |-------------------------| t/+/x -> node1, node3 || t/+/y -> node1 || t/# -> node2 || t/a -> node3 |-------------------------

����������(Topic Trie)������(Route Table)������������ MQTT ��:

8.7 ��(Hook)��

8.7.1 ��(Hook)��

EMQ X �������������������������������(Hook):

8.6. ����� 169

EMQ X - ����� MQTT �����, �� 3.1.0

�� ��client.authenticate �����client.check_acl ��� ACL ��client.connected �����client.subscribe ��������client.unsubscribe ���������session.subscribed ��������session.unsubscribed ����������message.publish MQTT ����message.deliver MQTT �����message.acked MQTT ����client.disconnected �������

��(Hook) ���������(Chain-of-responsibility_pattern)�����������������������������������������������������:

-------- ok | {ok, NewAcc} -------- ok | {ok, NewAcc} --------(Args, Acc) --> | Fun1 | -------------------> | Fun2 | -------------------> | Fun3 | -->↪→{ok, Acc} | {stop, Acc}

-------- -------- --------| | |

stop | {stop, NewAcc} stop | {stop, NewAcc} stop | {stop,␣↪→NewAcc}

�������������������������� emqx_plugin_template �������������:

�� ��ok ����{ok, NewAcc} ����������stop ����{stop, NewAcc} ����������

8.7.2 ��(Hook)��

emqx ����� Hook ��:

-spec(hook(emqx_hooks:hookpoint(), emqx_hooks:action()) -> ok | {error, already_exists}).hook(HookPoint, Action) ->

emqx_hooks:add(HookPoint, Action).

-spec(hook(emqx_hooks:hookpoint(), emqx_hooks:action(), emqx_hooks:filter() | integer())-> ok | {error, already_exists}).

hook(HookPoint, Action, Priority) when is_integer(Priority) ->emqx_hooks:add(HookPoint, Action, Priority);

hook(HookPoint, Action, Filter) when is_function(Filter); is_tuple(Filter) ->emqx_hooks:add(HookPoint, Action, Filter);

hook(HookPoint, Action, InitArgs) when is_list(InitArgs) ->emqx_hooks:add(HookPoint, Action, InitArgs).

-spec(hook(emqx_hooks:hookpoint(), emqx_hooks:action(), emqx_hooks:filter(), integer())-> ok | {error, already_exists}).

hook(HookPoint, Action, Filter, Priority) ->(����)

170 Chapter 8. ���� (Design)

EMQ X - ����� MQTT �����, �� 3.1.0

(���)

emqx_hooks:add(HookPoint, Action, Filter, Priority).

-spec(unhook(emqx_hooks:hookpoint(), emqx_hooks:action()) -> ok).unhook(HookPoint, Action) ->

emqx_hooks:del(HookPoint, Action).

-spec(run_hook(emqx_hooks:hookpoint(), list(any())) -> ok | stop).run_hook(HookPoint, Args) ->

emqx_hooks:run(HookPoint, Args).

-spec(run_fold_hook(emqx_hooks:hookpoint(), list(any()), any()) -> any()).run_fold_hook(HookPoint, Args, Acc) ->

emqx_hooks:run_fold(HookPoint, Args, Acc).

8.7.3 ��(Hook)��

emqx_plugin_template �������������������������:

-module(emqx_plugin_template).

-export([load/1, unload/0]).

-export([on_message_publish/2, on_message_deliver/3, on_message_acked/3]).

load(Env) ->emqx:hook('message.publish', fun ?MODULE:on_message_publish/2, [Env]),emqx:hook('message.deliver', fun ?MODULE:on_message_deliver/3, [Env]),emqx:hook('message.acked', fun ?MODULE:on_message_acked/3, [Env]).

on_message_publish(Message, _Env) ->io:format("publish ~s~n", [emqx_message:format(Message)]),{ok, Message}.

on_message_deliver(Credentials, Message, _Env) ->io:format("deliver to client ~s: ~s~n", [Credentials, emqx_message:format(Message)]),{ok, Message}.

on_message_acked(Credentials, Message, _Env) ->io:format("client ~s acked: ~s~n", [Credentials, emqx_message:format(Message)]),{ok, Message}.

unload() ->emqx:unhook('message.publish', fun ?MODULE:on_message_publish/2),emqx:unhook('message.acked', fun ?MODULE:on_message_acked/3),emqx:unhook('message.deliver', fun ?MODULE:on_message_deliver/3).

8.8 ���������

EMQ X ����������������������� client.authenticate and client.check_acl �������

8.8. ��������� 171

EMQ X - ����� MQTT �����, �� 3.1.0

8.8.1 ����������

������� client.authenticate ��:

emqx:hook('client.authenticate', fun ?MODULE:on_client_authenticate/1, []).

������������ Credentials ����������� Credentials:

on_client_authenticate(Credentials = #{password := Password}) ->{ok, Credentials#{result => success}}.

Credentials ������������� map:

#{client_id => ClientId, %% ��� IDusername => Username, %% ���peername => Peername, %% ���� IP �����password => Password, %% �� (��)result => Result %% �����success ������,

%% bad_username_or_password �� not_authorized ����.}

8.8.2 �� ACL ������

������� client.authenticate ��:

emqx:hook('client.check_acl', fun ?MODULE:on_client_check_acl/4, []).

��������� Credentials, AccessType, Topic, ACLResult ������ �������� ACLResult:

on_client_check_acl(#{client_id := ClientId}, AccessType, Topic, ACLResult) ->{ok, allow}.

AccessType ��� publish � subscribe ��� Topic � MQTT topic� ACLResult ��� allow���� deny�

emqx_mod_acl_internal ������� etc/acl.conf ��� ACL ���etc/acl.conf ��������

%%%-----------------------------------------------------------------------------%%%%%% -type who() :: all | binary() |%%% {ipaddr, esockd_access:cidr()} |%%% {client, binary()} |%%% {user, binary()}.%%%%%% -type access() :: subscribe | publish | pubsub.%%%%%% -type topic() :: binary().%%%%%% -type rule() :: {allow, all} |%%% {allow, who(), access(), list(topic())} |%%% {deny, all} |%%% {deny, who(), access(), list(topic())}.%%%

(����)

172 Chapter 8. ���� (Design)

EMQ X - ����� MQTT �����, �� 3.1.0

(���)

%%%-----------------------------------------------------------------------------

{allow, {user, "dashboard"}, subscribe, ["$SYS/#"]}.

{allow, {ipaddr, "127.0.0.1"}, pubsub, ["$SYS/#", "#"]}.

{deny, all, subscribe, ["$SYS/#", {eq, "#"}]}.

{allow, all}.

� emqx ��� Auth/ACL ��:

Plugin Authenticationemqx_auth_username Username and Passwordemqx_auth_clientid ClientID and Passwordemqx_auth_ldap LDAPemqx_auth_http HTTP APIemqx_auth_mysql MySQLemqx_auth_pgsql PostgreSQLemqx_auth_redis Redisemqx_auth_mongo MongoDBemqx_auth_jwt JWT

8.9 ��(Plugin)��

��������������� Erlang ��(Application)���������(Hook)������������������������������

emqx_plugins ����������������� API

-module(emqx_plugins).

-export([load/1, unload/1]).

%% @doc Load a Pluginload(PluginName :: atom()) -> ok | {error, any()}.

%% @doc UnLoad a Pluginunload(PluginName :: atom()) -> ok | {error, any()}.

����� ./bin/emqx_ctl ���������:

./bin/emqx_ctl plugins load <plugin name>

./bin/emqx_ctl plugins unload <plugin name>

����������: http://github.com/emqx/emqx_plugin_template

8.9. ��(Plugin)�� 173

EMQ X - ����� MQTT �����, �� 3.1.0

8.10 Mnesia/ETS ���

Table Type Descriptionemqx_conn ets ���emqx_metrics ets ���emqx_session ets ���emqx_hooks ets ���emqx_subscriber ets ����emqx_subscription ets ���emqx_admin mnesia Dashboard ���emqx_retainer mnesia Retained ���emqx_shared_subscription mnesia �����emqx_session_registry mnesia �������emqx_alarm_history mnesia �����emqx_alarm mnesia ���emqx_banned mnesia �����emqx_route mnesia ���emqx_trie mnesia Trie �emqx_trie_node mnesia Trie Node �mqtt_app mnesia App �

8.11 Erlang ����

1. �� Pool, Pool, Pool… �� GProc �: https://github.com/uwiger/gproc

2. ����������…����������������������

3. ���� Mailbox ����

4. ����� Socket ��������� Hibernate����� binary ��

5. ��� Binary ������������

6. �� ETS, ETS, ETS… Message Passing vs. ETS

7. �� ETS ������ select, match

8. ������ ETS ��, �� ETS ����������� lookup_element, update_counter

9. ���� ETS � {write_concurrency, true}

10. �� Mnesia ���������������������(overload)

11. ��� Mnesia ������������� match, select

174 Chapter 8. ���� (Design)

CHAPTER 9

���� (Clustering)

9.1 Erlang/OTP �����

Erlang/OTP �����������������������������(���������…)�����������������������������

Erlang/OTP ����������������� Erlang ��������� Erlang ���������(Node)���(Node) ��� TCP ������������:

--------- ---------| Node1 | --------| Node2 |--------- ---------

| \ / || \ / || / \ || / \ |

--------- ---------| Node3 | --------| Node4 |--------- ---------

9.1.1 ��(Node)

Erlang ��������������������������� ��������� Erlang ����������:

erl -name [email protected] -name [email protected] -name [email protected] -name [email protected]

[email protected] ��������������:

([email protected])1> net_kernel:connect_node('[email protected]').true

(����)

175

EMQ X - ����� MQTT �����, �� 3.1.0

(���)

([email protected])2> net_kernel:connect_node('[email protected]').true([email protected])3> net_kernel:connect_node('[email protected]').true([email protected])4> nodes().['[email protected]','[email protected]','[email protected]']

9.1.2 epmd

epmd(Erlang Port Mapper Daemon) - Erlang ���������� Erlang ���������������������� TCP ���:

([email protected])6> net_adm:names().{ok,[{"node1",62740},

{"node2",62746},{"node3",62877},{"node4",62895}]}

9.1.3 ��

Erlang ���������� cookie �������

Erlang �� Cookie ��:

1. $HOME/.erlang.cookie ��

2. erl -setcookie <Cookie>

������: http://erlang.org/doc/reference_manual/distributed.html

9.1.4 ��

Erlang ������� TCPv4, TCPv6 � TLS �����EMQ X ��� etc/emqx.conf �������:

## Specify the erlang distributed protocol.#### Value: Enum## - inet_tcp: the default; handles TCP streams with IPv4 addressing.## - inet6_tcp: handles TCP with IPv6 addressing.## - inet_tls: using TLS for Erlang Distribution.#### vm.args: -proto_dist inet_tcpnode.proto_dist = inet_tcp

## Specify SSL Options in the file if using SSL for Erlang Distribution.#### Value: File#### vm.args: -ssl_dist_optfile <File>## node.ssl_dist_optfile = {{ platform_etc_dir }}/ssl_dist.conf

176 Chapter 9. ���� (Clustering)

EMQ X - ����� MQTT �����, �� 3.1.0

9.2 EMQ X ������

EMQ X ��������� Erlang/OTP ��������������������:

1. MQTT �������������������������������(Topic)�������

2. MQTT ��������������������(Topic)����������������

EMQ X �����������������������(Topic) -> ��(Node)���������:

topic1 -> node1, node2topic2 -> node3topic3 -> node2, node4

9.2.1 ���(Topic Trie)����(Route Table)

EMQ X ��������������������(Topic Trie)�����

����������:

��� �� ����client1 node1 t/+/x, t/+/yclient2 node2 t/#client3 node3 t/+/x, t/a

����������(Topic Trie)����(Route Table):

--------------------------| t || / \ || + # || / \ || x y |--------------------------| t/+/x -> node1, node3 || t/+/y -> node1 || t/# -> node2 || t/a -> node3 |--------------------------

9.2.2 ��(Subscription)�����

��������(Subscription)������������������������������

��client1���’t/a’�������������������:

title: Message Route and Deliver

client1 -> node1: Publish[t/a]node1 --> node2: Route[t/#]

node2 --> client2: Deliver[t/#]node1 --> node3: Route[t/a]

node3 --> client3: Deliver[t/a]

9.2. EMQ X ������ 177

EMQ X - ����� MQTT �����, �� 3.1.0

9.3 ��������

��������� s1.emqx.io, s2.emqx.io �����:

��� ���(FQDN) IP ��[email protected][email protected] s1.emqx.io [email protected][email protected] s2.emqx.io 192.168.0.20

��: �����: Name@Host, Host ��� IP ��� FQDN(���.��)

9.3.1 [email protected] ����

emqx/etc/emqx.conf:

node.name = [email protected]

node.name = [email protected]

��������:

export [email protected] && ./bin/emqx start

��: �������������������

178 Chapter 9. ���� (Clustering)

EMQ X - ����� MQTT �����, �� 3.1.0

9.3.2 [email protected] ����

emqx/etc/emqx.conf:

node.name = [email protected]

node.name = [email protected]

9.3.3 ������

��������[email protected] ���:

$ ./bin/emqx_ctl cluster join [email protected]

Join the cluster successfully.Cluster status: [{running_nodes,['[email protected]','[email protected]']}]

��[email protected] ���:

$ ./bin/emqx_ctl cluster join [email protected]

Join the cluster successfully.Cluster status: [{running_nodes,['[email protected]','[email protected]']}]

�����������:

$ ./bin/emqx_ctl cluster status

Cluster status: [{running_nodes,['[email protected]','[email protected]']}]

9.3.4 ������

�����������:

1. leave: �������

2. force-leave: ���������

[email protected] ������:

$ ./bin/emqx_ctl cluster leave

[email protected] ��������� [email protected] ��:

$ ./bin/emqx_ctl cluster force-leave [email protected]

9.4 ���������

EMQ X ���� Ekka ��������(Autocluster)�Ekka �� Erlang/OTP ������������� Erlang������(Discovery)�����(Autocluster)�������(Network Partition Autoheal)���������(Autoclean)�

9.4. ��������� 179

EMQ X - ����� MQTT �����, �� 3.1.0

EMQ X ����������:

�� ��manual ��������static ����������mcast UDP ��������dns DNS A ������etcd �� etcd ����k8s Kubernetes ������

9.4.1 manual ������

���������������� ./bin/emqx_ctl join <Node> ����:

cluster.discovery = manual

9.4.2 �� static ��������

�������������������:

cluster.discovery = static

cluster.static.seeds = [email protected],[email protected]

9.4.3 �� mcast ������

�� UDP �����������:

cluster.discovery = mcast

cluster.mcast.addr = 239.192.0.1

cluster.mcast.ports = 4369,4370

cluster.mcast.iface = 0.0.0.0

cluster.mcast.ttl = 255

cluster.mcast.loop = on

9.4.4 �� DNS A ������

�� DNS A �����������:

cluster.discovery = dns

cluster.dns.name = localhost

cluster.dns.app = ekka

180 Chapter 9. ���� (Clustering)

EMQ X - ����� MQTT �����, �� 3.1.0

9.4.5 �� etcd ����

�� etcd ���������:

cluster.discovery = etcd

cluster.etcd.server = http://127.0.0.1:2379

cluster.etcd.prefix = emqcl

cluster.etcd.node_ttl = 1m

9.4.6 �� Kubernetes ����

Kubernetes ����������:

cluster.discovery = k8s

cluster.k8s.apiserver = http://10.110.111.204:8080

cluster.k8s.service_name = ekka

## Address Type: ip | dnscluster.k8s.address_type = ip

## The Erlang application namecluster.k8s.app_name = ekka

9.5 ���������

EMQ X ����������(Network Partition Autoheal):

cluster.autoheal = on

����������:

1. ���� Mnesia � inconsistent_database ��3�����������

2. ������������� Leader ��(���������)�������

3. Leader ��������������������������(SplitView)�

4. Leader ������(majority)��������� Coordinator ���

5. Coordinator �������(minority)���������

9.6 ��������

EMQ X �������������(Autoclean):

cluster.autoclean = 5m

9.5. ��������� 181

EMQ X - ����� MQTT �����, �� 3.1.0

9.7 �����(Session)

EMQ X ������MQTT �������(Session)����

�������������: node1 � node2��� MQTT ������ node1�node1 ������������������ node2 ��MQTT ���� node2 ��������� node1 ��:

node1-----------

|-->| session || -----------

node2 |-------------- |

client-->| connection |<--|--------------

9.8 �����

�������������������� 4369 ����� TCP ����4369 � epmd ���������TCP ����������������

�������EMQ X �����������emqx/etc/emqx.conf ��:

## Distributed node port rangenode.dist_listen_min = 6369node.dist_listen_max = 7369

182 Chapter 9. ���� (Clustering)

CHAPTER 10

���� (Deployment)

EMQ X �����������������(IoT Hub)�������AWS����������������

������:

10.1 LB (����)

LB (�����) ������� MQTT ������ EMQ X ���LB �� EMQ X �������������������

������� LB �� SSL ������ LB �� TLS �����LB � EMQ X ���� TCP ���������� EMQ X ��������100����

����� LB ��:

����� ���� TLS �� LB ������ � https://docs.qingcloud.com/guide/loadbalancer.htmlAWS � https://aws.amazon.com/cn/elasticloadbalancing/��� � https://www.aliyun.com/product/slbUCloud �� https://ucloud.cn/site/product/ulb.htmlQCloud �� https://www.qcloud.com/product/clb

183

EMQ X - ����� MQTT �����, �� 3.1.0

���� LB ���:

�� LB ���� TLS �� ����HAProxy � https://www.haproxy.com/solutions/load-balancing.htmlNGINX PLUS ���� https://www.nginx.com/solutions/load-balancing/

�����������(EMQ X ����)������� AWS ��������� HAProxy �� LB�

10.2 EMQ X ��

EMQ X ������� LB �������� VPC ���������������AWS�UCloud�QCloud ��� VPC ���

EMQ X ����� MQTT �� TCP ��:

1883 MQTT ����8883 MQTT/SSL ��8083 MQTT/WebSocket ��8084 MQTT/WebSocket/SSL ��

�������� MQTT �����������������

EMQ X ������� TCP ��:

4369 ��������6369 ��������

���������������� TCP �������

10.3 ��(QingCloud) ��

1. �� VPC ���

2. VPC ����� EMQ X ��’����’���: 192.168.0.0/24

3. ��������� EMQ X �����:

emqx1 192.168.0.2emqx2 192.168.0.3

4. ����� EMQ X �����������������

5. �� LB(�����) ����� IP ���

6. � LB ��� MQTT TCP ���:

184 Chapter 10. ���� (Deployment)

EMQ X - ����� MQTT �����, �� 3.1.0

��� SSL ������� SSL � LB :

7. MQTT ����� LB �������

10.4 ���(AWS)��

1. �� VPC ���

2. VPC ����� EMQ X ��’����’���: 192.168.0.0/24

3. ��������� EMQ X ���������� VPC ��,��:

emqx1 192.168.0.2emqx2 192.168.0.3

4. �������� MQTT ��� TCP �����1883, 8883�

5. ����� EMQ X �����������������

6. �� ELB (Classic�����)��� VPC �������� IP ���

7. � ELB ��� MQTT TCP ���:

10.4. ���(AWS)�� 185

EMQ X - ����� MQTT �����, �� 3.1.0

��� SSL ������� SSL � LB :

8. MQTT ����� LB �������

10.5 �����

10.6 ������

10.6.1 EMQ X ����

EMQ X ����� DNS ����������� IP ������:

1. �� EMQ X �������‘�����‘�‘����‘���

2. EMQ X ��������� MQTT �������1883, 8883�

3. ���� IP ��������� EMQ X ���

��: ��������������

186 Chapter 10. ���� (Deployment)

EMQ X - ����� MQTT �����, �� 3.1.0

10.6.2 HAProxy -> EMQ X ��

HAProxy �� LB �� EMQ X ������ SSL ��:

1. �� EMQ X �������:

�� IP ��emqx1 192.168.0.2emqx2 192.168.0.3

2. �� /etc/haproxy/haproxy.cfg���:

listen mqtt-sslbind *:8883 ssl crt /etc/ssl/emqx/emq.pem no-sslv3mode tcpmaxconn 50000timeout client 600sdefault_backend emqx_cluster

backend emqx_clustermode tcpbalance sourcetimeout server 50stimeout check 5000server emqx1 192.168.0.2:1883 check inter 10000 fall 2 rise 5 weight 1server emqx2 192.168.0.3:1883 check inter 10000 fall 2 rise 5 weight 1source 0.0.0.0 usesrc clientip

10.6.3 NGINX Plus -> EMQ X ��

NGINX Plus ���� EMQ X �� LB���� SSL ��:

1. �� NGINX Plus ����Ubuntu ���: https://cs.nginx.com/repo_setup

2. �� EMQ X �������:

�� IP ��emqx1 192.168.0.2emqx2 192.168.0.3

3. �� /etc/nginx/nginx.conf���:

stream {# Example configuration for TCP load balancing

upstream stream_backend {zone tcp_servers 64k;hash $remote_addr;server 192.168.0.2:1883 max_fails=2 fail_timeout=30s;server 192.168.0.3:1883 max_fails=2 fail_timeout=30s;

}

server {(����)

10.6. ������ 187

EMQ X - ����� MQTT �����, �� 3.1.0

(���)

listen 8883 ssl;status_zone tcp_server;proxy_pass stream_backend;proxy_buffer_size 4k;ssl_handshake_timeout 15s;ssl_certificate /etc/emqx/certs/cert.pem;ssl_certificate_key /etc/emqx/certs/key.pem;

}}

188 Chapter 10. ���� (Deployment)

CHAPTER 11

���� (Tuning Guide)

EMQ X �����1.x�� MQTT �������130�����8���32G��� CentOS �����

100�������� Linux �������������Erlang ������ EMQ X �����������:

11.1 Linux ������

����������������:

# 2 millions system-widesysctl -w fs.file-max=2097152sysctl -w fs.nr_open=2097152echo 2097152 > /proc/sys/fs/nr_open

������/���������:

ulimit -n 1048576

11.1.1 /etc/sysctl.conf

��� ‘fs.file-max’ ��� /etc/sysctl.conf ��:

fs.file-max = 1048576

/etc/systemd/system.conf �����������:

DefaultLimitNOFILE=1048576

189

EMQ X - ����� MQTT �����, �� 3.1.0

11.1.2 /etc/security/limits.conf

/etc/security/limits.conf ���������/���������:

* soft nofile 1048576* hard nofile 1048576

11.2 TCP �������

���� backlog ��:

sysctl -w net.core.somaxconn=32768sysctl -w net.ipv4.tcp_max_syn_backlog=16384sysctl -w net.core.netdev_max_backlog=16384

��������:

sysctl -w net.ipv4.ip_local_port_range='1000 65535'

TCP Socket �� Buffer ��:

sysctl -w net.core.rmem_default=262144sysctl -w net.core.wmem_default=262144sysctl -w net.core.rmem_max=16777216sysctl -w net.core.wmem_max=16777216sysctl -w net.core.optmem_max=16777216

#sysctl -w net.ipv4.tcp_mem='16777216 16777216 16777216'sysctl -w net.ipv4.tcp_rmem='1024 4096 16777216'sysctl -w net.ipv4.tcp_wmem='1024 4096 16777216'

TCP ������:

sysctl -w net.nf_conntrack_max=1000000sysctl -w net.netfilter.nf_conntrack_max=1000000sysctl -w net.netfilter.nf_conntrack_tcp_timeout_time_wait=30

TIME-WAIT Socket ������������:

net.ipv4.tcp_max_tw_buckets=1048576

# ��: ���������NAT���������RST# net.ipv4.tcp_tw_recycle = 1# net.ipv4.tcp_tw_reuse = 1

FIN-WAIT-2 Socket ����:

net.ipv4.tcp_fin_timeout = 15

190 Chapter 11. ���� (Tuning Guide)

EMQ X - ����� MQTT �����, �� 3.1.0

11.3 Erlang �����

���� Erlang ������������ emqx/etc/emqx.conf:

## Erlang Process Limitnode.process_limit = 2097152

## Sets the maximum number of simultaneously existing ports for this systemnode.max_ports = 1048576

11.4 EMQ X �������

�� TCP ���� Acceptor ���������������� emqx/etc/emqx.conf:

## TCP Listenerlistener.tcp.external = 0.0.0.0:1883listener.tcp.external.acceptors = 64listener.tcp.external.max_connections = 1000000

11.5 �������

���������������������65000��:

sysctl -w net.ipv4.ip_local_port_range="500 65535"echo 1000000 > /proc/sys/fs/nr_openulimit -n 100000

11.5.1 emqtt_benchmark

��������: http://github.com/emqtt/emqtt_benchmark

11.3. Erlang ����� 191

EMQ X - ����� MQTT �����, �� 3.1.0

192 Chapter 11. ���� (Tuning Guide)

CHAPTER 12

���� (Changes)

12.1 3.1.1 ��

����: 2019-05-10

EMQ X 3.1.1 �������������������������

����:

• ����������������

Github PR: emqx/emqx#2509

• force_shutdown_policy ���������������

Github PR: emqx/emqx#2515

����:

• �������� long_gc � long_schedule

Github PR: emqx/emqx#2504, emqx/emqx#2513

• ������ suboptions/count ���

Github PR: emqx/emqx#2507

12.1.1 emqx-lwm2m (plugin)

����:

• �� mountpoint �������

Github PR: emqx/emqx-lwm2m#34

• ������� emqx-web-hook �����

Github PR: emqx/emqx-lwm2m#35

193

EMQ X - ����� MQTT �����, �� 3.1.0

12.2 3.1.0 ��

����: 2019-04-26

EMQ X 3.1.0 ������������������������� storm ����� edge storm� �� flapping ���

����:

• �� emqx_ct_helpers ����������

Github PR: emqx/emqx#2480

• �� flapping ��

Github PR: emqx/emqx#2476

12.2.1 emqx-management (plugin)

����:

• �� listeners acceptors �����������

Github PR: emqx/emqx-management#76

12.2.2 emqx-rule-engine (plugin)

����:

• �����������

Github PR: emqx/emqx-rule-engine#b28318

• �������������

Github PR: emqx/emqx-rule-engine#fa75b9

• � republish ����� from ��

Github PR: emqx/emqx-rule-engine#8721eb

• ��� SQL where �����������

Github PR: emqx/emqx-rule-engine#c9c761

12.2.3 emqx-storm (plugin)

����:

• �� edge storm

Github Repository: emqx/emqx-storm

12.3 3.1-rc.3 ��

����: 2019-04-19

EMQ X 3.1-rc.3 �������������������������� ��: ��������� OpenSUSE ���������� Debian 7 ����

����:

194 Chapter 12. ���� (Changes)

EMQ X - ����� MQTT �����, �� 3.1.0

• �������� flapping �������������

Github PR: emqx/emqx#2438

• ����������

Github PR: emqx/emqx#2461

����:

• �� emqx_client ������ CONNECT �� Keep Alive �����

Github PR: emqx/emqx#2443

12.3.1 emqx-auth-mysql (plugin)

����:

• �� proxysql

Github PR: emqx/emqx-auth-mysql#134

12.3.2 emqx-statsd (plugin)

����:

• �� Windows ��������

Github PR: emqx/emqx-statsd#24

12.3.3 emqx-web-hook (plugin)

����:

• ���� actions

Github Commit: emqx/emqx-web-hook#8367e0

• �� webhook ��� specs

Github Commit: emqx/emqx-web-hook#5a1345

• ���� hook ���� actions

Github Commit: emqx/emqx-web-hook#fb3b1b

12.3.4 emqx-rule-engine (plugin)

����:

• ���������� actions

Github PR: emqx/emqx-rule-engine#25

• �����������������

Github PR: emqx/emqx-rule-engine#26

• �� actions �����

Github PR: emqx/emqx-rule-engine#27

12.3. 3.1-rc.3 �� 195

EMQ X - ����� MQTT �����, �� 3.1.0

12.3.5 emqx-rel

����:

• ���� log.rotation.size ��������

Github PR: emqx/emqx-rel#336

12.4 3.1-rc.2 ��

����: 2019-04-13

EMQ X 3.1-rc.2 ��������������������������

����:

• ���� emqx_bridge � ensure_start � ensure_stop API

Github PR: emqx/emqx#2423

• �� Handler ��� emqx_bridge

Github PR: emqx/emqx#2414

����:

• �� metrics ���������������

Github PR: emqx/emqx#2416

• �� trace log level ������������

Github PR: emqx/emqx#2408

12.4.1 emqx-auth-http (plugin)

����:

• ����� WebServer �� Mountpoint

Github PR: emqx/emqx-auth-http#116

12.4.2 emqx-auth-username (plugin)

����:

• ������������ username ���

Github PR: emqx/emqx-auth-username#96

12.4.3 emqx-auth-clientid (plugin)

����:

• ������������ clientid ���

Github PR: emqx/emqx-auth-clientid#81

196 Chapter 12. ���� (Changes)

EMQ X - ����� MQTT �����, �� 3.1.0

12.4.4 emqx-rule-engine (plugin)

����:

• ���� POSIX CLI ��

Github PR: emqx/emqx-rule-engine#23

����:

• �� HTTP APIs ����

Github PR: emqx/emqx-rule-engine#21

12.4.5 emqx-packages (plugin)

����:

• �� EMQ X � CentOS ����������

Github Commit: emqx/emqx-packages#64760523ea29ca0ad1d85b763f0e8a8e6954db9c

12.4.6 emqx-dashboard (plugin)

����:

• �� Rule-Engine ����

Github PR: emqx/emqx-dashboard#50

• ���������� Dashboard ��

Github PR: emqx/emqx-dashboard#48

12.5 3.1-rc.1 ��

����: 2019-04-04

EMQ X 3.1-rc.1 ���������������������������������

����:

• ���� WebSocket ��

Github PR: emqx/emqx#2356

• etcd ���� SSL ��

Github PR: emqx/emqx#2367

• �� Websocket � proxy protocol

Github PR: emqx/emqx#2372

����:

• �� monitor ��������

Github PR: emqx/emqx#2353

• �� allow_anonymous ����������

Github PR: emqx/emqx#2355

12.5. 3.1-rc.1 �� 197

EMQ X - ����� MQTT �����, �� 3.1.0

• �� session �����������������

Github PR: emqx/emqx#2373

• �� message.dropped � hook ��������������

Github PR: emqx/emqx#2399

12.5.1 emqx-auth-http (plugin)

����:

• ��� SSL ������� Subject Name � Common Name ����

Github PR: emqx/emqx-auth-http#113

12.5.2 emqx-auth-clientid (plugin)

����:

• ���� REST API �� ClientId

Github PR: emqx/emqx-auth-clientid#78

12.5.3 emqx-auth-jwt (plugin)

����:

• ������� claims ��

Github PR: emqx/emqx-auth-jwt#69

12.5.4 emqx-rule-engine (plugin)

����:

• ������

Github Repository: emqx/emqx-rule-engine

12.5.5 emqx-rel

����:

• �� Windows ��� EMQ X ���������

Github Commit: emqx/emqx-rel#75de3441db9bf03d489609dcbb340a74de263508

• �� Windows ��� EMQ X �������������������

Github Commit: emqx/emqx-rel#75de3441db9bf03d489609dcbb340a74de263508

198 Chapter 12. ���� (Changes)

EMQ X - ����� MQTT �����, �� 3.1.0

12.6 3.1-beta.3 ��

����: 2019-03-22

EMQ X 3.1-beta.3 ���������������������������������������

����:

• ��������

Github PR: emqx/emqx#2339

����:

• �����������

Github PR: emqx/emqx#2332

• �����������

Github PR: emqx/emqx#2333

• ���� PUBLISH ���� DUP ��

Github PR: emqx/emqx#2337

12.6.1 emqx-rule-engine (plugin)

����:

• ��������

Github Repository: emqx/emqx-rule-engine

12.6.2 emqx-lua-hook (plugin)

����:

• ����� ACL � hook

Github PR: emqx/emqx-lua-hook#63

12.6.3 emqx-auth-mysql (plugin)

����:

• �� ACL ���������

Github PR: emqx/emqx-auth-mysql#130

12.7 3.1-beta.2 ��

����: 2019-03-16

EMQ X 3.1-beta.2 ������������������ hooks, �� TLS/PSK ��� gen_rpc �������

����:

12.6. 3.1-beta.3 �� 199

EMQ X - ����� MQTT �����, �� 3.1.0

• �� emqx hooks

Github PR: emqx/emqx#2309

• �� TLS/DTLS PSK

Github PR: emqx/emqx#2297

• � Request/Response � emqx client ��

Github PR: emqx/emqx#2293

����:

• �������������� Broker �������

Github issues: emqx/emqx#2290

Github PR: emqx/emqx#2320

• � Broker ���������� emqx_alarm_handler

Github PR: emqx/emqx#2316

• ����� emqx bridge �����

Github issues: emqx/emqx#2312

Github PR: emqx/emqx#2313

• �� inflight full error

Github PR: emqx/emqx#2281

12.7.1 emqx-management (plugin)

����:

• ����� secret ��

Github PR: emqx/emqx-management#58

• ����������� reload ���

Github PR: emqx/emqx-management#59

• ����� HTTP API �������

Github PR: emqx/emqx-management#57

• ���� io/max_fds �� undefined ���

Github issues: emqx/emqx-management#2222

Github PR: emqx/emqx-management#54

12.7.2 emqx-auth-jwt (plugin)

����:

• �� JWT ����

Github PR: emqx/emqx-auth-jwt#63

200 Chapter 12. ���� (Changes)

EMQ X - ����� MQTT �����, �� 3.1.0

12.7.3 emqx-auth-usernmae (plugin)

����:

• �� CURD HTTP API ��������

Github PR: emqx/emqx-auth-username#82

12.7.4 emqx-web-hook (plugin)

����:

• �����������

Github issues: emqx/emqx-web-hook#93

Github PR: emqx/emqx-web-hook#96

12.7.5 minirest (deps)

����:

• �������� HTTP API

Github PR: emqx/minirest#12

12.7.6 gen_rpc (deps)

����:

• �� ‘gen_rpc’ � raw socket flags

Github PR: emqx/gen_rpc#5

12.8 3.1-beta.1 ��

����: 2019-02-28

EMQ X 3.1-beta.1 ������������������������ Bridge������������ redis ����

����:

• ���� Bridge ����� EMQ Broker ������ MQTT �����

Github PR: emqx/emqx#2199

• ��������

Github PR: emqx/emqx#2253

• �� gen_statem behaviour �� emqx_connection ��

Github PR: emqx/emqx#2235

• �������������

Github PR: emqx/emqx#2266

12.8. 3.1-beta.1 �� 201

EMQ X - ����� MQTT �����, �� 3.1.0

12.8.1 emqx-auth-redis

����:

• �� redis ��

Github PR: emqx/emqx-auth-redis#93

12.8.2 emqx-dashboard

����:

• � emqx_dashboard_cli ��������

Github PR: emqx/emqx-dashboard#34

12.8.3 emqx-auth-username

����:

• ���� CLI ��� username

Github PR: emqx/emqx-auth-username#74

12.8.4 emqx-auth-clientid

����:

• ���� CLI ��� clientid

Github PR: emqx/emqx-auth-clientid#59

12.9 3.0.1 ��

����: 2019-01-25

EMQ X 3.0.1 ����������������������

����:

• � emqx edge �� +L ����������

Github PR: emqx/emqx#2110

• �������������

Github PR: emqx/emqx#2115

• �� bridge ��; �� bridge �����

Github PR: emqx/emqx#2160, emqx/emqx#2117, emqx/emqx#2113, emqx/emqx#2108,emqx/emqx#2053

• ������

Github PR: emqx/emqx#2124

• �� ‘emqx_client’ ����

Github PR: emqx/emqx#2137

202 Chapter 12. ���� (Changes)

EMQ X - ����� MQTT �����, �� 3.1.0

• �� ‘emqx_pool’ �����

Github PR: emqx/emqx#2138

• ����������

Github PR: emqx/emqx#2144

• ���� emqx �������

Github PR: emqx/emqx#2175

����:

• ��������������

Github PR: emqx/emqx#2074

• �����������������������

Github PR: emqx/emqx#2156

12.9.1 emqx-lwm2m

����:

• ������

GitHub PR: emqx/emqx-lwm2m#14

12.9.2 emqx-auth-username

����:

• ���������

GitHub PR: emqx/emqx-auth-usernmae#64

12.9.3 emqx-auth-clientid

����:

• ���������

GitHub PR: emqx/emqx-auth-clientid#52

12.9.4 emqx-management

����:

• �� ‘plugins reload <Name>’ CLI ����������������

Github PR: emqx/emqx-management#30

12.9. 3.0.1 �� 203

EMQ X - ����� MQTT �����, �� 3.1.0

12.10 3.0.0 ��

����: 2018-12-22

EMQ X 3.0.0����������� ETS ����������� erlang �������� EMQ ��

����:

• ������������ vm.args ��

Github PR: emqx/emqx#2033, emqx/emqx#2057, emqx/emqx#2070

• �������������� ACL ��

Github PR: emqx/emqx#2075

• �� ACL ���������������������

Github PR: emqx/emqx#2059

• �� session ���

Github PR: emqx/emqx#2077

• �� ‘active_n’ ����� emqx_connection � CPU ���

Github PR: emqx/emqx#2060

• ���������

Github PR: emqx/emqx#2060

• ���������

Github PR: emqx/emqx#2044

• �� ‘emqx_gc’ ��

Github PR: emqx/emqx#2090

����:

• �� Topic Alias Maximum �����

Github PR: emqx/emqx#2074

• ������������������

Github PR: emqx/emqx#2068

12.10.1 emqx-auth-ldap

����:

• �����

GitHub PR: emqx/emqx-auth-ldap#46

12.10.2 emqx-lua-hook

����:

• ������

GitHub PR: emqx/emqx-lua-hook#45

204 Chapter 12. ���� (Changes)

EMQ X - ����� MQTT �����, �� 3.1.0

12.10.3 emqx-management

����:

• � REST API �����������������

Github PR: emqx/emqx-management#21

12.11 3.0-rc.5 ��

����: 2018-11-30

EMQ X 3.0-rc.5���������� metrics ����������:

����:

• ������

Github PR: emqx/emqx#1981

• �� metrics �����

Github PR: emqx/emqx#2001

• �� mnesia/ets �������

Github PR: emqx/emqx#2006

����:

• �� emqx_router �� ‘function_clause’ ��

Github PR: emqx/emqx#1998

• ������� simple ����

Github PR: emqx/emqx#2000

• �� emqx_reason_codes �������������

Github PR: emqx/emqx#2008

12.11.1 emqx-passwd

����:

• �� Rebar3

GitHub PR: emqx/emqx-passwd#6

12.11.2 emqx-web-hook

����:

• �� Rebar3

GitHub PR: emqx/emqx-web-hook#77

����:

• �� emqx-web-hook �� HTTP ������ username � clientid ���

GitHub PR: emqx/emqx-web-hook#77

12.11. 3.0-rc.5 �� 205

EMQ X - ����� MQTT �����, �� 3.1.0

12.11.3 emqx-dashboard

����:

• ������������������

Github PR: emqx/emqx-dashboard#12

12.11.4 emqx-management

����:

• �� clients � CLI ��

Github PR: emqx/emqx-management#16

12.12 3.0-rc.4 ��

����: 2018-11-24

EMQ X 3.0-rc.4��������������������� Rebar3 ��:

����:

• ��� MQTT v3.1.1‘�������� ‘loop delivery ���

Github PR: emqx/emqx#1964

• ���� username �� client_id������

Github PR: emqx/emqx#1961

• ������� both

Github PR: emqx/emqx#1979

• ��������������

Github PR: emqx/emqx#1977

• �� log tracer ������

Github PR: emqx/emqx#1973

• ������

Github PR: emqx/emqx#1960

����:

• �����������

Github PR: emqx/emqx#1969

• �� max_topic_alias ��������

Github PR: emqx/emqx#1962

• � client_id ����� proc meta-data ��������� client_id

Github PR: emqx/emqx#1980

206 Chapter 12. ���� (Changes)

EMQ X - ����� MQTT �����, �� 3.1.0

12.12.1 emqx-coap

����:

• �� Rebar3

GitHub PR: emqx/emqx-coap#89

����:

• �� sendfun �������

Github PR: emqx/emqx-coap#89

12.12.2 emqx-management

����:

• ��������� REST API ����������

Github PR: emqx/emqx-management#11

12.12.3 ekka

����:

• �����������

Github PR: emqx/ekka#39

12.12.4 minirest

����:

• ��Rebar3

Github PR: emqx/minirest#6

12.12.5 cuttlefish

����:

• � cuttlefish ������ std_error

Github PR: emqx/cuttlefish#4

12.12.6 emqx-rel

����:

• ����� cuttlefish

Github PR: emqx/emqx-rel#253

• ����� delay_publish ��

Github PR: emqx/emqx-rel#251

12.12. 3.0-rc.4 �� 207

EMQ X - ����� MQTT �����, �� 3.1.0

12.13 3.0-rc.3 ��

����: 2018-11-10

EMQ X 3.0-rc.3���������� emqx_mqueue ����� MQTT-SN, CoAP � STOMP ��:

����:

• � QOS$i ��� QOS_$i

Github PR: emqx/emqx#1948

• ������� ACL cache �����

Github PR: emqx/emqx#1950

• �� emqx_mqueue ��

Github PR: emqx/emqx#1926

• lager ��� OTP logger

Github PR: emqx/emqx#1898

����:

• �������� ‘badarg’ ��

Github PR: emqx/emqx#1943

• �� emqx_message:format �� ‘badarg’ ��

Github PR: emqx/emqx#1954

• �� MQTT bridge ���� TLS �����

Github PR: emqx/emqx#1949

12.13.1 emqx-stomp

����:

• �� receipt �����������

GitHub PR: emqx/emqx-stomp#53

12.13.2 emqx-sn

����:

• ��� MQTT-SN �����

GitHub PR: emqx/emqx-sn#90

12.13.3 emqx-lua-hook

����:

• �� emqx-lua-hook ���������

Github PR: emqx/emqx-lua-hook#41

208 Chapter 12. ���� (Changes)

EMQ X - ����� MQTT �����, �� 3.1.0

12.13.4 emqx-statsd

����:

• ������

Github PR: emqx/emqx-statsd#4

12.13.5 emqx-dashboard

����:

• �� qos2/forward ��

Github PR: emqx/emqx-dashboard#7

12.13.6 emqx-auth-pgsql

����:

• ������� emqx-auth-pgsql �����

Github PR: emqx/emqx-auth-pgsql#94

12.14 3.0-rc.2 ��

����: 2018-10-27

EMQ X 3.0-rc.2���������� Will Message ����������� ssl ���� MQTT ���:

����:

• �� Will Message �������������

Github PR: emqx/emqx#1889

• ������ ssl ���� MQTT ���

Github PR: emqx/emqx#1913

• ���������

Github PR: emqx/emqx#1921

����:

• �� emqx_broker:subscribed �� ‘bad argument’ ��

Github PR: emqx/emqx#1921

12.15 3.0-rc.1 ��

����: 2018-10-20

EMQ X 3.0-rc.1���������� request & response �� LwM2M ����� PUBLISH ����:

����:

12.14. 3.0-rc.2 �� 209

EMQ X - ����� MQTT �����, �� 3.1.0

• � CONNECT & CONNACK ���� request & response ��

Github PR: emqx/emqx#1819

• �������������

Github PR:

emqx/emqx#1878

• �� emqx_hooks ������, � emqx_mod_sup ��������

Github PR:

emqx/emqx#1892

����:

• �� ACL ����

Github PR: emqx/emqx#1899

• ���� PUBLISH ��������

Github PR: emqx/emqx#1888

• ���������� Reason Code � client � BUG

Github PR: emqx/emqx#1819

• �� emqx_client ���������

Github PR: emqx/emqx#1819

12.15.1 emqx-lwm2m

• �� LwM2M ����� EMQ X 3.0

Github PR: emqx/emqx-lwm2m#3

12.16 3.0-Beta.4 ��

����: 2018-09-29

EMQ X 3.0-beta.4 ������������ Shutdown ��������� sticky ����� Delayed Publish ���

����:

• ������ max_heap_size

GitHub issues: emqx/emqx#1855

• �� Topic �� Maximum��� Receive Maximum

GitHub issues: emqx/emqx#1873

• ������ sticky �� pick ID ��

GitHub issues: emqx/emqx#1871

• � Zone �� Mountpoint ��

GitHub issues: emqx/emqx#1869

210 Chapter 12. ���� (Changes)

EMQ X - ����� MQTT �����, �� 3.1.0

• ��make app.config ��

GitHub issues: emqx/emqx#1868,

• �� Hooks ������

GitHub issues: emqx/emqx#1866

• �� travis ���� rebar3 xref

GitHub issues: emqx/emqx#1861

• ����� esockd � v5.4.2

GitHub issues: emqx/emqx#1875

• ����� erlang-bcrypt �0.5.1

GitHub issues: emqx/emqx-passwd#3

12.16.1 emqx-delayed-publish

• ��������

GitHub issues: emqx/emqx-delayed-publish#5

12.16.2 emqx-passwd

• �� check_pass ������������

GitHub issues: emqx/emqx-passwd#3

12.16.3 bcrypt

• �� bcrypt ����

GitHub issues: emqx/erlang-bcrypt#1

12.16.4 esockd

• �� DTLS PSK ��

GitHub issues: emqx/esockd#88

• �� DTLS ����

GitHub issues: emqx/esockd#89

• �� SSL ����

GitHub issues: emqx/esockd#90

12.16. 3.0-Beta.4 �� 211

EMQ X - ����� MQTT �����, �� 3.1.0

12.17 3.0-Beta.3 ��

����: 2018-09-22

EMQ X 3.0-beta.3�����������������������GC�������:

����:

• �� travis ��

GitHub issues: emqx/emqx#1818

• ����emqx_mqueue.erl����

GitHub issues: emqx/emqx#1815

• ����������

GitHub issues: emqx/emqx#1823

• ��emqx_pool������

GitHub issues: emqx/emqx#1827

• ����shutdown��

GitHub issues: emqx/emqx#1836

• ��KeepAlive����

GitHub issues: emqx/emqx#1839

• ���������

GitHub issues: emqx/emqx#1846

• ��Bridge��

GitHub issues: emqx/emqx#1849

• ��force_gc_policy��

GitHub issues: emqx/emqx#1851

• ��Maximum-QoS���

GitHub issues: emqx/emqx#1852

• �����esockd�v5.4.1

GitHub issues: emqx/emqx#1858

����:

• ��API����������

GitHub issues: emqx/emqx#1706

• WebSocket ����Path��

GitHub issues: emqx/emqx#1809

• ����������block��

GitHub issues: emqx/emqx#1811

• ����check_expiry

GitHub issues: emqx/emqx#1813

212 Chapter 12. ���� (Changes)

EMQ X - ����� MQTT �����, �� 3.1.0

• ��DISCONNECT��Session Expiry Interval����

GitHub issues: emqx/emqx#1833

• ��DISCONNECT��Max Session Expiry Interval����

GitHub issues: emqx/emqx#1834

12.17.1 emqx-management

• ��Bridge CTL��

• ������emqx_mgmt_cli:print() crash��

• ��emqx_mgmt:subscribe��’function_clause’��

GitHub issues: emqx/emqx-management#1815

12.17.2 emqx-web-hook

����emqx_web_hook��

12.17.3 emqx-dashboard

• �� Dashboard -> OverView �disconnect������

• � Dashboard -> Websocket ��WebSocket Path��

GitHub issues: emqx/emqx-dashboard#5

12.17.4 emqx-retainer

• Retained ����TTL

GitHub issues: emqx/emqx-retainer#52

12.17.5 emqx-coap

• ��emqx_coap��

GitHub issues: emqx/emqx-coap#5 emqx/gen-coap#5

12.17.6 emqx-docker

• ��Dockerfile

GitHub issues: emqx/emqx-docker#5

12.17.7 esockd

• ��esockd_connection_sup����

GitHub issues: emqx/esockd#86

12.17. 3.0-Beta.3 �� 213

EMQ X - ����� MQTT �����, �� 3.1.0

12.18 3.0-Beta.2 ��

����: 2018-09-10

EMQ X 3.0-Beta.2 �������� MQTT 5.0 ��������������

12.18.1 EMQ X Core

����:

• �� MQTT 5.0 ‘subscription options’

GitHub issues: emqx/emqx#1788, emqx/emqx-retainer#58, emqx/emqx#1803

• ��� MQTT 5.0 ‘Topic-Alias’ ���

GitHub issues: emqx/emqx#1789, emqx/emqx#1802

• �� hooks ���

GitHub issue: emqx/emqx#1790

• ��� ‘emqx_mqtt_properties’ ���� ‘emqx_mqtt_props’

GitHub issue: emqx/emqx#1791

• �� emqx_zone

GitHub issue: emqx/emqx#1795

����:

• ��� ‘Will Delay Interval’ ������

GitHub issues: emqx/emqx#1800, emqx/emqx-delayed-publish#3

• ��� ‘Reserved’ ��������

GitHub issue: emqx/emqx#1783

• �����������

GitHub issue: emqx/emqx#1794

12.18.2 emqx-management (��)

����:

• �� ‘banned’ ��� restful API

GitHub issue: emqx/emqx-management#6

12.18.3 emqx-delayed-publish (��)

����:

• ����

GitHub issue: emqx/emqx-delayed-publish#4

214 Chapter 12. ���� (Changes)

EMQ X - ����� MQTT �����, �� 3.1.0

12.18.4 minirest (����)

����:

• ���������� query ��� body ��

GitHub issue: emqx/minirest#4

12.18.5 emqx-rel (����)

����:

• ����� OTP ��

GitHub issue: emqx/emqx-rel#217

12.19 3.0-Beta.1 ��

����: 2018-09-02 ����: The Promise of Tomorrow

3.0-beta.1 ��������� MQTT-3.1.1 ������ ���� MQTT-5.0 ��� ���������������������������������������

12.19.1 ���� MQTT-5.0

EMQX 3.0 ��������� MQTT-5.0 ������ MQTT-5.0 �����:

• ����� MQTT ������: AUTH

MQTT-5.0 ������� AUTH ����������������������

• Session ����

����� “Clean session flag” ����������: “Clean Start Flag”�”Session Expiry Interval”�

• Message ����

MQTT-5.0 ���������������������

• ��� ACK ���� Reason Code

MQTT-5.0 ������������ Reason Code ����������������������

• ��� ACK ���� Reason String

�� Reason Code ���������������� Reason String�

• Server �����

MQTT-5.0 ��Server �������������

• Payload format and content type

MQTT-5.0 ������������ Payload ����� MIME ��� content type�

• Request/Response ��

����� property������ MQTT ��� Request/Response ������

• ����

EMQ X 2.x ����������� �� EMQ X 3.0 ����������������

12.19. 3.0-Beta.1 �� 215

EMQ X - ����� MQTT �����, �� 3.1.0

• �� ID

������ ID��������������������

• Topic ��

Topic ������������������ MQTT ��� Topic ����������

• ������ User properties

MQTT-5.0 ����������� User properties�

• ������

EMQ X 2.x ����� Broker ��������������������� Broker �������MQTT-5.0 ���� CONNECT/CONNECT ACK �������Broker �������������

• ��� Server ����� (TODO)

Broker ���������������������

• ����

MQTT-5.0 ��������������������� �� nolocal�� retained ����������

• Will delay

MQTT-5.0 ���������������������������������������������������������

• Broker ������

MQTT-5.0 ��Broker �������������������

• Assigned ClientID

MQTT-5.0 ���� ClientID � Broker ������������� ClientID ����

• Server reference

MQTT-5.0 ��Broker ���������� Broker �����������������

12.19.2 ������

EQMX 3.0 ��������� RPC ���������������������:

-------- --------| EMQX |<--- MQTT--->| EMQX ||--------| |--------|| Ekka |<----RPC---->| Ekka ||--------| |--------|| Mnesia |<--Cluster-->| Mnesia ||--------| |--------|| Kernel |<----TCP---->| Kernel |-------- --------

�� Ekka ������������������������������:

• manual: ������;

• static: ���������������;

• mcast: ����������;

• dns: �� DNS A ��������;

216 Chapter 12. ���� (Changes)

EMQ X - ����� MQTT �����, �� 3.1.0

• etcd: �� etcd ������;

• k8s: �� k8s �������

12.19.3 ������

3.0 ������������� Broker ������ MQTT TCP � SSL �����������:

• ������: max_clients

• ������: max_conn_rate

• ������: rate_limit

• ������: max_publish_rate

12.19.4 Feature improvements and Bug Fixes

• ��� esockd;

• �� cowboy ��� HTTP �����;

• ��� ACL ����;

• ������� MQTT ����;

• ������ “zone” ������� “zone” ���������;

• ��� session �������������������������;

• ��� OpenLDAP � Access Control;

• ���������;

• ����� Prometheus ����������;

• ��� hook ���

12.20 2.3.11 ��

����: 2018-07-23

12.20.1 Bugfix and Enhancements

Fix the getting config REST API which throws exceptions.

Support to restart listeners when emqttd is running.

Specify a fixed tag for the dependency libraries.

12.20.2 emq-auth-jwt

Fix token verification with jwerl 1.0.0

12.20. 2.3.11 �� 217

EMQ X - ����� MQTT �����, �� 3.1.0

12.20.3 emq-auth-mongo

Support $all variable in ACL query. (emq-auth-mongo#123)

Support both clientid and username variables in all queries. (emq-auth-mongo#123)

12.21 2.3.10 ��

����: 2018-06-27

12.21.1 Bugfix and Enhancements

Upgrade the esockd library to v5.2.2

12.21.2 emq-auth-http

Ignore auth on ignore in body, allows for chaining methods

12.22 2.3.9 ��

����: 2018-05-20

12.22.1 Bugfix and Enhancements

Bugfix: check params for REST publish API (#1599)

Upgrade the mongodb library to v3.0.5

12.22.2 esockd

Bugfix: proxy protocol - set socket to binary mode (#78)

12.23 2.3.8 ��

����: 2018-05-11

12.23.1 Bugfix and Enhancements

Bugfix: unregister users CLI when unload emq_auth_username (#1588)

Bugfix: Should be an info level when change CleanSession (#1590)

Bugfix: emqttd_ctl crashed when emq_auth_usename doesn’t exist (#1588)

218 Chapter 12. ���� (Changes)

EMQ X - ����� MQTT �����, �� 3.1.0

12.23.2 emq-auth-mongo

Improve: Support authentication database (authSource) (#116)

12.24 2.3.7 ��

����: 2018-04-22

12.24.1 Bugfix and Enhancements

Bugfix: fixed spec of function setstats/3 (#1575)

Bugfix: clean dead persistent session on connect (#1575)

Bugfix: dup flag not set when re-deliver (#1575)

Bugfix: Upgrade the lager_console_backend config (#1575)

Improve: Support set k8s namespace (#1575)

Upgrade the ekka library to v0.2.3 (#1575)

Improve: move PIPE_DIR dir from /tmp/${WHOAMI}_erl_pipes/$NAME/ to /$RUN-NER_DATA_DIR/${WHOAMI}_erl_pipes/$NAME/ (emq-relx#188)

12.24.2 emq-auth-http

Improve: Retry 3 times when httpc:request occurred socket_closed_remotely error (emq-auth-http#70)

12.25 2.3.6 ��

����: 2018-03-25

12.25.1 Bugfix and Enhancements

Security: LWT message checking the ACL (#1524)

Bugfix: Retain msgs should not be sent to existing subscriptions (#1529)

12.25.2 emq-auth-jwt

Validate JWT token using a expired field (#29)

12.26 2.3.5 ��

����: 2018-03-03

12.24. 2.3.7 �� 219

EMQ X - ����� MQTT �����, �� 3.1.0

12.26.1 Bugfix and Enhancements

Feature: Add etc/ssl_dist.conf file for erlang SSL distribution (emq-relx#178)

Feature: Add node.ssl_dist_optfile option and etc/ssl_dist.conf file (#1512)

Feature: Support Erlang Distribution over TLS (#1512)

Improve: Tune off the ‘tune_buffer’ option for external MQTT connections (#1512)

12.26.2 emq-sn

Clean registered topics if mqtt-sn client send a 2nd CONNECT in connected state (#76)

Upgrade the esockd library to v5.2.1 (#76)

12.26.3 emq-auth-http

Remove ‘password’ param from ACL and superuser requests (#66)

12.27 2.3.4 ��

����: 2018-01-29

12.27.1 Bugfix and Enhancements

Feature: Forward real client IP using a reverse proxy for websocket (#1335)

Feature: EMQ node.name with link local ipv6 address not responding to ping (#1460)

Feature: Add PROTO_DIST_ARG flag to support clustering via IPv6 address. (#1460)

Bugfix: retain bit is not set when publishing to clients (when it should be set). (#1461)

Bugfix: Can’t search topic on web dashboard (#1473)

12.27.2 emq-sn

Bugfix: CONNACK is not always sent to the client (emq-sn#67)

Bugfix: Setting the port to ::1:2000 causes error (emq-sn#66)

12.28 2.3.3 ��

����: 2018-01-08

220 Chapter 12. ���� (Changes)

EMQ X - ����� MQTT �����, �� 3.1.0

12.28.1 Bugfix and Enhancements

Add a full documentation for emq.conf and plugins.

Repair a dead link in README - missing emq-lwm2m. (#1430)

Subscriber with wildcard topic does not receive retained messages with sub topic has $ sign (#1398)

Web Interface with NGINX Reverse Proxy not working. (#953)

12.28.2 emq-dashboard

Add dashboard.default_user.login, dashboard.default_user.password options to support configuring defaultadmin.

12.28.3 emq-modules

The emq-modules rewrite config is not right. (#35)

12.28.4 emq-docker

Upgrade alpine to 3.7 (#31)

12.28.5 emq-packages

Support ARM Platform (#12)

12.29 2.3.2 ��

����: 2017-12-26

12.29.1 Bugfix and Enhancements

Support X.509 certificate based authentication (#1388)

Add proxy_protocol, proxy_protocol_timeout options for ws/wss listener.

Cluster discovery etcd nodes key must be created manually. (#1402)

Will read an incorrect password at the last line of emq_auth_username.conf (#1372)

How can I use SSL/TLS certificate based client authentication? (#794)

Upgrade the esockd library to v5.2.

12.29. 2.3.2 �� 221

EMQ X - ����� MQTT �����, �� 3.1.0

12.29.2 esockd

Improve the parser of proxy protocol v2.

Add ‘send_timeout’, ‘send_timeout_close’ options.

Rename esockd_transport:port_command/2 function to async_send/2.

Add test case for esockd_transport:async_send/2 function.

Add esockd_transport:peer_cert_subject/1, peer_cert_common_name/1 functions.

12.29.3 emq-auth-mysql

Update depends on emqtt/mysql-otp.

Fixed the issue that Cannot connect to MySQL 5.7 (#67).

12.29.4 emq-relx

Fix mergeconf/3 appending line break error. (#152)

12.29.5 emq-sn

Fix crash in emq_sn_gateway:transform() function which handles SUBACK. (#57)

Define macro SN_RC_MQTT_FAILURE. (#59)

12.29.6 emq-web-hook

Filter auth_failure client for disconnected hook. (#30)

12.30 2.3.1 ��

����: 2017-12-03

12.30.1 Bugfix and Enhancements

Remove the unnecessary transactions to optimize session management.

Should not exit arbitrarily when clientid conflicts in mnesia.

Change the default value of ‘mqtt.session.enable_stats’ to ‘on’.

The DUP flag should be set to 0 for all QoS0 messages. (emqttd#1319)

Fix the ‘no function clause’ exception. (emqttd#1293)

The retained flags should be propagated for bridge. (emqttd#1293)

The management API should listen on 0.0.0.0:8080. (emqttd#1353)

Fast close the invalid websocket in init/1 function.

erlang:demonitor/1 the reference when erasing a monitor. (emqttd#1340)

222 Chapter 12. ���� (Changes)

EMQ X - ����� MQTT �����, �� 3.1.0

12.30.2 emq-retainer

Don’t clean the retain flag after the retained message is stored.

Add three CLIs for the retainer plugin. (emq-retainer#38)

12.30.3 emq-dashboard

Refactor(priv/www): improve the routing page. (emq-dashboard#185)

12.30.4 emq-modules

Turn off the subscription module by default. (emq-modules#26)

12.30.5 emq-sn

Add an integration test case for sleeping device.

Do not send will topic if client is kicked out.

Prevent crash information in log when emq_sn_gateway getting timeout, since it is a possible procedure.

12.30.6 emq-relx

Support node cookie value with = characters. (emq-relx#146)

12.30.7 mochiweb

Improve Req:get(peername) funciton to support x-forwarded-for and x-remote-port. (emqtt/mochiweb#9)

12.31 2.3.0 �� “Passenger’s Log”

����: 2017-11-20

EMQ 2.3.0 ���������� PubSub ������������ EMQ ������ SSL ����� Dashboard ��� API ���

12.31.1 Bugfix and Enhancements

Fix the issue that Retained message is not sent for Subscribe to existing topic. (emqttd#1314)

Fix the issue that The DUP flag MUST be set to 0 for all QoS0 messages.(emqttd#1319)

Improve the pubsub design and fix the race-condition issue. (emqttd#PR1342)

Crash on macOS High Sierra (emqttd#1297)

12.31.2 emq-dashboard Plugin (emq-dashboard#PR174)

Upgraded the ‘subscriptions’ RESTful API.

Improvement of the auth failure log. (emq-dashboard#59)

12.31. 2.3.0 �� “Passenger’s Log” 223

EMQ X - ����� MQTT �����, �� 3.1.0

12.31.3 emq-coap Plugin (emq-coap#PR61)

Replaced coap_client with er_coap_client.

Fix: correct the output format of coap_discover() to enable “.well-known/core”.

Refactor the coap_discover method.

12.31.4 emq-relx

Upgraded the bin/nodetool script to fix the rpcterms command.

12.31.5 emq-web-hook Plugin

Fix the emq_web_hook plugin getting username from client.connected hook. (emq-web-hook#19)

12.31.6 emq-auth-jwt Plugin(emq-auth-jwt#PR15)

Added test cases for emq_auth_jwt.

Fix jwt:decode/2 functions’s return type.

12.31.7 emq-auth-mongo Plugin(emq-auth-mongo#PR92)

Updated the default MongoDB server configuration.

12.32 2.3-rc.2 ��

����: 2017-10-22

12.32.1 Bugfix

Change the default logging level of trace CLI. (emqttd#1306)

12.32.2 emq-dashboard Plugin (emq-dashboard#164)

Fix the ‘Status’ filters of plugins’s management.

Fix the URL Redirection when deleting an user.

Compatible with IE,Safari,360 Browsers.

12.33 2.3-rc.1 ��

����: 2017-10-12

224 Chapter 12. ���� (Changes)

EMQ X - ����� MQTT �����, �� 3.1.0

12.33.1 Bugfix

Fix the issue that invalid clients can publish will message. (emqttd#1230)

Fix Dashboard showing no stats data (emqttd#1263)

Fix a rare occurred building failure (emqttd#1284)

Support Persistence Logs for longer time (emqttd#1275)

Fix for users APIs (emqttd#1289)

Changed passwd_hash/2 function’s return type (emqttd#1289)

12.33.2 emq-dashboard Plugin (emq-dashboard#154)

Improved the Dashboard Interface of Monitoring/Management/Tools.

Allow switching dashboard themes.

Supoort both EN and CN languages.

12.34 2.3-beta.4 ��

����: 2017-09-13

12.34.1 Highlights

Released a new sexy dashboard.

Add more RESTful APIs for manangement and monitoring.

Configuring the broker through CLI or API without having to restart.

12.34.2 Bugfix

Job for emqttd.service failed because the control process exited with error code. (emqttd#1238)

Travis-CI Build Failing (emqttd#1221)

Https listener of Dashboard plugin won’t work (emqttd#1220)

Service not starting on Debian 8 Jessie (emqttd#1228)

12.34.3 emq-dashboard

1. Support switching to other clustered node.

2. Configure and reboot the plugins on the dashboard.

3. A login page to replace the basic authentication popup window.

12.34. 2.3-beta.4 �� 225

EMQ X - ����� MQTT �����, �� 3.1.0

12.34.4 emq-coap

1.Try to clarify the relationship between coap and mqtt in EMQ. (emq-coap#54).

2.Fix crashes in coap concurrent test(gen-coap#3).

12.35 2.3-beta.3 ��

����: 2017-08-21

12.36 2.3-beta.3 ��

����: 2017-08-21

12.36.1 Enhancements

Add HTTP API for hot configuration.

12.36.2 Bugfix

1. Parse ‘auth.mysql.password_hash’ error when hot configuration reload (emq-auth-mysql#68)

2. Set ‘auth.pgsql.server’ error when hot configuration reload (emq-auth-pgsql#67)

3. Set ‘auth.redis.server’ and ‘auth.redis.password_hash’ error when hot configuration reload (emq-auth-redis#47)

4. Fix the issue that when deleting retained message subscribed clients are not notified (emqttd#1207)

5. Support more parameters for hot configuration reload:

• mqtt.websocket_protocol_header = on

• mqtt.mqueue.low_watermark = 20%

• mqtt.mqueue.high_watermark = 60%

• mqtt.client.idle_timeout = 30s

• mqtt.client.enable_stats = off

12.37 2.3-beta.2 ��

����: 2017-08-12

EMQ R2.3-beta.2 ���������� HTTP �� API����� Keepalive ���������������

�������������:

• emq-stomp

• emq-coap

• emq-sn

226 Chapter 12. ���� (Changes)

EMQ X - ����� MQTT �����, �� 3.1.0

• emq-lwm2m

• emq-retainer

• emq-recon

• emq-web-hook

• emq-auth-jwt

• emq-auth-http

• emq-auth-mongo

• emq-auth-mysql

• emq-auth-pgsql

• emq-auth-redis

��: ������������������������’,’���������

12.37.1 Enhancements

1. Introduce new HTTP management API.

2. Add ClientId parameter for HTTP Publish API.

3. Allow configuring keepalive backoff.

4. Remove the fullsweep_after option to lower CPU usage.

5. Authorize HTTP Publish API with clientId.

12.37.2 emq-sn Plugin (emq-sn#49)

1. Support CONNECT message in connected/wait_for_will_topic/wait_for_will_msg states.

2. Clean registered topic for a restarted client.

3. Bug fix of not clearing buffered PUBLISH messages received during asleep state as those messages aresent to client when client wakes up.

12.37.3 emq-auth-ldap Plugin (emq-auth-ldap#21)

Improve the design LDAP authentication.

12.37.4 emq-coap Plugin (emq-coap#51)

Support CoAP PubSub Specification (https://www.ietf.org/id/draft-ietf-core-coap-pubsub-02.txt)

12.38 2.3-beta.1 ��

����: 2017-07-24

EMQ R2.3-beta.1����������������������������������IP Multicast�Etcd�Kubernetes������������

12.38. 2.3-beta.1 �� 227

EMQ X - ����� MQTT �����, �� 3.1.0

12.38.1 ���������

EMQ R2.3 ������������������:

�� ��static ����������mcast UDP��������dns DNS A������etcd ��etcd����k8s Kubernetes������

12.38.2 ���������

EMQ R2.3��������������(Network Partition Autoheal):

cluster.autoheal = on

����������:

1. ����Mnesia��’inconsistent_database’��3�����������

2. �������������Leader��(���������)�������

3. Leader��������������������������(SplitView)�

4. Leader������(Majority)���������Coordinator���

5. Coordinator�������(minority)���������

12.38.3 ���������

EMQ R2.3���������������(Autoclean):

cluster.autoclean = 5m

12.38.4 LWM2M����

EMQ R2.3 ������LWM2M��������LWM2M���������MQTT�������EMQ-LWM2M����LWM2M����������EMQ-LWM2M��notification��EMQ����������

LWM2M��Open Mobile Alliance(OMA)������������������������������LWM2M��CoAP�������������UDP��SMS�

12.38.5 JSON Web Token����

EMQ R2.3 ������JWT(JSON Web Token)�MQTT������

12.38.6 Retainer��

Retainer����’disc_only’����retained���

228 Chapter 12. ���� (Changes)

EMQ X - ����� MQTT �����, �� 3.1.0

12.38.7 Debian 9 ���

EMQ R2.3 ��Debian 9������

12.38.8 Erlang/OTP R20

EMQ R2.3 ����Erlang/OTP R20��������Erlang/OTP R20���

12.39 2.2 ��� “Nostalgia”

����: 2017-07-08

����: Nostalgia

EMQ-2.2.0�������EMQ R2.2������CoAP(RFC 7252)�MQTT-SN�����Web Hook�Lua Hook�Proxy ProtocolV2���Elixir�������

Feature: Add ‘listeners restart/stop’ CLI command (emqttd#1135)

Bugfix: Exit Code from emqttd_ctl (emqttd#1133)

Bugfix: Fix spec errors found by dialyzer (emqttd#1136)

Bugfix: Catch exceptions thrown from rpc:call/4 (emq-dashboard#128)

Bugfix: Topic has been decoded by gen-coap, no conversion needed (emq-coap#43)

12.40 2.2-rc.2 ��

����: 2017-07-03

��: 2.2-rc.2��������Erlang/OTP R19.3+

12.40.1 �����

Compatible with Erlang/OTP R20 (emq-relx#77)

CoAP gateway plugin supports coap-style publish & subscribe pattern. (emq_coap#33)

MQTT-SN gateway plugin supports sleeping device (emq_sn#32)

Upgrade esockd and mochiweb libraries to support restarting a listener

12.41 2.2-rc.1 ��

����: 2017-06-14

12.39. 2.2 ��� “Nostalgia” 229

EMQ X - ����� MQTT �����, �� 3.1.0

12.41.1 �����

Add a new listener for HTTP REST API (emqttd#1094)

Fix the race condition issue caused by unregister_session/1 (emqttd#1096)

Fix the issue that we cannot remove a down node from the cluster (emqttd#1100)

Passed org.eclipse.paho.mqtt_sn.testing/interoperability tests (emq_sn#29)

Fix the issue that send http request and return non-200 status code, but AUTH/ACL result is denied(emq-auth-http#33)

Fix the issue that fail to stop listener (emq_stomp#24)

Support using systemctl to manage emqttd service on CentOS

12.42 2.2-beta.3 ��

����: 2017-05-27

12.42.1 �����

Call emit_stats when force GC (emqttd#1071)

Update the default value of ‘mqtt.mqueue.max_length’ to 1000 (emqttd#1074)

Update emq-auth-mongo READEME (emq-auth-mongo#66)

Update default password field (emq-auth-mongo#67)

Upgrade the mongodb library to v3.0.3

Remove ‘check password===undefined && userName!== undefined’ (emq-dashboard#120)

12.42.2 emq_auth_redis��

����HGET��

12.42.3 emq_auth_mongo��

��mongodb���Replica Set

12.42.4 ����

��Windows������

12.43 2.2-beta.2 ��

����: 2017-05-20

230 Chapter 12. ���� (Changes)

EMQ X - ����� MQTT �����, �� 3.1.0

12.43.1 �����

Add a ‘websocket_protocol_header’ option to handle WebSocket connection from WeChat (emqttd#1060)

Assign username and password to MQTT-SN’s CONNECT message (emqttd#1041)

Allow for Content-Type:application/json in HTTP Publish API (emqttd#1045)

emqttd_http.erl:data conversion (emqttd#1059)

Seperate emq_sn from emqttd (emq-sn#24)

Check St0’s type, making it easier to debug crash problems (emq-lua-hook#6)

Fix error: load xxx.lua (emq-lua-hook#8)

Leave luerl alone as a rebar project (emq-lue-hook#9)

Display websocket data in reverse order (emq-dashboard#118)

priv/www/assets/js/dashboard.js:Fixed a typo (emq-dashboard#118)

12.43.2 Update README

Update README of emq-auth-pgsql: add the ‘ssl_opts’ configuration (emq-auth-pgsql#56)

Update README of emq-auth-mysql: fix the ‘passwd_hash’ typo (emq-auth-mysql#54)

Update README of emq-auth-mongo: change ‘aclquery’ to ‘acl_query’ (emq-auth-mongo#63)

12.43.3 Elixir Plugin

Add a new plugin emq-elixir-plugin to support Elixir language.

12.44 2.2-beta.1 ��

����: 2017-05-05

EMQ 2.2-beta.1�������EMQ2.2 �����������:

1. ��MQTT�����������HAProxy�Proxy Protocol V1/V2

2. ��Web Hook��(emq-web-hook)�Lua Hook��(emq-lua-hook)

12.44.1 MQTT�������

��EMQ�������MQTT�������������external, internal�����������������:

--------- Ex���Web Hook�Lua Hook�ernal TCP 1883 --> | |

| EMQ | -- Internal TCP 2883 --> Service-- External SSL 8883--> | |

-------

EMQ 2.2 ��etc/emq.conf�������:

12.44. 2.2-beta.1 �� 231

EMQ X - ����� MQTT �����, �� 3.1.0

listener.tcp.${name}= 127.0.0.1:2883

listener.tcp.${name}.acceptors = 16

listener.tcp.${name}.max_clients = 102400

12.44.2 Proxy Protocol V1/2��

EMQ ������������(LB)�������:

-----| || L | --TCP 1883--> EMQ

--SSL 8883--> | | || B | --TCP 1883--> EMQ| |-----

HAProxy�NGINX���������(LB)�����Proxy Protocol����TCP����������EMQ�

EMQ 2.2 ��������Proxy Protocol��:

## Proxy Protocol V1/2## listener.tcp.${name}.proxy_protocol = on## listener.tcp.${name}.proxy_protocol_timeout = 3s

12.44.3 Web Hook��

��WebHook��: emq-web-hook ����MQTT����������������WebHook���

12.44.4 Lua Hook��

��Lua Hook��: emq-lua-hook ���Lua����EMQ����������

12.44.5 �������

EMQ 2.2 ������������������ignore(������������)����������������:

------------- ------------ -------------Client --> | Redis�� | -ignore-> | HTTP�� | -ignore-> | MySQL�� |

------------- ------------ -------------| | |

\|/ \|/ \|/allow | deny allow | deny allow | deny

12.44.6 ��bcrypt��Hash

EMQ 2.2 ����bcrypt��Hash�����Redis������:

232 Chapter 12. ���� (Changes)

EMQ X - ����� MQTT �����, �� 3.1.0

auth.redis.password_hash = bcrypt

12.44.7 etc/emq.conf����

‘mqtt.queue.*’ ����� ‘mqtt.mqueue.*’

12.44.8 emq-dashboard

WebSocket����Unsubscribe

12.45 2.1.2 ��

����: 2017-04-21

Fix emqttd_ctl sessions list CLI

Newline character in emq.conf causing error;(emqttd#1000)

Fix crash caused by duplicated PUBREC packet (emqttd#1004)

Unload the ‘session.created’ and ‘session.teminated’ hooks (emq-plugin-template)

12.46 2.1.1 ��

����: 2017-04-14

Localhost:8083/status returns 404 when AWS LB check the health of EMQ (emqttd#984)

Https listener not working in 2.1.0 as in 2.0.7 (emq-dashboard#105)

Fix mqtt-sn Gateway not working (emq-sn#12)

Upgrade emq-sn Plugin (emq-sn#11)

Upgrade emq-coap Plugin (emq-coap#21)

12.47 2.1.0 ��

����: 2017-04-07

The stable release of 2.1 version.

Trouble with auth.mysql.acl_query (emq-auth-mysql#38)

Filter the empty fields in ACL table (emq-auth-mysql#39)

12.45. 2.1.2 �� 233

EMQ X - ����� MQTT �����, �� 3.1.0

12.48 2.1.0-rc.2 ��

����: 2017-03-31

Support pbkdf2 hash (emq-auth-mongo#46)

Kickout the conflict WebSocket connection (emqttd#963)

Correct licence in app.src (emqttd#958)

SSL options to connect to pgsql (emq-auth-pgsql#41)

12.49 2.1.0-rc.1 ��

����: 2017-03-24

EMQ fails to start if run under a different linux user than that which first ran it (emqttd#842)

Depend on emqtt/pbkdf2 to fix the building errors of Travis CI (emqttd#957)

Depend on goldrush and emqtt/pbkdf2 to resolve the building errors (emqttd#956)

Fix ‘rebar command not found’ (emq-relx#33)

Compile error in v2.1.0-beta.2 (emq-relx#32)

Support salt with passwords (emq-auth-mongo#11)

Change the default storage_type to ‘ram’ (emq-retainer#13)

12.50 2.1.0-beta.2 ��

����: 2017-03-13

Cannot find AwaitingAck (emqttd#597)

EMQ V2.1 crash when public with QoS = 2 (emqttd#919)

Support pbkdf2 hash (emqttd#940)

Add src/emqttd.app.src to be compatible with rebar3 (emqttd#920)

Add more test cases (emqttd#944)

CRASH REPORT Process <0.1498.0> with 0 neighbours crashed with reason:{ssl_error,{tls_alert,”certificate unknown”}} in esockd_connection:upgrade (emqttd#915)

‘auth.redis.password_hash = plain’ by default (emq-auth-redis#20)

12.51 2.1.0-beta.1 ��

����: 2017-02-24

EMQ 2.1.0-beta.1�����

��: 2.1.x��������Erlang/OTP R19+

234 Chapter 12. ���� (Changes)

EMQ X - ����� MQTT �����, �� 3.1.0

EMQ���� Semantic Versioning 2.0.0 �����������’Tick-Tock’���������������������������������������

12.51.1 GC��

1. WebSocket�Client�Session�����������Hibernate�GC�

2. ��’mqtt.conn.force_gc_count’���Client�Session�������������GC�

3. ����WebSocket�Client�Session��fullsweep_after���������GC�

12.51.2 API��

Hooks API�����Tag����������������Hook�����

12.51.3 ����

emqttd#916: Add ‘mqtt_msg_from()’ type

emq-auth-http#15: ACL endpoint isnt called

12.52 2.1-beta ��

����: 2017-02-18

EMQ v2.1-beta���������Session/Inflight��������������Inflight QoS1/2������������������CPU���

12.52.1 Client, Session����

�����Client�Session�������etc/emq.conf�������’enable_stats’��:

mqtt.client.enable_stats = 60s

mqtt.session.enable_stats = 60s

12.52.2 ��missed����

EMQ�����PUBACK�PUBREC�PUBREL�PUBCOMP�����Inflight��������������missed����:

packets/puback/missed

packets/pubrec/missed

packets/pubrel/missed

packets/pubcomp/missed

12.52. 2.1-beta �� 235

EMQ X - ����� MQTT �����, �� 3.1.0

12.52.3 Syslog����

����EMQ���Syslog�etc/emq.config���:

## Syslog. Enum: on, offlog.syslog = on

## syslog level. Enum: debug, info, notice, warning, error, critical, alert, emergencylog.syslog.level = error

12.52.4 Tune QoS��

�������QoS�etc/emq.conf���:

mqtt.session.upgrade_qos = on

12.52.5 ‘acl reload’����

Reload acl.conf without restarting emqttd service (#885)

12.52.6 �����

1. �� mqtt.client_idle_timeout � mqtt.client.idle_timeout

2. �� mqtt.client.enable_stats ���

3. �� mqtt.session.upgrade_qos ���

4. �� mqtt.session.collect_interval ���

5. �� mqtt.session.enable_stats ���

6. �� mqtt.session.expired_after � mqtt.session.expiry_interval

12.52.7 �������emq_modules��

��emq_mod_presence, emq_mod_subscription, emq_mod_rewrite�emq_modules��

��emq_mod_retainer�emq_retainer��

12.52.8 Dashboard��

Overview����missed������� Client����SendMsg�RecvMsg����� Session����DeliverMsg�EnqueueMsg���

12.52.9 recon��

��recon.gc_interval������duration

12.52.10 reloader��

��reloader.interval������duration

236 Chapter 12. ���� (Changes)

EMQ X - ����� MQTT �����, �� 3.1.0

12.53 2.0.7 ��

����: 2017-01-20

The Last Maintenance Release for EMQ 2.0, and support to build RPM/DEB Packages.

emq-auth-http#9: Update the priv/emq_auth_http.schema, cuttlefish:unset() if no super_req/acl_req con-fig exists

emq-auth-mongo#31: cuttlefish:unset() if no ACL/super config exists

emq-dashboard#91: Fix the exception caused by binary payload

emq-relx#21: Improve the binemqttd.cmd batch script for windows

emqttd#873: Documentation: installing-from-source

emqttd#870: Documentation: The word in Documents is wrong

emqttd#864: Hook ‘client.unsubscribe’ need to handle ‘stop’

emqttd#856: Support variables in etc/emq.conf: {{ runner_etc_dir }}, {{ runner_etc_dir }}, {{ run-ner_data_dir }}

12.54 2.0.6 ��

����: 2017-01-08

Upgrade the esockd library to v4.1.1

esockd#41: Fast close the TCP socket if ssl:ssl_accept failed

emq-relx#15: The EMQ 2.0 broker cannot run on Windows.

emq-auth-mongo#31: Mongodb ACL Cannot work?

12.55 2.0.5 ��

����: 2016-12-24

emq-auth-http#9: Disable ACL support

emq-auth-mongo#29: Disable ACL support

emq-auth-mongo#30: {datatype, flag}

12.56 2.0.4 ��

����: 2016-12-16

emqttd#822: Test cases for SSL connections

emqttd#818: trap_exit to link WebSocket process

emqttd#799: Can’t publish via HTTPS

12.53. 2.0.7 �� 237

EMQ X - ����� MQTT �����, �� 3.1.0

12.57 2.0.3 ��

����: 2016-12-12

emqttd#796: Unable to forbidden tcp lisener

emqttd#814: Cannot remove a ‘DOWN’ node from the cluster

emqttd#813: Change parameters order

emqttd#795: Fix metrics of websocket connections

emq-dashboard#88: Rename the default topic from “/World” to “world”

emq-dashboard#86: Lookup all online clients

emq-dashboard#85: Comment the default listener port

emq-mod-retainer#3: Retained messages get lost after EMQTT broker restart.

12.58 2.0.2 ��

����: 2016-12-05

emqttd#787: Stop plugins before the broker stopped, clean routes when a node down

emqttd#790: Unable to start emqttd service if username/password contains special characters

emq-auth-clientid#4: Improve the configuration of emq_auth_clientid.conf to resolve emqttd#790

emq-auth-username#4: Improve the configuration of emq_auth_username.conf to resolve emqttd#790

12.59 2.0.1 ��

����: 2016-11-30

emqttd#781: ����README�2.0��

emq_dashboard#84: ��������

emq_dashboard#79: ������disc_copies��mqtt_admin�

emq_auth_clientid: ������disc_copies��mqtt_auth_clientid�

emq_auth_username: ������disc_copies��mqtt_auth_username�

emq_mod_subscription#3: ��emq_mod_subscription��module.subscription.backend��

emq_plugin_template#5: ���������/ACL��

12.60 2.0 ��� “����”

����: 2016-11-24

����: ����(West of West Lake)

EMQ-2.0�������EMQ-1.0����������900K�����EMQ-2.0����������������������:

1. ������(Shared Subscription)�����(Local Subscription)���MQTT�����������

238 Chapter 12. ���� (Changes)

EMQ X - ����� MQTT �����, �� 3.1.0

2. ��CoAP(RFC 7252)�MQTT-SN��������CoAP�MQTT-SN����MQTT������

3. ���������������������’K = V’����������������

4. ��������������������������NoSQL������

5. ����������Linux/Unix/Windows��ARM�������Docker�����

12.60.1 ����(Shared Subscription)

����(Shared Subscription)����������������������:

---------| | --Msg1--> Subscriber1

Publisher--Msg1,Msg2,Msg3-->| EMQ | --Msg2--> Subscriber2| | --Msg3--> Subscriber3---------

����: ������(Topic)���’$queue’�’$share/<group>/’���

12.60.2 ����(Local Subscription)

����(Local Subscription)�������������������������������������������

����: ������(Topic)���’$local/’���

12.60.3 erlang.mk�relx

2.0���� emqttd �������� emq-relx, �� erlang.mk � relx ��������1.x�����rebar���������Linux/Unix/Windows������

12.60.4 CoAP����

2.0����CoAP��(RFC7252)���CoAP���MQTT������

CoAP��: https://github.com/emqtt/emq_coap

12.60.5 MQTT-SN����

2.0����MQTT-SN�����MQTT-SN���MQTT������

MQTT-SN��: https://github.com/emqtt/emq_sn

12.60.6 ‘K = V’������

2.0���������’K = V’������etc/emq.conf:

node.name = [email protected]

...

mqtt.listener.tcp = 1883(����)

12.60. 2.0 ��� “����” 239

EMQ X - ����� MQTT �����, �� 3.1.0

(���)

...

12.60.7 ��������

2.0������������������������EMQ�������Cookie��TCP���:

[email protected]_NODE_COOKIE=emq_dist_cookieEMQ_MAX_PORTS=65536EMQ_TCP_PORT=1883EMQ_SSL_PORT=8883EMQ_HTTP_PORT=8083EMQ_HTTPS_PORT=8084

12.60.8 Docker����

EMQ-2.0����Docker�����Dockerfile���: https://github.com/emqtt/emq_docker

12.60.9 Windows����

2.0������Windows��������������Windows����’emqttd_ctl’��������Windows�������

12.60.10 �����

#764: add mqtt.cache_acl option

#667: Configuring emqttd from environment variables

#722: mqtt/superuser calls two times emqtt_auth_http

#754: “-heart” option for EMQ 2.0

#741: emq_auth_redis cannot use hostname as server address

12.60.11 ����

2.0��������������:

240 Chapter 12. ���� (Changes)

EMQ X - ����� MQTT �����, �� 3.1.0

�� ��emq_dashboard Web�����(����)emq_auth_clientid ClientId����emq_auth_username ����������emq_auth_ldap LDAP��/����emq_auth_http HTTP��/����emq_auth_mysql MySQL��/����emq_auth_pgsql PostgreSQL��/����emq_auth_redis Redis��/����emq_auth_mongo MongoDB��/����emq_mod_rewrite ����(Topic)��emq_mod_retainer Retain������emq_mod_presence ������������emq_mod_subscription �����������emq_coap CoAP����emq_sn MQTT-SN����emq_stomp Stomp����emq_sockjs Stomp over SockJS����emq_recon Recon����emq_reloader Reloader�������emq_plugin_template ������

12.61 2.0-rc.3 ��

12.62 2.0-rc.3 ��

����: 2016-11-01

1. �Presence�Retainer�Subscription������������:

emq_mod_retainer Retain������emq_mod_presence ������������emq_mod_subscription �����������

2. ��EMQ������SSL�����SSL����������

3. Bugfix: Fixed a typo (#716)

4. Bugfix: emqttd_http can not use emq_auth_http? #739

5. Bugfix: emq_auth_redis cannot use hostname as server address (#741)

6. ��Redis, MySQL, Postgre, MongoDB�������������

12.63 2.0-rc.2 ��

����: 2016-10-19

1. ��cuttlefish����’K = V’�����������EMQ���������:

12.61. 2.0-rc.3 �� 241

EMQ X - ����� MQTT �����, �� 3.1.0

node.name = [email protected]

...

mqtt.listener.tcp = 1883

...

2. ����������������������EMQ�����Cookie��TCP���:

EMQ_NODE_NAMEEMQ_NODE_COOKIEEMQ_MAX_PORTSEMQ_TCP_PORTEMQ_SSL_PORTEMQ_HTTP_PORTEMQ_HTTPS_PORT

3. �������ACL�������������������������

TODO: issues closed.

12.64 2.0-rc.1 ��

����: 2016-10-03

1. ������������������ACL�� (#696)

2. MQTT���������EMQ�������TCP�� (#707)

3. �����������������rel/sys.config��

4. ������Makefile�emqttd��:

BUILD_DEPS = emqttddep_emqttd = git https://github.com/emqtt/emqttd emq20

5. ����Redis���ACL����

12.65 2.0-beta.3 ��

����: 2016-09-18

12.65.1 ����(Shared Subscription)

Shared Suscriptions (#639, #416):

mosquitto_sub -t '$queue/topic'mosquitto_sub -t '$share/group/topic'

242 Chapter 12. ���� (Changes)

EMQ X - ����� MQTT �����, �� 3.1.0

12.65.2 ����(Local Subscription)

Local Subscriptions that will not create global routes:

mosquitto_sub -t '$local/topic'

12.65.3 ����

Error on Loading emqttd_auth_http (#691)

Remove ‘emqttd’ application from dependencies (emqttd_coap PR#3)

12.66 2.0-beta.2 ��

����: 2016-09-10

12.66.1 CoAP����

CoAP������(Beta): https://github.com/emqtt/emqttd_coap

12.66.2 API Breaking Changes

‘$u’, ‘$c’ variables in emqttd.conf and modules/acl.conf changed to ‘%u’, ‘%c’

Improve the design of mqtt retained message, replace emqttd_retainer with emqttd_mod_retainer.

Add ‘session.subscribed’, ‘session.unsubscribed’ hooks, remove ‘client.subscribe.after’ hook

Tab ‘retained_message’ -> ‘mqtt_retained’

12.66.3 Bugfix

[2.0 beta1] FORMAT ERROR: “~s PUBLISH to ~s: ~p” (PR #671)

Fixing issues in cluster mode. (PR #681)

Fixing issues with unsubscribe hook (PR #673)

12.67 2.0-beta.1 ��

����: 2016-08-30

����: ����(West of West Lake)

EMQ 2.0-beta1����(Preview Release)���EMQ 2.0���������������Git����������������EMQ��������������

��: 1.x�����������������2.0���������API���

12.66. 2.0-beta.2 �� 243

EMQ X - ����� MQTT �����, �� 3.1.0

12.67.1 ���� - EMQ

�������EMQ(Erlang/Enterprise/Elastic MQTT Broker)�E��Erlang/OTP�����(Enterprise)���(Elastic)�

12.67.2 ������

2.0 ��������(Preview Release) + ����(Release Candidate)���������2.0�������beta1, beta2, beta3, rc1, rc2������2.0�������

12.67.3 �����

2.0 ��� emqttd �������������������(rel)�����: emqttd_relx ����1.0�����(plugins)�emqttd���������

�����clone emqttd_relx:

git clone https://github.com/emqtt/emqttd-relx.git

cd emqttd-relx && make

cd _rel/emqttd && ./bin/emqttd console

12.67.4 erlang.mk�relx

2.0 ������ emqttd_relx �� erlang.mk � relx ��������1.x�����rebar���: https://erlang.mk/guide/why.html

12.67.5 Git����

stable 1.x ������master 2.x �����emq10 1.x ������emq20 2.x ������emq30 3.x ������issue#{id} Issue����

etc/emqttd.conf���� ———=————-

2.0 ���������������rebar.config�relx.config���������������������

etc/emqttd.conf����:

%% Max ClientId Length Allowed.{mqtt_max_clientid_len, 512}.

%% Max Packet Size Allowed, 64K by default.{mqtt_max_packet_size, 65536}.

%% Client Idle Timeout.{mqtt_client_idle_timeout, 30}. % Second

244 Chapter 12. ���� (Changes)

EMQ X - ����� MQTT �����, �� 3.1.0

12.67.6 MQTT-SN����

2.0-beta1������ emqttd_sn ����MQTT-SN�����������emqttd_sn���MQTT-SN��UDP��: 1884:

./bin/emqttd_ctl plugins load emqttd_sn

12.67.7 ������

2.0 ���emqttd����plugins/������������Erlang�������(deps)������lib��������������etc/plugins/���:

� emqttd-relx/� etc/� modules/� plugins/

emqtt_coap.confemqttd.confemqttd_auth_http.confemqttd_auth_mongo.confemqttd_auth_mysql.confemqttd_auth_pgsql.confemqttd_auth_redis.confemqttd_coap.confemqttd_dashboard.confemqttd_plugin_template.confemqttd_recon.confemqttd_reloader.confemqttd_sn.confemqttd_stomp.conf

12.67.8 2.0 ������

2.0 ������: http://emqtt.com/docs/v2/index.html � http://docs.emqtt.cn/zh_CN/emq20

2.0 ������: https://developer.emqx.io/docs/emq/v2/en/index.html � http://docs.emqtt.com/

12.67.9 ������

12.67. 2.0-beta.1 �� 245

EMQ X - ����� MQTT �����, �� 3.1.0

12.68 1.1.3 ��

����: 2016-08-19

Support ‘./bin/emqttd_ctl users list’ CLI (#621)

Cannot publish payloads with a size of the order 64K using WebSockets (#643)

Optimize the procedures that retrieve the Broker version and Borker description in the tick timer (PR#627)

Fix SSL certfile, keyfile config (#651)

12.69 1.1.2 ��

����: 2016-06-30

Upgrade mysql-otp driver to 1.2.0 (#564, #523, #586, #596)

Fix WebSocket Client Leak (PR #612)

java.io.EOFException using paho java client (#551)

Send message from paho java client to javascript client (#552)

Compatible with the Qos0 PUBREL packet (#575)

Empty clientId with non-clean session accepted (#599)

Update docs to fix typos (#601, #607)

12.70 1.1.1 ��

����: 2016-06-04

Compatible with the Qos0 PUBREL packet (#575)

phpMqtt Client Compatibility (#572)

java.io.EOFException using paho java client (#551)

12.71 1.1 ��

����: 2016-06-01

1.1����eSockd��4.0���IPv6�����IP�����MongoDB�����HTTP�����Reloader�����MySQL�PostgreSQL�Redis��������������SQL����������(superuser)���

12.71.1 �����

Allow human-friendly IP addresses (PR#395)

File operation error: emfile (#445)

emqttd_plugin_mongo not found in emqttd (#489)

emqttd_plugin_mongo Error While Loading in emqttd (#505)

Feature request: HTTP Authentication (#541)

246 Chapter 12. ���� (Changes)

EMQ X - ����� MQTT �����, �� 3.1.0

Compatible with the Qos0 PUBREL packet (#575)

Bugfix: function_clause exception occurs when registering a duplicated authentication module (#542)

Bugfix: ./emqttd_top msg_q result: {“init terminating in do_boot”,{undef,[{etop,start,[],[]},{init,start_it,1,[]},{init,start_em,1,[]}]}}(#557)

12.71.2 Dashboard��

WebSocket������Clean Session, Qos, Retained���� (emqttd_dashboard#52)

��eSockd��4.0���Overview����OTP�� (emqttd_dashboard#61)

Changing dashboard credentials for username authentication (emqttd_dashboard#56)

��’./bin/emqttd_ctl admins’����������������admin��

12.71.3 HTTP����

����HTTP API��/��MQTT���: https://github.com/emqtt/emqttd_auth_http

12.71.4 MongoDB����

��Erlang Mongodb���v1.0.0 (emqttd_plugin_mongo#1)

��������

����MongoDB�ACL (emqttd_plugin_mongo#3)

12.71.5 MySQL����

��������

���������SQL��

12.71.6 Postgre����

��������

���������SQL��

12.71.7 Redis����

��������

��ClientId��/ACL (emqttd_plugin_redis#4)

12.71.8 Reloader��

�����������: https://github.com/emqtt/emqttd_reloader

12.71. 1.1 �� 247

EMQ X - ����� MQTT �����, �� 3.1.0

12.72 1.0.2 ��

����: 2016-05-04

Issue#534 - ‘./bin/emqttd_ctl vm’ - add ‘port/count’, ‘port/limit’ statistics

Issue#535 - emqttd_client should be terminated properly even if exception happened when sending data

PR#519 - The erlang ‘-name’ requires the fully qualified host name

emqttd_reloader plugin - help reload modified modules during development.

12.73 1.0.1 ��

����: 2016-04-16

PR#515 - Fix ‘$queue’ pubsub, add ‘pubsub_queue’ test and update docs

12.74 1.0 (���) ��

����: 2016-04-13

����: ���(The Seven Mile Journey)

���������������������1.0(���)���������������

1.0�����������: ����������������������MQTT��������������������MQTT�����

1. ����MQTT V3.1.1�������WebSocket�Stomp���TCP�����

2. ����������MQTT��������������50��100����

3. ���������������������������1000�������

4. �������������������������������������

12.74.1 �����

1.0���������������0.17.1��������:

Possible race condition using emqttd_cm (#486)

Improve the design of retained message expiration (#503)

Should not expire the retained messages from $SYS/# topics (#500)

12.74.2 ����

1.0 ������: http://emqtt.com/docs/ � http://docs.emqtt.cn

1.0 ������: https://developer.emqx.io/docs/emq/v1/en/index.html � http://docs.emqtt.com/

248 Chapter 12. ���� (Changes)

EMQ X - ����� MQTT �����, �� 3.1.0

12.74.3 ����

����: http://emqtt.com

����: https://www.emqx.io/

12.74.4 ��

����Erlang/OTP������(http://www.erlang.org/)!

���(GitHub��): @callbay @lsxredrain @hejin1026 @desoulter @turtleDeng @Hades32 @huangdan @phanima-hesh @dvliman @Prots @joaohf

��: ���������������������������������

��: ���(The Seven Mile Journey)�����������

12.75 0.17.1-beta ��

����: 2016-03-22

12.75.1 Enhancements

Time unit of session ‘expired_after’ changed to minute. (#479)

12.75.2 Dashboard

Code Review and improve the design of Dashboard.

12.76 0.17.0-beta ��

����: 2016-03-15

12.76.1 Highlights

Installation and Configuration Guide released on http://docs.emqtt.com

Improve and Consolidate the design of Hook, Server, PubSub and Router

Upgrade the [Web Dashboard](https://github.com/emqtt/emqttd_dashboard) to support pagination

Bridge emqttd broker to another emqttd broker & emqttd to mosquitto bridge (#438)

12.76.2 Enhancements

emqttd_ctl: better error message (#450)

./bin/emqttd_ctl: add ‘routes’ command

` routes list # List all routes routes show <Topic> # Show a route `

12.75. 0.17.1-beta �� 249

EMQ X - ����� MQTT �����, �� 3.1.0

Add ‘backend_subscription’ table and support static subscriptions (emqttd_backend)

Add ‘retained_message’ table and refactor emqttd_retainer module (emqttd_backend)

A New Hook and Callback Design (emqttd_hook)

Add PubSub, Hooks APIs to emqttd module (emqttd)

Move start_listeners/0, stop_listeners/0 APIs to emqttd_app module (emqttd_app)

12.76.3 Tests

Add 100+ common test cases.

12.76.4 Plugins

Upgrade Dashboard, Redis, Stomp and Template Plugins

12.77 0.16.0-beta ��

����: 2016-02-16

12.77.1 Highlights

Licensed under the Apache License, Version 2.0 Now.

Improve the design of cluster, support to join or leave the cluster (#449):

` $ ./bin/emqttd_ctl cluster cluster join <Node> #Join the cluster cluster leave #Leavethe cluster cluster remove <Node> #Remove the node from cluster cluster status #Clusterstatus `

Improve the design of Trie and Route, only the wildcard topics stored in Trie.

Common Test to replace EUnit.

12.77.2 Enhancements

mqtt_message record: add ‘sender’ field (#440)

refactor the emqttd, emqttd_time, emqttd_opts, emqttd_node modules.

12.77.3 Bugfix

noproc error when call to gen_server2:call(false, {add_route,Topic,<0.685.0>}, infinity) (#446)

#### Plugins

Changed the license of all plugins.

250 Chapter 12. ���� (Changes)

EMQ X - ����� MQTT �����, �� 3.1.0

12.78 0.15.0-beta ��

����: 2016-01-31

12.78.1 Highlights

Optimize for Push Application, 500K+ Subscribers to a Topic.

Optimization for Route ETS insertion (#427)

Priority Message Queue for Persistent Session (#432)

Add Redis, MongoDB Plugins (#417)

12.78.2 Enhancements

Username/Password Authentication: Support to configure default users (#428)

Improve CLI Commands: pubsub, bridges, trace (#429)

emqttd_mod_subscription: fix client_connected/3

emqttd_auth_mod: add passwd_hash/2 function

priority_queue: add plen/2, out/2 functions

12.78.3 Bugfix

Fix dequeue/1 of emqttd_bridge…

Add emqttd:seed_now/0 function

12.78.4 Plugins

emqttd_plubin_mysql: Changed mysql driver to mysql-otp

emqttd_plugin_pgsql: Integrate with ecpool

emqttd_plugin_redis: First release

emqttd_plugin_mongo: First release

12.79 0.14.1-beta ��

����: 2015-12-28

Bugfix: emqttd_ws_client.erl: Unexpected Info: {‘EXIT’,<0.27792.18>,{shutdown,destroy}} (#413)

Improve: fix spec errors found by dialyzer

12.80 0.14.0-beta ��

����: 2015-12-18

12.78. 0.15.0-beta �� 251

EMQ X - ����� MQTT �����, �� 3.1.0

12.80.1 Highlights

Scaling to 1.3 Million Concurrent MQTT Connections on a 12 Core, 32G CentOS server.

New PubSub, Router Design (#402). Prepare for scaling to 10 millions on one cluster.

12.80.2 Enhancements

Improve the gproc_pool usage with a general emqttd_pool_sup

Improve the design of emqttd_pubsub, add a new emqttd_router module

Improve the design of the whole supervisor tree

Route aging mechanism to remove the topics that have no subscriptions

Improve the dashboard, mysql, pgsql, stomp, sockjs plugins

Add ‘topics’, ‘subscriptions’ admin commands

Avoid using mnesia table index and mnesia:index_read API to lower CPU usage

Subscribe timeout exception (#366)

Long Delay on Multiple Topic Subscription (#365)

Subscriptions persistence (#344)

emqttd_ctl: ‘subscriptions’ command to force clients to subscribe some topics (#361)

12.80.3 Bugfix

emqttd_sm: spec of lookup_session/1 is not right BUG (#411)

Observer application should be removed from reltool.config for ‘wx’ app is not available (#410)

12.80.4 Benchmark

1.3 million concurrent MQTT connections on a 12 Core, 32G CentOS Server, consume about 15G Memoryand 200% CPU.

12.81 0.13.1-beta ��

����: 2015-11-28

Bugfix: Plugin pathes error under windows (#387)

Improve: Too many error logs “[error] Session ….. Unexpected EXIT: client_pid=<0.14137.35>,exit_pid=<0.30829.22>, reason=nop…” (#383)

Improve: Define QOS0/1/2, Pooler Error (PR#382)

Improve: High CPU load when 400K unstable mobile connections (#377)

BugFix: emqttd_plugin_pgsql - error using same query with latest update plugin (pgsql#5)

252 Chapter 12. ���� (Changes)

EMQ X - ����� MQTT �����, �� 3.1.0

12.82 0.13.0-beta ��

����: 2015-11-08

12.82.1 Highlights

Rate Limiting based on [Token Bucket](https://en.wikipedia.org/wiki/Token_bucket) and [LeakyBucket](https://en.wikipedia.org/wiki/Leaky_bucket#The_Leaky_Bucket_Algorithm_as_a_Meter) Al-gorithm

Upgrade eSockd and MochiWeb libraries to support Parameterized Connection Module

Improve emqttd_client to support fully asynchronous socket networking

12.82.2 Enhancements

Protocol Compliant - Session Present Flag (#163)

Compilation fails if repo is cloned with a different name (#348)

emqttd_client: replace gen_tcp:send with port_command (#358)

TCP sndbuf, recbuf, buffer tuning (#359)

emqttd_client.erl to handle ‘inet_async’, ‘inet_reply’ properly (#360)

Refator the [client/session management design](https://github.com/emqtt/emqttd/blob/master/doc/design/ClientSession.md)

12.82.3 Bugfix

Cannot kick transient client out when clientId collision (#357)

Fix the order of emqttd_app:start_server/1 (#367)

emqttd_session:subscribe/2 will crash (#374)

12.82.4 Benchmark

[benchmark for 0.13.0 release](https://github.com/emqtt/emqttd/wiki/benchmark-for-0.13.0-release)

3.1G memory and 50+ CPU/core:

Connections: 250KSubscribers: 250KTopics: 50KQos1 Messages/Sec In: 4KQos1 Messages/Sec Out: 20KTraffic In(bps): 12M+Traffic Out(bps): 56M+

12.82. 0.13.0-beta �� 253

EMQ X - ����� MQTT �����, �� 3.1.0

12.83 0.12.3-beta ��

����: 2015-10-22

Bugfix: emqttd_sysmon crasher for ‘undefined’ process_info (#350)

Bugfix: emqttd_client: catch parser exception (#353)

12.84 0.12.2-beta ��

����: 2015-10-16

Bugfix: Retained messages should not be expired if ‘broker.retained.expired_after = 0’ (#346)

12.85 0.12.1-beta ��

����: 2015-10-15

Highlight: Release for Bugfix and Code Refactor.

Feature: Retained message expiration (#182)

Improve: ‘$SYS/#’ publish will not match ‘#’ or ‘+/#’ (#68)

Improve: Add more metrics and ignore ‘$SYS/#’ publish (#266)

Improve: emqttd_sm should be optimized for clustered nodes may be crashed (#282)

Improve: Refactor emqttd_sysmon and suppress ‘monitor’ messages (#328)

Task: benchmark for 0.12.0 release (#225)

Benchmark: About 900K concurrent connections established on a 20Core, 32G CentOS server.

12.86 0.12.0-beta ��

����: 2015-10-08

12.86.1 Highlights

Enhance the emqttd_ctl module to allow plugins to register new commands (#256)

Add [emqttd_recon plugin](https://github.com/emqtt/emqttd_recon) to debug/optimize the broker (#235)

Add ‘./bin/emqttd_ctl broker pubsub’ command to check the status of core pubsub processes

Add ‘./bin/emqttd_top’ command(like etop) to show the top ‘msg_q’, ‘reductions’, ‘memory’ or ‘runtime’processes

‘rel/files/emqttd.config.production’ for production deployment(default)

‘rel/files/emqttd.config.development’ for development deployment

254 Chapter 12. ���� (Changes)

EMQ X - ����� MQTT �����, �� 3.1.0

12.86.2 Enhancements

Qos1/2 messages will not be dropped under unstable mobile network (#264)

emqttd_session:subscribe/2, emqttd_session:unsubscribe/2 APIs should be asynchronous (#292)

etc/emqttd.config: ‘idle_timeout’ option to close the idle client(socket connected but no ‘CONNECT’frame received)

etc/emqttd.config: ‘unack_retry_interval’ option for redelivering Qos1/2 messages

How to monitor large ‘message_queue_len’ (#283)

12.86.3 Bugfix

Behaviour emqttd_auth_mod is missing init callback (#318)

12.86.4 Benchmark

Write a new [benchmark tool](https://github.com/emqtt/emqtt_benchmark) to benchmark this release

Hw requirements - 5K users, 25-50 msgs/sec, QoS=1 (#209)

Supported Number of Connections Greatly Reduced When Clients are Subscribing (#324)

12.87 0.11.0-beta ��

����: 2015-09-25

Highlight: Rebar to manage plugin dependencies.

Highlight: [Stomp](https://github.com/emqtt/emqttd_stomp) and [SockJS](https://github.com/emqtt/emqttd_sockjs) Plugins!

Improve: add rel/files/emqttd.config.development|production.

Improve: rel/reltool.config.script to release deps of plugin.

Improve: persist mnesia schema on slave nodes.

Improve: use timer:seconds/1 api.

Improve: The binary release will be compiled with R18.1 now.

Bugfix: issue#306 - emqttd_cm should unregister the duplicated client

Bugfix: issue#310 - usage of emqttd_ctl error: ‘session list’ should be ‘sessions list’

Bugfix: issue#311 - ‘./bin/emqttd_ctl sessions list’ error

Bugfix: issue#312 - unsubcribe will lead to crash if emqttd_plugin_template plugin loaded

12.88 0.10.4-beta ��

����: 2015-09-18

Optimize session management and upgrade eSockd library to 2.7.1

12.87. 0.11.0-beta �� 255

EMQ X - ����� MQTT �����, �� 3.1.0

[Benchmark for 0.10.4 release](https://github.com/emqtt/emqttd/wiki/benchmark-for-0.10.4-release)

Improve: issue#294 - [error] failed to start connection on 0.0.0.0:1883 - enotconn

Improve: issue#297 - How do I allow user with some pattern to access topic with some pattern?

Bugfix: issue#291 - “./bin/emqttd attach …” cannot work

Bugfix: issue#284 - Should not use erlang:list_to_atom/1 in emqttd_vm.erl

12.89 0.10.3-beta ��

����: 2015-08-30

Bugfix: issue#271 - add emqttd_ws_client:subscribe/2 function

Bugfix: issue#269 - bin/emqttd Syntax error on ubuntu

Improve: issue#265 - client under unstable mobile network generate a lot of logs

12.90 0.10.2-beta ��

����: 2015-08-26

Improve: issue#257 - After the node name changed, the broker cannot restart for mnesia schema error.

12.91 0.10.1-beta ��

����: 2015-08-25

Bugfix: issue#259 - when clustered the emqttd_dashboard port is close, and the ‘emqttd’ application cannotstop normally.

Feature: issue#262 - Add ‘http://host:8083/mqtt/status’ Page for health check

12.92 0.10.0-beta ��

����: 2015-08-20

[Web Dashboard](https://github.com/emqtt/emqttd_dashboard) and [MySQL](https://github.com/emqtt/emqttd_plugin_mysql), [PostgreSQL](https://github.com/emqtt/emqttd_plugin_pgsql) Authenti-cation/ACL Plugins!

Highlight: Web Dashboard to monitor Statistics, Metrics, Clients, Sessions and Topics of the broker.

Highlight: JSON/HTTP API to query all clients connected to broker.

Highlight: A new [Plugin Design](https://github.com/emqtt/emqttd/wiki/Plugin%20Design) and a [Tem-plate project](https://github.com/emqtt/emqttd_plugin_template) for plugin development.

Highlight: Authentication/ACL with MySQL, PostreSQl databases (#194, #172)

Feature: Session Statistics including inflight_queue, message_queue, message_dropped, awaiting_rel,awaiting_ack, awaiting_comp (#213)

Feature: Cookie based authentication for MQTT over websocket connections (#231)

256 Chapter 12. ���� (Changes)

EMQ X - ����� MQTT �����, �� 3.1.0

Feature: Get all clients connected to the broker (#228, #230, #148, #129)

Feature: “./bin/emqttd_ctl clients show ClientId” to query client status (#226)

Feature: “./bin/emqttd_ctl clients kick ClientId” to kick out a client

Feature: “./bin/emqttd_ctl sessions list” to show all sessions

Feature: “./bin/emqttd_ctl sessions show ClientId” to show a session

Feature: Erlang VM metrics monitor with Web Dashboard (#59)

Improve: Too many “inflight queue is full!” log when session is overloaded (#247)

Improve: There are two many “MQueue(~s) drop ~s” logs if the message queue of session is small (#244)

Improve: gen_server2(from RabbitMQ) to improve emqttd_session, emqttd_pubsub

Improve: Makefile to build plugins

Bugfix: emqttd_broker:unhook/2 cannot work (#238)

Bugfix: emqttd plugin cannot include_lib(“emqttd/include/emqttd.hrl”) (#233)

Bugfix: Too many ‘Session ~s cannot find PUBACK’ logs (#212)

Bugfix: emqttd_pooler cannot work

12.93 0.9.3-alpha ��

����: 2015-07-25

Wiki: [Bridge](https://github.com/emqtt/emqttd/wiki/Bridge)

Improve: emqttd_protocol.hrl to define ‘QOS_I’

Improve: emqttd_pubsub to add subscribe/2 API

Improve: ./bin/emqttd_ctl to support new bridges command

Bugfix: issue #206 - Cannot bridge two nodes

12.94 0.9.2-alpha ��

����: 2015-07-18

Improve: issue #196 - Add New Hook ‘client.subscribe.after’

12.95 0.9.1-alpha ��

����: 2015-07-10

Bugfix: issue #189 - MQTT over WebSocket(SSL) cannot work?

Bugfix: issue #193 - ‘client.ack’ hook should be renamed to ‘message.acked’, and called byemqttd_broker:foreach_hooks

12.93. 0.9.3-alpha �� 257

EMQ X - ����� MQTT �����, �� 3.1.0

12.96 0.9.0-alpha ��

����: 2015-07-09

[Session, Queue, Inflight Window, Hooks, Global MessageId and More Protocol Compliant](https://github.com/emqtt/emqttd/releases/tag/0.9.0-alpha) Now!

Feature: Session/Queue/Inflight Window Design (#145).

Feature: Support to resume a persistent session on other clustered node.

Feature: Support alarm management.

Feature: emqttd_guid to generate global unique message id.

Feature: Hooks for message pub/ack.

Feature: Protocol compliant - message ordering, timeout and retry.

Improve: Every client will start_link a session process, whether or not the client is persistent.

Improve: etc/emqttd.config to support more session, queue configuration.

Improve: issue #179 - Max offline message queue {max_queue, 100} meaning.

Improve: issue #180 - Should change project structure for other projects maybe depend on ‘emqttd’. Mergeemqtt, emqttd apps.

Improve: issue #185 - PacketId and MessageId: the broker should generate global unique message id.

Improve: issue #187 - etc/emqttd.config to support https listener

Improve: issue #186 - emqttd_cm to store client details

Improve: issue #174 - add ‘from’ field to mqtt_message record.

Improve: issue #170 - $SYS Topics should support alarms.

Improve: issue #169 - Add More [Hooks](https://github.com/emqtt/emqttd/wiki/Hooks-Design)

Improve: issue #167 - Inflight window to assure message ordering.

Improve: issue #166 - Message delivery timeout and retry.

Improve: issue #143 - Qos1, Qos2 PubSub message timeout.

Improve: issue #122 - Labeling message with unique id. emqttd_guid module to generate global uniquemsgid.

Improve: emqttd_bridge to support pending message queue, and fix the wrong Qos design.

Improve: mqtt_message record to add ‘msgid’, ‘from’ and ‘sys’ fields.

Change: Add emqttd_mqueue, emqttd_guid, emqttd_alarm modules.

Bugfix: issue #184 - emqttd_stats:setstats is not right.

Bugfix: Closed issues #181, #119.

Tests: fix the parser, acl test cases.

12.97 0.8.6-beta ��

����: 2015-06-17

Bugfix: issue #175 - publish Will message when websocket is closed without ‘DISCONNECT’ packet

258 Chapter 12. ���� (Changes)

EMQ X - ����� MQTT �����, �� 3.1.0

12.98 0.8.5-beta ��

����: 2015-06-10

Bugfix: issue #53 - client will receive duplicate messages when overlapping subscription

12.99 0.8.4-beta ��

����: 2015-06-08

Bugfix: issue #165 - duplicated message when publish ‘retained’ message to persistent client

12.100 0.8.3-beta ��

����: 2015-06-05

Bugfix: issue #158 - should queue:in new message after old one dropped

Bugfix: issue #155 - emqtt_parser.erl: parse_topics/3 should reverse topics

Bugfix: issue #149 - Forget to merge plugins/emqttd_auth_mysql from ‘dev’ branch to ‘master’ in 0.8.xrelease

12.101 0.8.2-alpha ��

����: 2015-06-01

Bugfix: issue #147 - WebSocket client cannot subscribe queue ‘$Q/queue/${clientId}’

Bugfix: issue #146 - emqttd_auth_ldap: fill(Username, UserDn) is not right

12.102 0.8.1-alpha ��

����: 2015-05-28

Client [Presence](https://github.com/emqtt/emqttd/wiki/Presence) Support and [$SYS Topics](https://github.com/emqtt/emqttd/wiki/\protect\TU\textdollarSYS-Topics) Redesigned!

Bugfix: issue #138 - when client disconnected normally, broker will not publish disconnected $SYS message

Bugfix: fix websocket url in emqttd/priv/www/websocket.html

Improve: etc/emqttd.config to allow websocket connections from any hosts

Improve: rel/reltool.config to exclude unnecessary apps.

12.103 0.8.0-alpha ��

����: 2015-05-25

[Hooks](https://github.com/emqtt/emqttd/wiki/Hooks%20Design), Modules and [Plugins](https://github.com/emqtt/emqttd/wiki/Plugin%20Design) to extend the broker Now!

12.98. 0.8.5-beta �� 259

EMQ X - ����� MQTT �����, �� 3.1.0

Plugin: emqttd_auth_mysql - MySQL authentication plugin (issues #116, #120)

Plugin: emqttd_auth_ldap - LDAP authentication plugin

Feature: emqttd_broker to support Hooks API

Feature: issue #111 - Support ‘Forced Subscriptions’ by emqttd_mod_autosub module

Feature: issue #126 - Support ‘Rewrite rules’ by emqttd_mod_rewrite module

Improve: Support hooks, modules to extend the broker

Improve: issue #76 - dialyzer check

Improve: ‘Get Started’, ‘User Guide’, ‘Developer Guide’ Wiki

Improve: emqtt_topic to add join/1, feed_var/3, is_queue/1

Improve: emqttd_pooler to execute common tasks

Improve: add emqttd_sm_sup module, and use ‘hash’ gproc_pool to manage sessions

Tests: add more test cases for ‘emqttd’ app

12.104 0.7.1-alpha ��

����: 2015-05-04

Add doc/design/* and merge doc/* to github Wiki

Bugfix: issue #121 - emqttd cluster issuse

Bugfix: issue #123 - emqttd:unload_all_plugins/0 cannot unload any plugin

Bugfix: fix errors found by dialyzer

12.105 0.7.0-alpha ��

����: 2015-05-02

[MQTT over WebSocket(SSL)](https://github.com/emqtt/emqttd/wiki/MQTT-Over-WebSocket) Now!

[Plugin Achitecture](https://github.com/emqtt/emqttd/wiki/Plugin%20Design) based on OTP application

[Trace MQTT Packets or Messages](https://github.com/emqtt/emqttd/wiki/Trace%20Design) to log files

Feature: issue #40, #115 - WebSocket/SSL Support

Feature: issue #49, #105 - Plugin Architecture Support

Feature: issue #93 - Trace API Design

Improve: issue #109 - emqttd_broker should add subscribe, notify API

Improve: update README.md to add ‘Goals’, ‘Contributors’ chapters

Change: rename etc/app.config to etc/emqttd.config

Change: etc/emqttd.config changed

Bugfix: critical issue #54 - error when resume session!

Bugfix: issue #118 - error report when UNSUBSCRIBE with no topics

Bugfix: issue #117 - sys_interval = 0 config cannot work

260 Chapter 12. ���� (Changes)

EMQ X - ����� MQTT �����, �� 3.1.0

Bugfix: issue #112 - Makefile to support build plugins

Bugfix: issue #96 - “make clean” cannot work

12.106 0.6.2-alpha ��

����: 2015-04-24

Bugfix: critical issue #54, #104, #106 - error when resume session

Improve: add emqttd_cm_sup module, and use ‘hash’ gproc_pool to register/unregister client ids

Improve: kick old client out when session is duplicated.

Improve: move mnesia dir config from etc/app.config to etc/vm.args

12.107 0.6.1-alpha ��

����: 2015-04-20

Integrate with [gproc library](https://github.com/uwiger/gproc) to support pool

Feature: issues#91 - should use worker_pool to handle some async work?

Feature: issues#95 - Topic filters in ACL rule should support ‘eq’ tag

Improve: issues#84 - emqttd_pubsub is redesigned again to protect mnesia transaction

Improve: issues#74 - ACL Support and update [ACL Design Wiki](https://github.com/emqtt/emqttd/wiki/ACL-Design)

12.108 0.6.0-alpha ��

����: 2015-04-17

ACL Support Now: [ACL-Design Wiki](https://github.com/emqtt/emqttd/wiki/ACL-Design)

Authentication with username, clientid Now: [Authentication Wiki](https://github.com/emqtt/emqttd/wiki/Authentication)

Seperate common MQTT library to ‘emqtt’ application

Redesign message pubsub, route and retain modules

Redesign mnesia database cluster

Feature: issues#47 - authentication, authorization support

Feature: issues#92 - merge emqttd_acl and emqttd_auth to emqttd_access_control

Feature: emqttd_acl_mod, emqttd_auth_mod behaviour to extend ACL, authentication

Feature: issues#85 - lager:info to log subscribe, unsubscribe actions

Feature: issues#77 - authentication with clientid, ipaddress

Improve: issues#90 - fix lager_file_backend log format, and rotate 10 log files

Improve: issues#88 - use ‘-mneisa_create’, ‘-mnesia_replicate’ attributes to init mneisa

12.106. 0.6.2-alpha �� 261

EMQ X - ����� MQTT �����, �� 3.1.0

Improve: issues#87 - record mqtt_user and mqtt_client is duplicated

Improve: issues#81 - redesign nodes cluster to support disc_copies mnesia tables

Improve: issues#80 - redesign emqttd_cm to handle more concurrent connections

Improve: issues#70 - how to handle connection flood? Now could support 2K+ CONNECT/sec

Change: redesign mnesia tables: message, topic, subscriber, trie, trie_node

Bugfix: issues#83 - emqttd_broker stats cannot work

Bugfix: issues#75 - careless about function name when emqttd_pubsub handle getstats message

12.109 0.5.5-beta ��

����: 2015-04-09

Bugfix: issue #75 - careless about function name when emqttd_pubsub handle getstats message.

Bugfix: issue #79 - cannot find topic_subscriber table after cluster with other nodes.

12.110 0.5.4-alpha ��

����: 2015-03-22

Benchmark this release on a ubuntu/14.04 server with 8 cores, 32G memory from QingCloud.com:

200K Connections,30K Messages/Sec,20Mbps In/Out Traffic,200K Topics,200K Subscribers,Consumed 7G memory, 40% CPU/core

Benchmark code: https://github.com/emqtt/emqttd_benchmark

Change: rewrite emqttd_pubsub to handle more concurrent subscribe requests.

Change: ./bin/emqttd_ctl add ‘stats’, ‘metrics’ commands.

Bugfix: issue #71, #72

12.111 0.5.3-alpha ��

����: 2015-03-19

Bugfix: issues#72 - emqttd_cm, emqtt_sm ets:match_delete/2 with wrong pattern

12.112 0.5.2-alpha ��

����: 2015-03-18

Change: upgrade esockd to 2.1.0-alpha, do not tune socket buffer for mqtt connection.

262 Chapter 12. ���� (Changes)

EMQ X - ����� MQTT �����, �� 3.1.0

12.113 0.5.1-alpha ��

����: 2015-03-13

Change: upgrade esockd to v1.2.0-beta, rename ‘acceptor_pool’ to ‘acceptors’

12.114 0.5.0-alpha ��

����: 2015-03-12

RENAME ‘emqtt’ to ‘emqttd’!

Support [Broker Bridge](https://github.com/emqtt/emqttd/wiki/Bridge-Design) Now!

Change: rename project from ‘emqtt’ to ‘emqttd’

Change: lager:debug to dump RECV/SENT packets

Feature: emqttd_bridge, emqttd_bridge_sup to support broker bridge

Feature: emqtt_event to publish client connected/disconnected message to $SYS topics

Feature: ./bin/emqttd_ctl add more commands: listeners, broker, bridges, start_bridge, stop_bridge…

Feature: issue#57 - support to configure max packet size

Feature: issue#68 - if sys_interval = 0, emqttd_broker will not publish messages to $SYS/brokers/#

Bugfix: issue#67 - subscribe ‘#’ to receive all messages

Bugfix: issue#64 - emqtt_app start/2: should wait_for_databases

Test: emqttd_topic_tests add more ‘_match_test’

12.115 0.4.0-alpha ��

����: 2015-03-10

Support [$SYS Topics of Broker](https://github.com/emqtt/emqttd/wiki/\protect\TU\textdollarSYS-Topics-of-Broker) Now!

Feature: emqtt_broker to publish version, uptime, datetime to $SYS/brokers/# topics

Feature: emqtt_broker to publish count of clients, sessions, suscribers to $SYS/brokers/# topics

Feature: emqtt_metrics to publish bytes, packets, messages metrics to $SYS/brokers/# topics

Feature: add include/emqtt_systop.hrl

Change: emqtt_cm to count current clients

Change: emqtt_sm to count current sessions

Change: emqtt_pubsub to count current topics and suscribers

Change: emqtt_pubsub to add create/1 API

Change: emqtt_pubsub dispatch/2 to return number of subscribers

Change: emqtt_pubsub to count ‘dropped’ messages

Change: emqtt_opts to add merge/2 function

12.113. 0.5.1-alpha �� 263

EMQ X - ����� MQTT �����, �� 3.1.0

Test: add emqtt_serialiser_tests.erl

12.116 0.3.4-beta ��

����: 2015-03-08

Bugfix: emqtt_serialiser.erl cannot serialise UNSUBACK packets

12.117 0.3.3-beta ��

����: 2015-03-07

Bugfix: emqtt_serialiser.erl cannot serialise PINGRESP issue#60

12.118 0.3.2-beta ��

����: 2015-03-05

Improve: merge emqttc serialiser, parser, packet

Add: emqtt_opts to merge socket options

12.119 0.3.1-beta ��

����: 2015-03-02

Feature: SSL Socket Support

Feature: issue#44 HTTP API should add Qos parameter

Bugfix: issue#52 emqtt_session crash

Bugfix: issue#53 sslsocket keepalive error

Upgrade: esockd to v0.2.0

Upgrade: mochiweb to v3.0.0

12.120 0.3.0-beta ��

����: 2015-01-19

Feature: HTTP POST API to support ‘qos’, ‘retain’ parameters

Feature: $SYS system topics support

Change: Rewrite emqtt_topic.erl, use ‘’, ‘#’, ‘+’ to replace <<”“>>, <<”#”>>, <<”+”>>

Change: fix emqtt_pubsub.erl to match ‘#’, ‘+’

Tests: emqtt_topic_tests.erl add more test cases

264 Chapter 12. ���� (Changes)

EMQ X - ����� MQTT �����, �� 3.1.0

12.121 0.3.0-alpha ��

����: 2015-01-08

NOTICE: Full MQTT 3.1.1 support now!

Feature: Passed org.eclipse.paho.mqtt.testing/interoperability tests

Feature: Qos0, Qos1 and Qos2 publish and suscribe

Feature: session(clean_sess=false) management and offline messages

Feature: redeliver awaiting puback/pubrec messages(doc: Chapter 4.4)

Feature: retain messages, add emqtt_server module

Feature: MQTT 3.1.1 null client_id support

Bugfix: keepalive timeout to send will message

Improve: overlapping subscription support

Improve: add emqtt_packet:dump to dump packets

Test: passed org.eclipse.paho.mqtt.testing/interoperability

Test: simple cluster test

Closed Issues: #22, #24, #27, #28, #29, #30, #31, #32, #33, #34, #36, #37, #38, #39, #41, #42, #43

12.122 0.2.1-beta ��

����: 2015-01-08

pull request 26: Use binaries for topic paths and fix wildcard topics

emqtt_pubsub.erl: fix wildcard topic match bug caused by binary topic in 0.2.0

Makefile: deps -> get-deps

rebar.config: fix mochiweb git url

tag emqtt release accoding to [Semantic Versioning](http://semver.org/)

max clientId length is 1024 now.

12.123 0.2.0 ��

����: 2014-12-07

rewrite the project, integrate with esockd, mochiweb

support MQTT 3.1.1

support HTTP to publish message

12.121. 0.3.0-alpha �� 265

EMQ X - ����� MQTT �����, �� 3.1.0

12.124 0.1.5 ��

����: 2013-01-05

Bugfix: remove QOS_1 match when handle PUBREL request

Bugfix: reverse word in emqtt_topic:words/1 function

12.125 0.1.4 ��

����: 2013-01-04

Bugfix: fix “mosquitto_sub -q 2 ……” bug

Bugfix: fix keep alive bug

12.126 0.1.3 ��

����: 2013-01-04

Feature: support QOS2 PUBREC, PUBREL,PUBCOMP messages

Bugfix: fix emqtt_frame to encode/decoe PUBREC/PUBREL messages

12.127 0.1.2 ��

����: 2012-12-27

Feature: release support like riak

Bugfix: use ?INFO/?ERROR to print log in tcp_listener.erl

12.128 0.1.1 ��

����: 2012-09-24

Feature: use rebar to generate release

Feature: support retained messages

Bugfix: send will msg when network error

12.129 0.1.0 ��

����: 2012-09-21

The first public release.

266 Chapter 12. ���� (Changes)

CHAPTER 13

���� (Upgrade)

13.1 ���3.1��

��: 3.1������������������������2.x�1.x�������������

����:

1. ����3.1����������� /opt/emqx-3.1/�

2. ����� etc/vm.args�etc/emqttd.config � etc/emq.conf���3.1��� etc/emqx.conf�

3. ������ etc/plugins/${your-plugin}.conf�

4. �������� data/loaded_plugins�

5. �����������

13.2 2.0���2.0.3��

����:

1. ����2.0.3����������� /opt/emqttd-2.0.3/�

2. ���� ‘etc/’ �����’data/’ ������������

3. �����������

13.3 ���2.0��

��: 2.0������������������������1.x�������������

267

EMQ X - ����� MQTT �����, �� 3.1.0

����:

1. ����2.0����������� /opt/emqttd-2.0/

2. ����� etc/vm.args�etc/emqttd.config���2.0��� etc/emq.conf

3. ������ etc/plugins/${your-plugin}.conf

4. �������� data/loaded_plugins

5. �����������

13.4 ���1.1.2��

��: 1.0����������1.1.2

����:

1. ����1.1.2����������� /opt/emqttd_112�

2. ���� ‘etc/’ �����’data/’ ������������

3. �����������������������

4. �����������

268 Chapter 13. ���� (Upgrade)

CHAPTER 14

���� (Protocol)

14.1 MQTT��

14.1.1 ��

MQTT�������������������������������������������

MQTT��: http://mqtt.org

MQTT V3.1.1����: http://docs.oasis-open.org/mqtt/mqtt/v3.1.1/os/mqtt-v3.1.1-os.html

14.1.2 ��

1. ������������

2. ��������������

3. ��TCP/IP����

4. 1�������2�������������

5. ��QoS���������

14.1.3 ��

MQTT����������������������������������

1. ���M2M�����������

2. Android�����WEB����

3. ���������Facebook Messenger

4. ��������������

5. �������������

269

EMQ X - ����� MQTT �����, �� 3.1.0

6. ��������������

7. �������������

14.1.4 MQTT����(Topic)����

MQTT������(Topic)���������(Topic)��URL�����:

chat/room/1

sensor/10/temperature

sensor/+/temperature

$SYS/broker/metrics/packets/received

$SYS/broker/metrics/#

��(Topic)��’/’�������’+’, ‘#’���:

'+': �����������a/+���a/x, a/y

'#': �����������a/#���a/x, a/b/c/d

��������������������������mosquitto���������:

mosquitto_sub -t a/b/+ -q 1

mosquitto_pub -t a/b/c -m hello -q 1

��: ���������������������������������

14.1.5 MQTT V3.1.1����

����

����(Fixed header)����(Variable header)������(Payload)

����

Bit 7 6 5 4 3 2 1 0byte1 MQTT Packet type Flagsbyte2… Remaining Length

270 Chapter 14. ���� (Protocol)

EMQ X - ����� MQTT �����, �� 3.1.0

����

���� ��� ����CONNECT 1 ����CONNACK 2 ����PUBLISH 3 ����PUBACK 4 ����PUBREC 5 QoS2����PUBREL 6 QoS2����PUBCOMP 7 QoS2����SUBSCRIBE 8 ����SUBACK 9 ����UNSUBSCRIBE 10 ����UNSUBACK 11 ������PINGREQ 12 PING��PINGRESP 13 PING��DISCONNECT 14 ����

PUBLISH����

PUBLISH�������������������� PUBACK���������QoS1���PUBREC/PUBREL/PUBCOMP����QoS2�����

PINGREQ/PINGRESP��

����������������(KeepAlive)��������PINGREQ����������PINGRESP���PINGREQ/PINGRESP���2����

14.1.6 MQTT��QoS

MQTT����QoS��������������������������MQTT���QoS�������������QoS������QoS�

�����QoS �����QoS �����QoS0 0 00 1 00 2 01 0 01 1 11 2 12 0 02 1 12 2 2

14.1. MQTT�� 271

EMQ X - ����� MQTT �����, �� 3.1.0

Qos0������

272 Chapter 14. ���� (Protocol)

EMQ X - ����� MQTT �����, �� 3.1.0

Qos1������

14.1. MQTT�� 273

EMQ X - ����� MQTT �����, �� 3.1.0

Qos2������

274 Chapter 14. ���� (Protocol)

EMQ X - ����� MQTT �����, �� 3.1.0

14.1.7 MQTT��(Clean Session)

MQTT���������CONNECT��������’Clean Session’�������

‘Clean Session’���0���������������������������������������������

‘Clean Session’���1�����������������������������

14.1.8 MQTT������

MQTT���������CONNECT������KeepAlive���������

������������KeepAlive������2���PINGREQ����������PINGREQ������2���PINGRESP���

����1.5���������������������������PINGREQ�����������������TCP���

��: emqttd����������2.5���������

14.1.9 MQTT����(Last Will)

MQTT��������CONNECT����������������(Will Message)����������(Topic)���(Payload)�

MQTT��������(�������������DISCONNECT��)�MQTT�������������

14.1.10 MQTT����(Retained Message)

MQTT���������(PUBLISH)������������(Retained Message)�������(Retained Message)������������������������������

��mosquitto��������������’a/b/c’:

mosquitto_pub -r -q 1 -t a/b/c -m 'hello'

�������MQTT�������’a/b/c’����������:

$ mosquitto_sub -t a/b/c -q 1hello

����(Retained Message)�������:

1. �������������������:

mosquitto_pub -r -q 1 -t a/b/c -m ''

2. �����������������

14.1.11 MQTT WebSocket��

MQTT�����TCP��������WebSocket��������WebSocket�������MQTT���������������MQTT������

MQTT���WebSocket�������binary���������Header:

Sec-WebSocket-Protocol: mqttv3.1 � mqttv3.1.1

14.1. MQTT�� 275

EMQ X - ����� MQTT �����, �� 3.1.0

14.1.12 MQTT������

emqtt����

emqtt���: https://github.com/emqtt

emqttc Erlang MQTT����CocoaMQTT Swift��MQTT����QMQTT QT��MQTT����

Eclipse Paho����

Paho��: http://www.eclipse.org/paho/

mqtt.org������

mqtt.org: https://github.com/mqtt/mqtt.github.io/wiki/libraries

14.1.13 MQTT�XMPP����

MQTT���������������������������������PC���XMPP��:

1. MQTT�������������������������������XMPP�������XML������������

2. MQTT������(Topic)�������������XMPP��JID�������������

3. MQTT����������������JSON������������XMPP����XML����������Base64������

4. MQTT�����������QoS���XMPP������������MQTT��������������

14.2 MQTT-SN ��

MQTT-SN ��� MQTT ��������� UDP �����������1884�MQTT-SN ����������������������������������� CPU�TCP ����������������������ZIGBEE�������300������������������ MQTT-SN ��������

MQTT-SN ���������: http://mqtt.org/new/wp-content/uploads/2009/06/MQTT-SN_spec_v1.2.pdf

14.2.1 MQTT-SN � MQTT ���

MQTT-SN ���� MQTT ����������� Will, �� Connect/Subscribe/Publish ��.

MQTT-SN �������Topic �� TopicId ����� TopicId ���16��������������� Topic, ��������� REGISTER ���� TopicId � Topic ������

MQTT-SN ������ Will ���, ������. � MQTT ���� CONNECT ��� Will ���, �������.

MQTT-SN ���������������� MQTT-SN ��� MQTT����� MQTT Broker ��. MQTT-SN ���������������

MQTT-SN �������������������������� UDP ���������� PUBLISH ������������������

14.2.2 EMQX-SN ����

EMQX-SN � EMQ X ����������� MQTT-SN ����������������� MQTT-SN ������ EMQ X Broker ���

276 Chapter 14. ���� (Protocol)

EMQ X - ����� MQTT �����, �� 3.1.0

����

File: etc/plugins/emqx_sn.conf:

mqtt.sn.port = 1884

mqtt.sn.advertise_duration = 900

mqtt.sn.gateway_id = 1

mqtt.sn.username = mqtt_sn_user

mqtt.sn.password = abc

mqtt.sn.port �� MQTT-SN ������mqtt.sn.advertise_duration ADVERTISE �������(�)mqtt.sn.gateway_id �� IDmqtt.sn.username ������������ MQTT-SN �������������mqtt.sn.password ���������� username ����

�� emqx-sn

14.2.3 MQTT-SN ����

1. https://github.com/eclipse/paho.mqtt-sn.embedded-c/

2. https://github.com/ty4tw/MQTT-SN

3. https://github.com/njh/mqtt-sn-tools

4. https://github.com/arobenko/mqtt-sn

14.3 LWM2M ��

LWM2M �� Open Mobile Alliance(OMA) ����������������������������������� �� ���

LWM2M �� CoAP ������������� UDP �� SMS ��

LWM2M ��������

• ��� LWM2M BOOTSTRAP SERVER�emqx-lwm2m ��������������

• ��� LWM2M SERVER�emqx-lwm2m ������� UDP �����SMS ������

LWM2M ���������� Object � Resource, � XML ������� Object ���������� �� �� XML ������

14.3.1 EMQX-LWM2M ��

EMQX-LWM2M � EMQ X �������������� LWM2M �������MQTT ������� EMQX-LWM2M ���� LWM2M ���������� EMQX-LWM2M �� notification�� EMQ X����������

14.3. LWM2M �� 277

14.3.2 MQTT � LWM2M���

� MQTT ������� Command � LWM2M ���MQTT � LWM2M �������� topic

�� MQTT Payload ��� json ������������������������ emqx-lwm2m ����

LWM2M �������� topic ��

MQTT Payload ���� json ��������������� emqx-lwm2m ����

����

File: etc/emqx_lwm2m.conf:

lwm2m.port = 5683

lwm2m.certfile = etc/certs/cert.pem

lwm2m.keyfile = etc/certs/key.pem

lwm2m.xml_dir = etc/lwm2m_xml

lwm2m.port �� lwm2m ������������ emqx-coap ����������5783��lwm2m.certfile DTLS �����lwm2m.keyfile DTLS �����lwm2m.xml_dir �� XML �������� XML ���� LWM2M Object

�� emqx-lwm2m

14.3.3 LWM2M �����

• https://github.com/eclipse/wakaama

• https://github.com/OpenMobileAlliance/OMA-LWM2M-DevKit

• https://github.com/AVSystem/Anjay

• http://www.eclipse.org/leshan/

EMQ X �������:

��: https://www.emqx.io��: https://github.com/emqx/emqx��: emqttd��: http://weibo.com/emqttTwitter: @emqtt��: ������������: [email protected] <[email protected]>

278

279