无法使用Node.js连接到Apache ActiveMQ [英] Unable to connect to Apache ActiveMQ with Node.js
问题描述
尝试通过 amqp10 。我正在使用以下代码(改编自述文件中的原始示例):
Trying to connect to my Apache ActiveMQ broker using the AMQP 1.0 protocol via amqp10. I am using the following code (adapted from the original example in the README):
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));
错误
执行失败,并显示以下内容应用程序错误:
Error
Execution fails with the following application error:
Workspace / activemq / node_modules / amqp10 / lib / frames.js:64
stream.write(buffer,打回来);
^
Workspace/activemq/node_modules/amqp10/lib/frames.js:64 stream.write(buffer, callback); ^
TypeError:无法在Object.frames.writeFrame(/ home / pedro / Workspace / activemq /在Connection.sendFrame上的node_modules / amqp10 / lib / frames.js:64:9)
(/home/pedro/Workspace/activemq/node_modules/amqp10/lib/connection.js:329:10)
在Connection._sendCloseFrame(/home/pedro/Workspace/activemq/node_modules/amqp10/lib/connection.js:491:8)在Connection._receiveAny(/ home / pedro / Workspace / activemq / node_modules / amqp10 / lib / connection.js:413:12)
在Connection._receiveData(/home/pedro/Workspace/activemq/node_modules/amqp10/lib/connection.js:358:8)
在NetTransport。 (/home/pedro/Workspace/activemq/node_modules/amqp10/lib/connection.js:516:38)
在emitOne(events.js:96:13)
在NetTransport.emit(事件。 js:191:7)
在Socket。 (/home/pedro/Workspace/activemq/node_modules/amqp10/lib/transport/net_transport.js:26:49)
在emitOne(events.js:96:13)
在Socket.emit( events.js:191:7)可读AddChunk的
(_stream_visible.js:178:18)Socket.Readable.push的
(_stream_visible.js:136:10)TCP.onread的
(net.js:560:20)
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拒绝请求并显示以下消息:
While ActiveMQ rejects the request with the following message:
WARN |来自非AMQP v1.0客户端的连接尝试。 AMQP,0,1,0,0
警告|传输连接到:tcp://127.0.0.1:53188失败:org.apache.activemq.transport.amqp.AmqpProtocolException:尝试使用不支持的AMQP从客户端进行连接
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
我尝试过的事情
我尝试实施此问题中描述的修复程序:
What I tried
I tried to implement the fix described in this issue:
- https://github.com/noodlefrenzy/node-amqp10/issues/241
但是它也不起作用。还尝试在url中指定端口5672,但是没有运气。
But it didn't work either. Also tried specifying the port 5672 in the url, but with no luck.
这时我可以肯定的是,该应用程序将失败,因为ActiveMQ拒绝了该请求为无效请求。
At this point I am quite sure the application fails the write, because ActiveMQ rejects the request as invalid.
- 有关如何解决此问题的任何想法?
推荐答案
解决方案
之后在ActiveMQ论坛中询问,事实证明@Tim是正确的。要引用用户Gordon Sim-2:
Solution
After asking around in the ActiveMQ forums, it does turn out that @Tim was correct. To quote the user Gordon Sim-2:
从5.14(...)开始,ActiveMQ需要一个SASL层,即使您使用
匿名认证。客户的示例通常不会以任何方式
进行显式身份验证(...)
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 (...)
两个选择。
第一个是更改代码,这就是我一直在寻找的代码对于:
The first one is to change the code, which is what I was looking for:
要让amqp10客户端使用SASL层,只需在连接上指定
saslMechanism替代,例如
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
,我强烈建议您在阅读时检查
This approach was suggested by the creator of yet another AMQP 1.0 Node.js library called rhea
and I highly recommend that if you are reading this, to check it.
第二个是Tim所建议的代理配置文件。如果您选择这种方法,我建议您阅读他的文章,因为它比较完整。
The second one, as Tim suggested, is to change the broker configuration files. I recommend reading his post if you opt for this approach as it is more complete.
这篇关于无法使用Node.js连接到Apache ActiveMQ的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!