在将外部RabbitMQ与NodeJS连接时,我遇到了以下错误消息:
Error: read ECONNRESET
at TCP.onStreamRead (internal/stream_base_commons.js:205:27) {
errno: 'ECONNRESET',
code: 'ECONNRESET',
syscall: 'read'
}
我的nodejs代码如下:
const amqp_url = "amqp://un:pw@sb-mq.com:9901/my-vhost";
amqp.connect(amqp_url, function (error0, connection) {
if (error0) {
throw error0;
}
connection.createChannel(function (error1, channel) {
if (error1) {
throw error1;
}
var queue = 'hello';
var msg = 'Hello World!';
channel.assertQueue(queue, {
durable: false
});
channel.sendToQueue(queue, Buffer.from(msg));
console.log(" [x] Sent %s", msg);
});
setTimeout(function () {
connection.close();
process.exit(0);
}, 500);
});
但是问题是,当我用相同的配置在本地安装RabbidMQ时,但是使用默认端口(如amqp://un:pw@localhost:5672/my-vhost
),它运行得很好。请让我知道如何解决这个问题,谢谢。
发布于 2021-06-20 09:30:33
当我尝试使用amqps
而不是amqp
时,我发现这个问题已经解决了。
发布于 2021-06-15 14:57:53
"ECONNRESET“是指TCP会话的另一端突然关闭了连接的结束。
请参阅How do I debug error ECONNRESET in Node.js?
关于RabbitMQ,请检查rabbitmq是否在该端口中活动,只需:
telnet sb-mq.com 9901
从您的客户端计算机和检查防火墙配置。您可能在9901上运行另一个服务。
ECONNRESET
是网络问题,rabbitmq可以在不同的端口上工作而没有问题。
https://stackoverflow.com/questions/67973620
复制相似问题