兔子 - 通道和连接未关闭
我正在使用以下Nodejs脚本在我的RabbitMQ队列中发布消息:
const amqp = require("amqplib");
[...]
const publishMsgToQueue = async (job, res) => {
const queue = job.queueName;
const msg = { url: job.msg };
try {
const connection = await amqp.connect(Rabbitmq.host);
const channel = await connection.createChannel();
await channel.assertQueue(queue, { durable: true });
await channel.sendToQueue(queue, Buffer.from(JSON.stringify(msg)));
await channel.close();
await connection.close();
} catch (error) {
logger.error(
"[AMQP] Error publishing to RabbitMQ",
job.msg,
"queue name:",
job.queueName
);
}
};
此功能在循环中以为单位来发布消息数组。
当所有消息发布时,我都有许多连接和频道打开...虽然应该通过Channel.Class.Close和Connection.close.Close ...但不是...
我在其他帖子上进行了很多检查,但是我没有成功……
我在哪里错了?
I'm using the following Nodejs script to publish messages in my RabbitMq queue:
const amqp = require("amqplib");
[...]
const publishMsgToQueue = async (job, res) => {
const queue = job.queueName;
const msg = { url: job.msg };
try {
const connection = await amqp.connect(Rabbitmq.host);
const channel = await connection.createChannel();
await channel.assertQueue(queue, { durable: true });
await channel.sendToQueue(queue, Buffer.from(JSON.stringify(msg)));
await channel.close();
await connection.close();
} catch (error) {
logger.error(
"[AMQP] Error publishing to RabbitMQ",
job.msg,
"queue name:",
job.queueName
);
}
};
This function is called in a for
loop to publish an array of messages.
When all the messages are published, I have many many connections and channels open... while it should be closed thanks to channel.close and connection.close ... but it's not...
I check a lot on other posts, but I didn't succeed so far...
Where am I wrong ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论