赞
踩
方式一、订阅系统主题
1、修改acl.conf文件配置,添加如下
{allow, all, subscribe, ["$SYS/brokers/+/clients/#"]}.
注:要注释掉deny,它是默认阻止访问系统主题的
%%%{deny, all, subscribe, ["$SYS/#", {eq, "#"}]}.
或者直接在图形界面
2、代码中订阅$SYS/brokers/+/clients/#主题
@PostConstruct
public String subMessage() {
String subTopic = "$SYS/brokers/+/clients/#";
// String[] topic={"$SYS/brokers/+/clients/#"};
mqttConfig.subscribe(subTopic);
// 断开连接
// mqttConfig.disconnect();
return "OK";
}
方式二、遗嘱消息方式
1、搭建连接EQMX参考我的文章
https://blog.csdn.net/weixin_41463944/article/details/129152166?ops_request_misc=%257B%2522request%255Fid%2522%253A%2522169924959616800227490098%2522%252C%2522scm%2522%253A%252220140713.130102334.pc%255Fblog.%2522%257D&request_id=169924959616800227490098&biz_id=0&utm_medium=distribute.pc_search_result.none-task-blog-2~blog~first_rank_ecpm_v1~rank_v31_ecpm-3-129152166-null-null.nonecase&utm_term=EMQX&spm=1018.2226.3001.4450
2、在配置文件中新增如下:
//遗嘱消息
connOpts.setWill("deadTest","我已死亡,连接已经断开".getBytes(),qos,false);
3、实现效果
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。