moquitto配置方法
sudo nano /etc/mosquitto/mosquitto.confpid_file /var/run/mosquitto.pid
# 消息持久存储
persistence true
persistence_location /var/lib/mosquitto/
# 日志文件
log_dest file /var/log/mosquitto/mosquitto.log
# 其他配置
include_dir /etc/mosquitto/conf.d
# 禁止匿名访问
allow_anonymous false
# 认证配置
password_file /etc/mosquitto/pwfile
# 权限配置
acl_file /etc/mosquitto/aclfile
认证配置pwfile
创建文件
sudo touch /etc/mosquitto/pwfile
开启服务开启
sudo mosquitto_passwd /etc/mosquitto/pwfile bootloader #bootloader是我当前用户名
权限配置aclfile
sudo nano /etc/mosquitto/aclfile
# user1只能发布以test为前缀的主题,订阅以$SYS开头的主题即系统主题
user user1
topic write test/#
topic read $SYS/#
# user2只能订阅以test为前缀的主题
user user2
topic read test/#
启动服务端:
#-c:指定特定配置文件启动
#-d:后台运行
mosquitto -c /etc/mosquitto/mosquitto.conf -d
测试:
发布使用mosquitto_pub命令,订阅使用mosquitto_sub命令.常用参数介绍:
参数描述
-h服务器主机,默认localhost
-t指定主题
-u用户名
-P密码
-i客户端id,唯一
-m发布的消息内容
[*]订阅
mosquitto_sub -h localhost -t "test/#" -u user2 -P 123456 -i "client1"
订阅系统主题
# 订阅客户端存活连接数
mosquitto_sub -h localhost -u user1 -P 123456 -i "client2" -t '$SYS/broker/clients/active'#发布者 订阅 者都算存活连接发布:
mosquitto_pub -h localhost -t "test/abc" -u user1 -P 123456 -i "client3" -m "How are you?"
4.2注册应用到EdgeX
curl -X POST -d '{
"name":"QuickStartExport",
"addressable":{
"name":"HiveMQBroker",
"protocol":"tcp",
"address":"localhost",
"port":1883,
"publisher":"EdgeXExportPublisher",
"topic":"EdgeXQuickStartGuide"
},
"format":"JSON",
"filter":{
"deviceIdentifiers":["Random-Integer-Generator01"]
},
"enable":true,
"destination":"MQTT_TOPIC"
}' http://localhost:48071/api/v1/registration
页:
[1]