2015-12-04 105 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