这是我的代码:
var amqp = require('amqp');
var connection = amqp.createConnection( { host: 'localhost' }, { defaultExchangeName: 'testexchange' });
connection.on('ready', function () {
console.log('Connected to rabbitmq');
var exchange = connection.exchange('testexchange', {confirm:true}, function(exch){
console.log('Created exchange: ' + exch.name);
var queue = connection.queue('testqueue', { durable: true }, function(q) {
exch.publish('testqueue', {a:1}, {}, function(error) {
console.log(error);
});
});
});
});
我使用节点0.10.2和node-amqp 0.1.6,
我可以看到textexchange
by rabbitmqctl list_exchanges
,但是没有testqueue
by rabbitmqctl list_queues
,怎么了?
你必须先定义它。
connection.queue('testqueue', { durable: true })