Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there an equivalent of "ping" for RabbitMQ? How can I diagnose whether an exchange or queue is broadcasting?

I'm using postwait/node-amqp (link) to connect to a variety of RabbitMQ exchanges and queues in our organization.

As my project has moved from dev to production I've encountered several issues with queues not being setup correctly or passwords being incorrect etc. In the latter case, it's obvious, I'll get a ECONNREFUSED error. In the first case though, I don't get any errors, just a timeout on the connect.

Given a URI like amqp://USER:[email protected] how can I determine if a queue called "FooWorkItems.Work' is accepting connections for listening? What's the bare minimum code for this, the equivalent of checking if an API is listening or a server is up and listening on the ping port?

Code:

if (this.amqpLib == null) {
    this.amqpLib = require('amqp');
  }
this.connection = this.amqpLib.createConnection({
    url: this.endpoint
  });

  this.connection.on('ready', (function(_this) {
    return function() {
      var evt, _fn, _fn1, _i, _j, _len, _len1, _ref, _ref1;
      _this.logger.info("" + _this.stepInfo + " connected to " + _this.endpoint + "; connecting to " + queueName + "  now.");
      if (_this.fullLogging) {
        _ref = ['connect', 'heartbeat', 'data'];
        _fn = function(evt) {
          return _this.connection.on(evt, function() {
            _this.logger.trace("" + _this.stepInfo + " AMQP event: " + evt);
            if (arguments != null) {
              return _this.logger.trace({
                args: arguments
              });
            }
          });
        };
        for (_i = 0, _len = _ref.length; _i < _len; _i++) {
          evt = _ref[_i];
          _fn(evt);
        }
        _ref1 = ['error', 'close', 'blocked', 'unblocked'];
        _fn1 = function(evt) {
          return _this.connection.on(evt, function() {
            if (evt !== 'close') {
              return _this.logger.error("" + _this.stepInfo + " AMQP event: " + evt);
            } else {
              return _this.logger.warn("" + _this.stepInfo + " AMQP event: " + evt);
            }
          });
        };
        for (_j = 0, _len1 = _ref1.length; _j < _len1; _j++) {
          evt = _ref1[_j];
          _fn1(evt);
        }
      }
      return _this.connection.queue(_this.queueName, {
        passive: true
      }, function(q) {
        logger.debug("" + stepInfo + " connected to queue " + queueName + ". Init complete.");
        return q.subscribe(function(message, headers, deliveryInfo, messageObject) {
          logger.trace("" + stepInfo + " recvd message");
          return logger.trace({
            headers: headers
          });
        });
      });
    };
like image 914
jcollum Avatar asked Mar 21 '16 17:03

jcollum


People also ask

How do you test RabbitMQ connectivity?

Here are the recommended steps: Make sure the node is running using rabbitmq-diagnostics status. Verify config file is correctly placed and has correct syntax/structure. Inspect listeners using rabbitmq-diagnostics listeners or the listeners section in rabbitmq-diagnostics status.

What is RabbitMQ queue and Exchange?

RabbitMQ's exchange is used as a routing mediator, to receive messages from producers and push them to message queues according to rules provided by the RabbitMQ exchange type. Each RabbitMQ exchange type uses a separate set of parameters and bindings to route the message.

How do I check messages on RabbitMQ exchange?

In rabbitmq, we can read or consume a published messages from queue using web management portal for that we need to login into rabbitmq web management portal using default (guest) credentials like as shown below.

What is Rabbitmqctl?

rabbitmqctl is the main command line tool for managing a RabbitMQ server node, together with rabbitmq-diagnostics , rabbitmq-upgrade , and others.


1 Answers

In amqp, queues and exchanges are concepts unrelated to a connection, they don't listen or broadcast, and you can't connect to those, only to a broker.

The RabbitMQ server does of course accept network connections, and the protocol defines a logical Connection on top of the transport, this connection includes a heartbeat, configurable with the heartbeat option in this library.

Like you said, connection errors, including timeouts need to be taken care off at startup, for the rest you can rely on the heartbeat, analogous to a "ping" mechanism. If the connection is interrupted and your heartbeat parameter is set, your library will simply throw an error, so there is no need for you to re-implement this.

You should also take a look a the reconnect setting in postwait/node-ampq, as it might automatically deal with some of the network failure modes.

like image 140
istepaniuk Avatar answered Oct 21 '22 03:10

istepaniuk