mqtt 蚊子桥水平缩放
mqtt mosquitto bridge horizontal scaling
我有一个负载均衡器,即 aws elb
所有 pub/sub 都将通过那个 elb
elb 下的两个蚊子经纪人 A 和蚊子经纪人 B
一个 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 "" ""
但这不起作用它只连接到 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 "" ""
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 "" ""
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 "" ""
但在这种情况下,我发送消息的节点在它上面被复制了
对于第一次尝试,问题是因为 address
字段是按顺序尝试连接的代理列表,而不是同时连接的代理列表。
如何解释此列表取决于 round_robin
设置。
如果设置为 true 则代理将连接到列表中的第一个,当连接断开时它将尝试列表中的下一个,在列表中向下移动每个重新连接。
如果设置为 false 它将连接到第一个并将其视为首选连接。当连接断开时,它将尝试重新连接,如果失败,它将在列表中向下移动,但会定期尝试并重新连接到列表中的拳头。
要真正解决您的问题,请尝试以下操作:
mosquitto.broker.A
connection sync-a
try_private false
address mosquitto.broker.sync:1883
notifications true
topic # out 2 "" A/
topic # in 2 "" B/
mosquitto.broker.B
connection sync-b
try_private false
address mosquitto.broker.sync:1883
notifications true
topic # out 2 "" B/
topic # in 2 "" A/
并让同步机保持原样。
这使用主题前缀来确保不会形成循环。这也意味着您可以跟踪哪个代理在同步机器上做什么,因为所有主题都以它们来自的机器为前缀。
我有一个负载均衡器,即 aws elb 所有 pub/sub 都将通过那个 elb elb 下的两个蚊子经纪人 A 和蚊子经纪人 B 一个 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 "" ""
但这不起作用它只连接到 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 "" ""
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 "" ""
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 "" ""
但在这种情况下,我发送消息的节点在它上面被复制了
对于第一次尝试,问题是因为 address
字段是按顺序尝试连接的代理列表,而不是同时连接的代理列表。
如何解释此列表取决于 round_robin
设置。
如果设置为 true 则代理将连接到列表中的第一个,当连接断开时它将尝试列表中的下一个,在列表中向下移动每个重新连接。
如果设置为 false 它将连接到第一个并将其视为首选连接。当连接断开时,它将尝试重新连接,如果失败,它将在列表中向下移动,但会定期尝试并重新连接到列表中的拳头。
要真正解决您的问题,请尝试以下操作:
mosquitto.broker.A
connection sync-a
try_private false
address mosquitto.broker.sync:1883
notifications true
topic # out 2 "" A/
topic # in 2 "" B/
mosquitto.broker.B
connection sync-b
try_private false
address mosquitto.broker.sync:1883
notifications true
topic # out 2 "" B/
topic # in 2 "" A/
并让同步机保持原样。
这使用主题前缀来确保不会形成循环。这也意味着您可以跟踪哪个代理在同步机器上做什么,因为所有主题都以它们来自的机器为前缀。