连接到activemq artemis时使用nodejs stompit的连接超时
Connection timeout using nodejs stompit when connecting to activemq artemis
我正在与我的 ActiveMQ Artemis 代理建立 stompit 连接,并且在调用连接时我没有看到任何错误。一段时间后(几分钟后)我看到连接超时错误。
此外,我没有看到正在创建的队列(只有地址)正在创建,并且在 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
我是 stompit 新手。
ActiveMQ Artemis STOMP documentation 在这里应该会有帮助。
我推荐的第一件事是启用调试日志记录。 The documentation 状态:
Incoming and outgoing STOMP frames can be logged by enabling DEBUG
for org.apache.activemq.artemis.core.protocol.stomp.StompConnection
. This can be extremely useful for debugging or simply monitoring client activity. Along with the STOMP frame itself the remote IP address of the client is logged as well as the internal connection ID so that frames from the same client can be correlated.
您可以通过修改 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 文档指出:
When a STOMP client sends a message (using a SEND
frame), the protocol manager looks at the message to determine where to route it and potentially how to create the address and/or queue to which it is being sent. The protocol manager uses either of the following bits of information from the frame to determine the routing type:
The value of the destination-type
header. Valid values are ANYCAST
and MULTICAST
(case sensitive).
The "prefix" on the destination
header. See additional info on prefixes.
If no indication of routing type is supplied then the default defined in the corresponding default-address-routing-type
& default-queue-routing-type
address-settings will be used.
The destination
header maps to an address of the same name. If the destination
header used a prefix then the prefix is stripped.
当您发送消息时,代理使用 MULTICAST
路由类型,这意味着它只会自动创建地址而不是队列。这是默认行为。
如文档中所述您有 3 个主要选项 来解决此...
一个,可以发送destination-type
头,例如:
const sendHeaders= {
'destination': '/queue/TestEvent', 'content-type': 'text/plain', 'destination-type': 'ANYCAST'
};
Two,你可以在 STOMP acceptor
上配置一个前缀,就像在代理附带的 "stomp-jms" example 中所做的那样,例如:
<acceptor name="stomp">tcp://0.0.0.0:61613?anycastPrefix=/queue/</acceptor>
三种,可以通过address-settings更改默认的路由类型,例如:
<address-setting match="#">
...
<default-address-routing-type>ANYCAST</default-address-routing-type>
<default-queue-routing-type>ANYCAST</default-queue-routing-type>
...
</address-setting>
当然,使用 #
的 match
将更改 每个 地址和队列的默认值,因此您可能需要针对您的具体情况进行调整需要。
我正在与我的 ActiveMQ Artemis 代理建立 stompit 连接,并且在调用连接时我没有看到任何错误。一段时间后(几分钟后)我看到连接超时错误。
此外,我没有看到正在创建的队列(只有地址)正在创建,并且在 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
我是 stompit 新手。
ActiveMQ Artemis STOMP documentation 在这里应该会有帮助。
我推荐的第一件事是启用调试日志记录。 The documentation 状态:
Incoming and outgoing STOMP frames can be logged by enabling
DEBUG
fororg.apache.activemq.artemis.core.protocol.stomp.StompConnection
. This can be extremely useful for debugging or simply monitoring client activity. Along with the STOMP frame itself the remote IP address of the client is logged as well as the internal connection ID so that frames from the same client can be correlated.
您可以通过修改 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 文档指出:
When a STOMP client sends a message (using a
SEND
frame), the protocol manager looks at the message to determine where to route it and potentially how to create the address and/or queue to which it is being sent. The protocol manager uses either of the following bits of information from the frame to determine the routing type:
The value of the
destination-type
header. Valid values areANYCAST
andMULTICAST
(case sensitive).The "prefix" on the
destination
header. See additional info on prefixes.If no indication of routing type is supplied then the default defined in the corresponding
default-address-routing-type
&default-queue-routing-type
address-settings will be used.The
destination
header maps to an address of the same name. If thedestination
header used a prefix then the prefix is stripped.
当您发送消息时,代理使用 MULTICAST
路由类型,这意味着它只会自动创建地址而不是队列。这是默认行为。
如文档中所述您有 3 个主要选项 来解决此...
一个,可以发送destination-type
头,例如:
const sendHeaders= {
'destination': '/queue/TestEvent', 'content-type': 'text/plain', 'destination-type': 'ANYCAST'
};
Two,你可以在 STOMP acceptor
上配置一个前缀,就像在代理附带的 "stomp-jms" example 中所做的那样,例如:
<acceptor name="stomp">tcp://0.0.0.0:61613?anycastPrefix=/queue/</acceptor>
三种,可以通过address-settings更改默认的路由类型,例如:
<address-setting match="#">
...
<default-address-routing-type>ANYCAST</default-address-routing-type>
<default-queue-routing-type>ANYCAST</default-queue-routing-type>
...
</address-setting>
当然,使用 #
的 match
将更改 每个 地址和队列的默认值,因此您可能需要针对您的具体情况进行调整需要。