我在PC1(mosquitto v1.4.8)和PC2(带有MQTT适配器的RabbitMQ v3.6.2)上安装了两个mosquitto代理。
在PC1开始的桥接如下
sensor/room1/ <-> office/room1/
但是我注意到,每当网桥处于活动状态时,总会有一条重复的消息被发布回来,这意味着我订阅同一主题的所有应用程序(在PC1上)都会收到两次相同的消息。 我在这里做错了什么设置?
PC1 mosquitto.conf
connection bridge-pc1-to-pc2
address pc2-address.com
topic room1/# both 2 sensor/ office/
bridge_protocol_version mqttv311
notifications true
cleansession true
try_private false
为了测试环回问题,我让PC1订阅了主题sensor/#
mosquitto_sub -t sensor/# -v -d
然后在PC1我发布了一条测试消息
mosquitto_pub -t sensor/room1/temperature -m '{"value":27.3, "timestamp":"2016-06-03 14:02:38"}'
云端的经纪人(PC2)正确收到消息(只收到一次消息)
Client mosqsub/3121-Dennis-iMa sending CONNECT
Client mosqsub/3121-Dennis-iMa received CONNACK
Client mosqsub/3121-Dennis-iMa sending SUBSCRIBE (Mid: 1, Topic: office/#, QoS: 0)
Client mosqsub/3121-Dennis-iMa received SUBACK
Subscribed (mid: 1): 0
Client mosqsub/3121-Dennis-iMa received PUBLISH (d0, q0, r0, m0, 'office/room1/temperature', ... (14 bytes))
office/room1/temperature {"value":27.3, "timestamp":"2016-06-03 14:02:38"}
但PC1两次收到同样的消息!下面是Pi的输出
Received CONNACK
Received SUBACK
Subscribed (mid: 1): 0
Received PUBLISH (d0, q0, r0, m0, 'sensor/room1/temperature', ... (14 bytes))
sensor/room1/temperature {"value":27.3, "timestamp":"2016-06-03 14:02:38"}
Received PUBLISH (d0, q0, r0, m0, 'sensor/room1/temperature', ... (14 bytes))
sensor/room1/temperature {"value":27.3, "timestamp":"2016-06-03 14:02:38"}
为什么会有环回发布的消息以及如何解决这个问题?
2016年6月3日更新
这与question不是同一个问题,因为它不涉及水平扩展(1对多经纪人)
答案 0 :(得分:1)
将try_private false
更改为try_private true
。这正是它的目的。如果兔子不支持该功能(它目前不在规范中,但广泛使用),那么你运气不好。
答案 1 :(得分:0)
RabbitMQ不支持try_private
并且对网桥一无所知。因此,发布到RabbitMQ中的office/*
的消息将被发送回订阅的mosquitto而不考虑任何private
标志。
要删除周期,可以使用不同的主题名称进行连接或使用两个mosquitto服务器。