【问题标题】:Connection timeout using nodejs stompit when connecting to activemq artemis连接到activemq artemis时使用nodejs stompit的连接超时
【发布时间】:2020-01-30 04:44:32
【问题描述】:

我正在与我的 ActiveMQ Artemis 代理建立 stompit 连接,并且在调用 connect 时没有看到任何错误。一段时间后(几分钟后)我看到连接超时错误。

另外,我没有看到正在创建的队列(仅地址)被创建,并且在 Artemis 控制台上没有看到该消息。

ActiveMQ Artemis 控制台:

代码:

const stompConnectOptions= {
    'host': 'localhost',
    'port': 61613,
    'connectHeaders': {
        'host': '/', 'login': 'admin', 'passcode': 'xxxx', 'heart-beat': '1000,1000'
    }
};

const stompit=require ('stompit') const subscribeHeaders= {
    'destination': 'emailEvent', 'ack': 'client-individual'
};

const sendHeaders= {
    'destination': '/queue/TestEvent', 'content-type': 'text/plain'
};

stompit.connect(stompConnectOptions, (err, client)=> {
    if (err) {
        console.log("error with stomp connection.");
        return;
    }
    console.log("stomp connected") stompClient=client;
    const frame=client.send(sendHeaders);
    frame.write('hello');
    frame.end();
    console.log('hello message sent')
});

ActiveMQ 服务器日志:

2020-01-29 23:33:46,333 WARN  [org.apache.activemq.artemis.core.protocol.stomp] AMQ332069: Sent ERROR frame to STOMP client /127.0.0.1:52170: null
2020-01-29 23:33:46,334 WARN  [org.apache.activemq.artemis.core.server] AMQ222067: Connection failure has been detected: null [code=REMOTE_DISCONNECT]
2020-01-29 23:33:46,335 WARN  [org.apache.activemq.artemis.core.server] AMQ222061: Client connection failed, clearing up resources for session 21617631-4319-11ea-a1bd-24a2e1f3b27a
2020-01-29 23:33:46,337 WARN  [org.apache.activemq.artemis.core.server] AMQ222107: Cleared up resources for session 21617631-4319-11ea-a1bd-24a2e1f3b27a

我是新手。

【问题讨论】:

    标签: node.js stomp activemq-artemis


    【解决方案1】:

    ActiveMQ Artemis STOMP documentation 在这里应该会有所帮助。

    我建议的第一件事是启用调试日志记录。 The documentation 状态:

    可以通过为org.apache.activemq.artemis.core.protocol.stomp.StompConnection 启用DEBUG 来记录传入和传出的STOMP 帧。这对于调试或简单地监视客户端活动非常有用。除了 STOMP 帧本身,还会记录客户端的远程 IP 地址以及内部连接 ​​ID,以便可以关联来自同一客户端的帧。

    您可以通过修改 etc/logging.properties 来启用此日志记录。

    首先,将其添加到文件开头以逗号分隔的loggers 列表中:

    org.apache.activemq.artemis.core.protocol.stomp.StompConnection
    

    第二,在ActiveMQ Artemis logger levels注释下添加一个新行:

    logger.org.apache.activemq.artemis.core.protocol.stomp.StompConnection.level=DEBUG
    

    启用日志记录后,它应该可以帮助您了解关闭连接的原因。我的猜测是客户端没有发送正确的心跳帧。在这种情况下,您可以尝试无心跳连接,例如:

    const stompConnectOptions= {
        'host': 'localhost',
        'port': 61613,
        'connectHeaders': {
            'host': '/', 'login': 'admin', 'passcode': 'xxxx', 'heart-beat': '0,0'
        }
    };
    

    该文档还应该有助于解释为什么只创建一个地址而不是一个队列。 In the "Sending" section 文档状态:

    当 STOMP 客户端发送消息(使用 SEND 帧)时,协议管理器会查看消息以确定将其路由到何处以及可能如何创建将其发送到的地址和/或队列。协议管理器使用帧中的以下任一信息位来确定路由类型:

    1. destination-type 标头的值。有效值为ANYCASTMULTICAST(区分大小写)。

    2. destination 标头上的“前缀”。请参阅 additional info 的前缀。

    如果未提供路由类型指示,则将使用在相应的default-address-routing-typedefault-queue-routing-type 地址设置中定义的默认值。

    destination 标头映射到同名地址。如果destination 标头使用了前缀,则前缀将被去除。

    当您发送消息时,代理使用MULTICAST 路由类型,这意味着它只会自动创建地址而不是队列。这是默认行为。

    如文档中所述,您有 3 个主要选项来解决此问题...

    一个,可以发送destination-type标头,例如:

    const sendHeaders= {
        'destination': '/queue/TestEvent', 'content-type': 'text/plain', 'destination-type': 'ANYCAST'
    };
    

    ,你可以在 STOMP acceptor 上配置前缀,就像在代理附带的 "stomp-jms" example 中所做的那样,例如:

    <acceptor name="stomp">tcp://0.0.0.0:61613?anycastPrefix=/queue/</acceptor>
    

    ,您可以通过地址设置更改默认路由类型,例如:

    <address-setting match="#">
       ...
       <default-address-routing-type>ANYCAST</default-address-routing-type>
       <default-queue-routing-type>ANYCAST</default-queue-routing-type>
       ...
    </address-setting>
    

    当然,使用# 中的match 会更改每个地址和队列的默认值,因此您可能需要根据自己的特定需求对其进行调整。

    【讨论】:

    • 感谢您的帖子,它帮助我理解并解决了为什么队列没有创建问题。连接问题不再发生,不知道它是如何解决的。将继续检查谢谢
    • 刚刚连接失败。
    • 2020-01-30 19:54:24,734 调试 [org.apache.activemq.artemis.core.protocol.stomp.StompConnection] STOMP(/192.168.0.10:50538, b5d4fe43):OUT > > StompFrame[command=ERROR,headers={message=null},content=null,bytes=null 2020-01-30 19:54:24,738 WARN [org.apache.activemq.artemis.core.protocol.stomp] AMQ332069:向 STOMP 客户端 /192.168.0.10:50538 发送错误帧:null 2020-01-30 19:54:24,739 WARN [org.apache.activemq.artemis.core.server] AMQ222067:检测到连接失败:null [code= REMOTE_DISCONNECT]
    • 你还在和'heart-beat': '1000,1000'联系吗?此外,您需要在 Stomp 连接处于活动状态的整个过程中提供调试日志,以便我可以看到发生了什么。此时我怀疑客户端在没有发送DISCONNECT 帧的情况下关闭了它的连接。
    • 仍有心跳:1000。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-01-17
    • 2012-03-12
    • 1970-01-01
    • 2021-05-16
    • 2012-06-08
    • 2014-10-10
    • 2021-01-12
    相关资源
    最近更新 更多