I want to check whether a particular RabbitMQ exchange exists or not from node.js. I am using Mocha as test framework. I have written code for the same but my expectation seems to be incorrect. I expect exchange variable to have a value of undefined when there is no exchange, but that is not the case. I am using amqp module for interacting with RabbitMQ. The following is the code:
var should = require('should');
var amqp = require('amqp');
//Configuration
var amqpConnectionDetails = {
'host':'localhost',
'port':5672,
'login':'guest',
'password':'guest'
};
describe('AMQP Objects', function(){
describe('Exchanges', function(){
it('There should exist an exchange', function(done){
var amqpConnection = amqp.createConnection(amqpConnectionDetails);
amqpConnection.on('ready', function(){
var exchange = amqpConnection.exchange('some_exchange', {'passive':true, 'noDeclare':true});
exchange.should.not.be.equal(undefined);
exchange.should.not.be.equal(null);
done();
});
});
});
});
What is the right way to check for the existence of an exchange?
Thanks.