无法使用node-amqp中的exchange发送消息

时间:2013-05-09 01:35:27

标签: javascript node.js amqp node-amqp

这是我的代码:

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看到rabbitmqctl list_exchanges,但testqueue没有rabbitmqctl list_queues,有什么不对?

1 个答案:

答案 0 :(得分:0)

你必须先定义它。

connection.queue('testqueue', { durable: true })