【问题标题】:mqtt mosquitto bridge horizontal scalingmqtt 蚊子桥水平缩放
【发布时间】:2016-03-29 11:37:30
【问题描述】:

我有一个负载均衡器,即 aws elb 所有的 pub/sub 都将通过那个 elb elb下的两个蚊子经纪人A和蚊子经纪人B 一个 mosquitto 代理在这两个代理之间同步主题(mosquitto.broker.sync)

试一试

这就是 mosquitto broker 在节点 A 和 B 之间同步主题的配置看起来很相似

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 "" ""

但在这种情况下,我发送消息的节点被复制了

【问题讨论】:

  • 您能否在第二次尝试中更详细地解释问题,目前尚不完全清楚问题所在。
  • 更新问题,答案帮我排序,我都在添加一个虚拟主题

标签: mqtt mosquitto


【解决方案1】:

对于第一次尝试,问题是因为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/

让同步机器保持原样。

这使用主题前缀来确保不形成循环。这也意味着您可以跟踪哪个代理在同步机器上正在做什么,因为所有主题都以它们来自的机器为前缀。

【讨论】:

  • 谢谢。但是,为什么有人必须这样做呢?引入第二个broker(B)的原因是为了处理broker(A)单独无法处理的负载。现在同步代理将崩溃,因为它的消息处理能力将等同于单独的代理(A)。还是说同时 tcp 连接的数量是代理更重要的限制因素,而不是它的消息处理能力?
  • 只有当您需要超过 2 个面向客户的经纪人时才真正需要。它可以防止转发循环,因为如果您发布到代理 A,它会转发给 B,然后再转发给 C。C 仅将消息视为来自 B,因此将转发给 A,并且消息不断循环。同步代理不会像其他代理那样努力工作,因为它只需要为其他代理而不是所有最终客户端匹配主题。
猜你喜欢
  • 2015-12-07
  • 2015-09-21
  • 2020-09-26
  • 2015-09-20
  • 2016-04-22
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多