node.js - Rabbit MQ amqplib错误 "No channels left to allocate"

标签 node.js rabbitmq

在 pub sub 模式中使用rabbit mq 工作人员工作一段时间后,我在创建 channel 时遇到错误。

错误:没有剩余 channel 可供分配

最佳答案

如果您使用https://www.npmjs.com/package/amqplib , 您可以使用 Promise 在发布多条消息的同时共享一个 channel

message-queue.js

const q = 'tasks';

const open = require('amqplib').connect('amqp://localhost');

const channelPromise = open.then((conn) => conn.createChannel());

// Publisher
function publishMessage(message) {
  channelPromise.then((ch) => ch.assertQueue(q)
    .then((ok) => ch.sendToQueue(q, Buffer.from(message))))
    .catch(console.warn);
}

// Consumer
open.then((conn) => conn.createChannel())
  .then((ch) => ch.assertQueue(q).then((ok) => ch.consume(q, (msg) => {
    if (msg !== null) {
      console.log(msg.content.toString());
      ch.ack(msg);
    }
  }))).catch(console.warn);

module.exports = {
  publishMessage,
};

some-where.js

messageQueue.publishMessage('hello world')

关于node.js - Rabbit MQ amqplib错误 "No channels left to allocate",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51336128/

相关文章:

mysql - 什么是呈现时间序列数据的首选方法

node.js - Meteor: Unexpected mongo exit code 14. Restarting.Can't start mongo server

node.js - Node 中的 Jest 安装出现错误 gyp ERR!堆栈错误 : EACCES: permission denied, rmdir 'build'

design-patterns - 微服务架构 - 当订单无关紧要时通过服务传递消息

SpringAMQP RabbitMQ如何在没有Exchange的情况下直接发送到队列

java - 如何在Windows上启用rabbitmq的管理控制台?

node.js - 使用 Azure Easytables 和 Node.js 后端时出现 HTTP 500 错误

python - celery 结果,不起作用

rabbitmq - 如何通过相关 ID 将 RabbitMq 消息聚合为单个消息

javascript - NodeJS : Searching for specific string with fs. readFile() 多个文件