amqp 客户端不显示 RabbitMQ 服务器连接被阻止

amqp client doesn't show that RabbitMQ server connection is blocked

我运行 RabbitMQ 镜像在docker-这样写:

version: '2.2'

services:
  rabbitmq:
    networks:
      - private
    image: rabbitmq:3.8.0-beta.3-management
    ports: 
      - 15672:15672

然后像这样通过其他 Node.js 应用程序连接:

const amqp = require('amqplib');

this._connection = await amqp.connect(xxxxxx);
console.log(this._connection.blocked);

this._connection.on("blocked", (reason) => {
    console.log("!!!! connection blocked");
});

它工作正常但问题很少:

  1. 为什么 console.log(this._connection.blocked); 输出 undefined;
  2. 如何在启动客户端时检测到连接已被阻止? IE。服务资源不足,RabbitMA 经理说连接在连接后立即处于 'blocking' 状态。这就是 this._connection.on("blocked" 不起作用的原因

我检查了amqplib的document and source,注册事件回调是接收的唯一途径Blocked Connection Notifications,amqplib连接没有使用一些成员变量来显示阻塞状态。

From offical document,我不确定这是否意味着当您连接到已被阻止的服务器时没有通知:

If before the connections are unblocked the node also starts running low on disk space, another connection.blocked will not be sent