【问题标题】:Mosquitto MQTT looping on subscribeMosquitto MQTT 在订阅时循环
【发布时间】:2015-12-04 07:23:25
【问题描述】:

我使用 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

谁能帮我解决这个问题。

【问题讨论】:

    标签: mqtt mosquitto


    【解决方案1】:

    有一点 - 我假设您在将配置放在这里时打错了:

    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
    

    这允许网桥向远程主机表明它们是网桥,并且是在某些情况下可以避免循环的方式。

    【讨论】:

    • 在添加 try_private true 后,我仍然面临着 lopping 的问题
    【解决方案2】:

    派对迟到了 :)

    在配置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
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-06-10
      相关资源
      最近更新 更多