2015-12-04 98 views
1

我使用蚊子作为我的经纪人服务器。我想根据桥接连接建立一个经纪人集群。Mosquitto MQTT循环订阅

当我发布并订阅主题“存在”时,我从三个代理服务器得到了无尽的重复消息。

我有三个服务器,如: 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

一点 - 我想你已经在把你的配置在这里做了一个错字:

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 

这使得桥梁指示到远程主机,他们是一个桥梁,是在其中循环可以在某些情况下是可以避免的方式。

+0

尽管我在添加try_private true –

0

迟到了:)

了一个环路出现在配置topiC# both

删除/注释掉从服务器中的任何一个都桥配置,对双方

  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 
重启mosquitto