【问题标题】:Cannot send message using exchange in node-amqp无法使用 node-amqp 中的交换发送消息
【发布时间】:2013-05-09 01:35:26
【问题描述】:

这是我的代码:

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); 
      });
    });
  });
});

我正在使用 node 0.10.2 和 node-amqp 0.1.6,

我可以看到textexchange by rabbitmqctl list_exchanges,但是没有testqueue by rabbitmqctl list_queues,怎么了?

【问题讨论】:

    标签: javascript node.js amqp node-amqp


    【解决方案1】:

    你必须先定义它。

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

    【讨论】:

    • 我已经更新了源代码。我现在可以通过rabbitmqctl list_queues 看到testqueue,但testqueue 中没有消息。
    • 如果您不使用“直接”交换,则必须将交换绑定到队列:queue.bind(exchange, routing_key)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-11-09
    • 2019-08-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多