Node-amqp主题交换示例

时间:2013-07-30 19:29:12

标签: node.js node-amqp

有没有人有一个在Node-amqp中创建主题交换的例子?我已经完成了https://github.com/rabbitmq/rabbitmq-tutorials/tree/master/javascript-nodejs但不幸的是它没有从RabbitMQ网站重新创建教程4+。

1 个答案:

答案 0 :(得分:4)

这可能是一个过于简单的答案,但在基本层面上它是可行的......

var amqp = require('amqp');
var connection = amqp.createConnection({ host: '127.0.0.1' });
connection.on('ready', function () {
  var exchange = connection.exchange('my-super-xchange', {type: 'topic'});
  exchange.on('open', function(){
    console.log('Lets do this!');
  })
})

运行上述内容后,现在应该可以在rabbitMQ实例上看到交换

$ rabbitmqctl list_exchanges
Listing exchanges ...
    direct
amq.direct  direct
amq.fanout  fanout
amq.headers headers
amq.match   headers
amq.rabbitmq.log    topic
amq.rabbitmq.trace  topic
amq.topic   topic
dingo   topic
my-super-xchange    topic
...done.