我想从 node.js 检查是否存在特定的 RabbitMQ 交换。我正在使用 Mocha 作为测试框架。我已经编写了相同的代码,但我的期望似乎不正确。当没有交换时,我希望交换变量的值未定义,但事实并非如此。我正在使用 amqp 模块与 RabbitMQ 进行交互。以下是代码:
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();
});
});
});
});
检查交易所是否存在的正确方法是什么?
谢谢。