0

I run RabbitMQ image in docker-compose like this:

version: '2.2'

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

Then connect to via other Node.js app like this:

const amqp = require('amqplib');

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

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

It works fine but few questions:

  1. Why console.log(this._connection.blocked); outputs undefined;
  2. How do I detect that connection is already blocked when I start the client? I.e. service is out of resources and RabbitMA manager says that connection is in 'blocking' state right after it connected. This is why this._connection.on("blocked" doesn't work

enter image description here

4

1 回答 1

0

I have check the document and source of amqplib, register event callback is the only way to receive Blocked Connection Notifications, amqplib connection hasn't use some member variable to show blocking state.

From offical document, I am not sure whether this mean there is no notification when you connect to an already blocked server:

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

于 2019-06-01T04:11:08.390 回答