我有一个负载均衡器,即 aws elb 所有发布/订阅都将通过 elb 两个 mosquitto 代理 A 和 mosquitto 代理 B 在 elb 一个 mosquitto 代理下同步这两个代理之间的主题(mosquitto.broker.sync)
这就是在节点 A 和 B 之间同步主题的 mosquitto 代理的配置看起来相似
mosquitto.broker.sync: ##
connection mosquitto-bridge
try_private false
address mosquitto.broker.A:1883 mosquitto.broker.B:1883
start_type automatic
round_robin true
notifications true
topic # both 2 "" ""
Run Code Online (Sandbox Code Playgroud)
但这不起作用,它只能连接到 mosquitto.broker.A 而不能连接到 mosquitto.broker.B
撤消所有先尝试一个
所以我尝试以其他方式从 mosquitto.broker.sync 中删除所有网桥配置(只是为了避免循环)
并将此配置添加到节点上
mosquitto.broker.A:##
connection mosquitto-bridge
try_private false
address mosquitto.broker.sync:1883
start_type automatic
round_robin true
notifications true
topic # both 2 "" ""
Run Code Online (Sandbox Code Playgroud)
mosquitto.broker.B:##
connection mosquitto-bridge
try_private false
address mosquitto.broker.sync:1883
start_type automatic
round_robin true
notifications true
topic # both 2 "" ""
Run Code Online (Sandbox Code Playgroud)
mosquitto.broker.sync: ##
#connection mosquitto-bridge
#try_private false
#address mosquitto.broker.A:1883 mosquitto.broker.B:1883
#start_type automatic
#round_robin true
#notifications true
#topic # both 2 "" ""
Run Code Online (Sandbox Code Playgroud)
但在这种情况下,我发送消息的节点被复制到它上面
对于第一次尝试,问题在于该address字段是要按顺序尝试连接的代理列表,而不是要同时连接的代理列表。
如何解释此列表取决于round_robin设置。
如果设置为true,则代理将连接到列表中的第一个,当连接断开时,它将尝试列表中的下一个,在每次重新连接时向下移动列表。
如果设置为false,它将连接到第一个并将其视为首选连接。当连接断开时,它将尝试重新连接,如果失败,它将向下移动列表,但会定期尝试重新连接到列表中的第一个。
要真正解决您的问题,请尝试以下操作:
蚊子经纪人A
connection sync-a
try_private false
address mosquitto.broker.sync:1883
notifications true
topic # out 2 "" A/
topic # in 2 "" B/
Run Code Online (Sandbox Code Playgroud)
蚊子经纪人B
connection sync-b
try_private false
address mosquitto.broker.sync:1883
notifications true
topic # out 2 "" B/
topic # in 2 "" A/
Run Code Online (Sandbox Code Playgroud)
并保持同步机原样。
这使用主题前缀来确保不形成循环。这也意味着您可以跟踪哪个代理在同步机器上做什么,因为所有主题都以它们来自的机器为前缀。