【问题标题】:Failover for NodeJS rhea AMQP clientNodeJS rhea AMQP 客户端的故障转移
【发布时间】:2020-06-14 01:44:26
【问题描述】:

我的机器上运行了多个 ActiveMQ 实例。它们被配置为shared file system master slave。如果一个 ActiveMQ 服务器宕机,那么应该自动恢复另一个。这按预期工作。

ActiveMQ 第一个实例的相关配置:

<transportConnectors>
    <!-- DOS protection, limit concurrent connections to 1000 and frame size to 100MB -->
    <transportConnector name="openwire" uri="tcp://0.0.0.0:61626?maximumConnections=1000&amp;wireFormat.maxFrameSize=104857600"/>
    <transportConnector name="amqp" uri="amqp://0.0.0.0:5672?maximumConnections=1000&amp;wireFormat.maxFrameSize=104857600"/>
    <transportConnector name="stomp" uri="stomp://0.0.0.0:61623?maximumConnections=1000&amp;wireFormat.maxFrameSize=104857600"/>
    <transportConnector name="mqtt" uri="mqtt://0.0.0.0:1889?maximumConnections=1000&amp;wireFormat.maxFrameSize=104857600"/>
    <transportConnector name="ws" uri="ws://0.0.0.0:61625?maximumConnections=1000&amp;wireFormat.maxFrameSize=104857600"/>
</transportConnectors>
<persistenceAdapter>
    <kahaDB directory="/Users/srikanth.doddi/Downloads/apachemq3.2.4/data/kahadb"/>
</persistenceAdapter>

ActiveMQ 第二个实例的相关配置:

<transportConnectors>
    <!-- DOS protection, limit concurrent connections to 1000 and frame size to 100MB -->
    <transportConnector name="openwire" uri="tcp://0.0.0.0:61616?maximumConnections=1000&amp;wireFormat.maxFrameSize=104857600"/>
    <transportConnector name="amqp" uri="amqp://0.0.0.0:5673?maximumConnections=1000&amp;wireFormat.maxFrameSize=104857600"/>
    <transportConnector name="stomp" uri="stomp://0.0.0.0:61613?maximumConnections=1000&amp;wireFormat.maxFrameSize=104857600"/>
    <transportConnector name="mqtt" uri="mqtt://0.0.0.0:1883?maximumConnections=1000&amp;wireFormat.maxFrameSize=104857600"/>
    <transportConnector name="ws" uri="ws://0.0.0.0:61614?maximumConnections=1000&amp;wireFormat.maxFrameSize=104857600"/>
</transportConnectors>
<persistenceAdapter>
    <kahaDB directory="/Users/srikanth.doddi/Downloads/apachemqold/data/kahadb"/>
</persistenceAdapter>

我在 NodeJS 中使用 AMQP 连接,使用 rhea,方式如下:

var container = require('rhea');
container.on('message', function (context) {
    console.log(context.message.body);
    context.connection.close();
});
container.once('sendable', function (context) {
    context.sender.send({body:'Hello World!'});
});
var connection = container.connect({'port':5672});
connection.open_receiver('examples');
connection.open_sender('examples');

现在,如果 5672 关闭,我的 ActiveMQ 作为主从运行,我希望客户端自动连接到 5673 并继续工作。这种检查应该持续进行。

Spring-boot中是这样实现的

activemq_url=tcp://localhost:61616,tcp://localhost:61626

spring.activemq.broker-url=failover://(${activemq_url})?randomize=false

【问题讨论】:

  • 是的,@JustinBertram 我已经将它实现为具有共享文件系统的主从。我有多个 ActiveMQ 实例正在运行
  • 现在这就是我使用 rhea 实现我的消息代理 npmjs.com/package/rhea 的方式
  • 您的问题缺少真正提供足够答案所需的详细信息,请编辑并扩展您的设置以及您想要实现的目标以及您尝试过哪些没有成功的内容。
  • @TimBish,我已经用更多输入更新了我的问题,请验证并提供答案
  • 据我所知,Spring Boot 实现无关紧要,因为它使用的是 OpenWire JMS 客户端而不是 rhea。这两个客户完全不同。我不清楚你为什么在这里提到它。

标签: node.js activemq amqp rhea


【解决方案1】:

您必须做一些工作来构建您的客户端代码,以便发生重新连接,rhea 没有 Qpid JMS 或 Artemis Core JMS 客户端等客户端提供的那种故障转移处理支持。

在 Rhea 源代码树中有一个重新连接 example,您可以将其用作将逻辑构建到您自己的应用程序中的起点。

【讨论】:

    猜你喜欢
    • 2013-02-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-06-24
    • 2014-01-09
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多