Reputation: 1160
I'm using mosquitto as my broker server. And I want to build a cluster of brokers based on the bridge connection.
When I published and then subscribed the topic 'presence', I got endless repeated messages from the three broker servers.
I have three servers, such as: 10.80.1.1, 10.80.1.2
and I have the following configuration for each server.
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
Who guy could help me to fix this problem.
Upvotes: 1
Views: 1837
Reputation: 131
late to the party :)
its a loop as seen in the config topic # both
,
remove/comment out all bridge config from any one of the server and restart mosquitto on 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
Upvotes: 0
Reputation: 11608
One point - I assume you've made a typo in putting your config here:
address 10.80.1.1:1883,10.80.1.2:1883
The separator for multiple addresses is a " ", not a ",".
The problem is that you've created a loop in your subscriptions.
When Bridge3 receives a message, it publishes to Bridge2. Bridge2 knows that the message came from Bridge3, and that Bridge3 is a bridge, so although the topic rule says it should send the message back to Bridge3, it doesn't. It sends the message to Bridge1 though.
Now I'm assuming that Bridge1 has ended up connected to Bridge3 instead of Bridge2. In that case, Bridge1 doesn't return the message to Bridge2 for the same reason as above, but it does send the message to Bridge3.
Bridge3 doesn't know that this is the same message as the original one, so it publishes to Bridge1 and so the loop continues.
Answer to original question is above.
Updated answer:
You should use
try_private true
This allows bridges to indicate to the remote host that they are a bridge, and is the way in which the loops can be avoided in some situations.
Upvotes: 2