1.插件开关
2.0-rc.3版本将Presence模块改为独立插件,Presence模块会向$SYS主题(Topic)发布客户端上下线消息。
默认是开启
etc/plugins/emq_mod_presence.conf
## Enable presence module
## Values: on | off
module.presence = on
module.presence.qos = 0
2.$SYS系统主题订阅配置
订阅主题通用上下线主题
$SYS/brokers/emqttd@127.0.0.1/clients/#
默认只允许localhost的MQTT客户端订阅$SYS主题,可通过etc/acl.config修改访问控制规则。
%%--------------------------------------------------------------------
%%
%% [ACL](https://github.com/emqtt/emqttd/wiki/ACL)
%%
%% -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())}.
%%
%%--------------------------------------------------------------------
%% 允许'dashboard'用户订阅 '$SYS/#'
{allow, {user, "dashboard"}, subscribe, ["$SYS/#"]}.
%% 允许本机用户发布订阅全部主题
{allow, {ipaddr, "127.0.0.1"}, pubsub, ["$SYS/#", "#"]}.
%% 拒绝用户订阅'$SYS#'与'#'主题
{deny, all, subscribe, ["$SYS/#", {eq, "#"}]}.
%% 上述规则无匹配,允许所有
{allow, all}.
可以根据实际情况修改,比如添加一个用户名为“lucien”,ip地址为“192.168.1.100”的用户
%% 允许'dashboard'用户订阅 '$SYS/#'
{allow, {user, "dashboard","lucien"}, subscribe, ["$SYS/#"]}.
%% 允许本机用户发布订阅全部主题
{allow, {ipaddr, "127.0.0.1","192.168.1.100"}, pubsub, ["$SYS/#", "#"]}.
%% 拒绝用户订阅'$SYS#'与'#'主题
{deny, all, subscribe, ["$SYS/#", {eq, "#"}]}.
%% 上述规则无匹配,允许所有
{allow, all}.