在订阅上进行Mosquitto MQTT循环

时间:2015-12-04 07:23:26

标签: mqtt mosquitto

我正在使用mosquitto作为我的经纪人服务器。我想基于桥接连接构建一个代理集群。

当我发布然后订阅主题“在场”时,我从三个代理服务器收到了无数重复的消息。

我有三台服务器,例如: 10.80.1.1,10.80.1.2

我为每台服务器配置了以下配置。

on server 10.80.1.1, the config as the following:
connection myconn
address 10.80.1.2:1881
topic # both
cleansession true
try_private false
bridge_attempt_unsubscribe false
notifications false
allow_anonymous true
start_type automatic
clientid Bridge3

on server 10.80.1.2, the config as the following:
connection myconn
address 10.80.1.1:1883
topic # both
cleansession true
try_private false
bridge_attempt_unsubscribe false
notifications false
allow_anonymous true
start_type automatic
clientid Bridge2

谁能帮助我解决这个问题。

2 个答案:

答案 0 :(得分:2)

有一点 - 我认为你把配置放在这里是一个错字:

address 10.80.1.1:1883,10.80.1.2:1883

多个地址的分隔符是“”,而不是“,”。

问题是您在订阅中创建了一个循环。

当Bridge3收到消息时,它会发布到Bridge2。 Bridge2知道消息来自Bridge3,并且Bridge3是一个桥接器,所以尽管主题规则说它应该将消息发送回Bridge3,但事实并非如此。它会将消息发送到Bridge1。

现在我假设Bridge1最终连接到Bridge3而不是Bridge2。在这种情况下,由于与上面相同的原因,Bridge1不会将消息返回给Bridge2,但它会将消息发送到Bridge3。

Bridge3不知道这是与原始消息相同的消息,因此它发布到Bridge1,因此循环继续。

原始问题的答案在上面。

更新回答:

你应该使用

try_private true

这允许网桥向远程主机指示它们是桥接器,并且是在某些情况下可以避免环路的方式。

答案 1 :(得分:0)

派对迟到了:)

它是一个循环,如配置topic # both

中所示

从任何一台服务器删除/注释掉所有网桥配置,然后重新启动mosquitto

            on server 10.80.1.1, the config as the following:
            connection myconn
            address 10.80.1.2:1881
            topic # both
            cleansession true
            try_private false
            bridge_attempt_unsubscribe false
            notifications false
            allow_anonymous true
            start_type automatic
            clientid Bridge3

            on server 10.80.1.2, the config as the following:
            #connection myconn
            #address 10.80.1.1:1883
            #topic # both
            #cleansession true
            #try_private false
            #bridge_attempt_unsubscribe false
            #notifications false
            #allow_anonymous true
            #start_type automatic
            #clientid Bridge2
相关问题