I use postwait/node-amqp( link ) to connect to various exchanges and queues of RabbitMQ in our organization.
As my project moved from dev to production, I ran into several issues related to incorrect queuing or incorrect passwords, etc. In the latter case, obviously, I will get an ECONNREFUSED error. In the first case, however, I do not get any errors, just a timeout when connecting.
Given a URI, such as amqp://USER:PASS@messaging.abc.xyz.comhow can I determine if the "FooWorkItems.Work" queue accepts connections for listening? What is the minimum code for this, the equivalent of checking if the API is listening or the server is connected and listening on the ping port?
The 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
});
});
});
};