gpt4 book ai didi

node.js - 无法使用 Node.js 连接到 Apache ActiveMQ

转载 作者:太空宇宙 更新时间:2023-11-03 22:41:34 26 4
gpt4 key购买 nike

背景

尝试通过 amqp10 使用 AMQP 1.0 协议(protocol)连接到我的 Apache ActiveMQ 代理。我正在使用以下代码(改编自自述文件中的原始示例):

const AMQPClient = require("amqp10").Client;
const Promise = require("bluebird");

//Fix from: https://github.com/noodlefrenzy/node-amqp10/issues/241
const activeMQPolicy = require("amqp10").Policy;
const client = new AMQPClient(activeMQPolicy.ActiveMQ);

const setUp = () => {
return Promise.all([
client.createReceiver("amq.topic"),
client.createSender("amq.topic")
]);
};

client.connect("amqp://localhost")
.then(setUp)
.spread(function (receiver, sender) {
receiver.on("errorReceived", function (err) {

if (err) {
console.log(`failed with error: ${err}`);
return;
}

receiver.on("message", message => console.log(`Rx message: ${message.body}`));

return sender.send({ key: "Value" });
});
})
.error( err => console.log("error: ", err));

错误

执行失败并出现以下应用程序错误:

Workspace/activemq/node_modules/amqp10/lib/frames.js:64 stream.write(buffer, callback); ^

TypeError: Cannot read property 'write' of null at Object.frames.writeFrame (/home/pedro/Workspace/activemq/node_modules/amqp10/lib/frames.js:64:9) at Connection.sendFrame (/home/pedro/Workspace/activemq/node_modules/amqp10/lib/connection.js:329:10) at Connection._sendCloseFrame (/home/pedro/Workspace/activemq/node_modules/amqp10/lib/connection.js:491:8) at Connection._receiveAny (/home/pedro/Workspace/activemq/node_modules/amqp10/lib/connection.js:413:12) at Connection._receiveData (/home/pedro/Workspace/activemq/node_modules/amqp10/lib/connection.js:358:8) at NetTransport. (/home/pedro/Workspace/activemq/node_modules/amqp10/lib/connection.js:516:38) at emitOne (events.js:96:13) at NetTransport.emit (events.js:191:7) at Socket. (/home/pedro/Workspace/activemq/node_modules/amqp10/lib/transport/net_transport.js:26:49) at emitOne (events.js:96:13) at Socket.emit (events.js:191:7) at readableAddChunk (_stream_readable.js:178:18) at Socket.Readable.push (_stream_readable.js:136:10) at TCP.onread (net.js:560:20)

虽然 ActiveMQ 拒绝请求并显示以下消息:

WARN | Connection attempt from non AMQP v1.0 client. AMQP,0,1,0,0 WARN | Transport Connection to: tcp://127.0.0.1:53188 failed: org.apache.activemq.transport.amqp.AmqpProtocolException: Connection from client using unsupported AMQP attempted

我尝试了什么

我尝试实现此问题中描述的修复:

但是也没有成功。还尝试在 url 中指定端口 5672,但没有成功。

问题

此时我非常确定应用程序写入失败,因为 ActiveMQ 将请求视为无效而拒绝。

  • 关于如何解决这个问题有什么想法吗?

最佳答案

解决方案

在 ActiveMQ 论坛中询问后,事实证明@Tim 是正确的。引用用户 Gordon Sim-2 的话:

As of 5.14 (...) ActiveMQ requires a SASL layer, even if you use ANONYMOUS to authenticate. The examples for clients often don't explicitly authenticate in any way (...)

要解决此问题,有两种选择。

选项 1 - 更改代码

第一个是更改代码,这就是我正在寻找的:

To have the amqp10 client use a SASL layer, just specify a saslMechanism override on the connect e.g.

client.connect(uri, {'saslMechanism':'ANONYMOUS'})

这种方法是由另一个名为 rhea 的 AMQP 1.0 Node.js 库的创建者建议的。如果您正在阅读本文,我强烈建议您检查一下。

选项 2 - 更改代理配置文件

正如 Tim 建议的那样,第二个是更改代理配置文件。如果您选择这种方法,我建议您阅读他的文章,因为它更完整。

关于node.js - 无法使用 Node.js 连接到 Apache ActiveMQ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43873400/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com