2

Does anyone have an example of creating a topic exchange in Node-amqp? I've already gone through https://github.com/rabbitmq/rabbitmq-tutorials/tree/master/javascript-nodejs but unfortunately it doesn't recreate tutorials 4+ from the RabbitMQ website.

RachelD
  • 4,072
  • 9
  • 40
  • 68

1 Answers1

4

This might be an over simplistic answer but at a basic level it's doable like this...

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

Once you have run the above, the exchange should now be visible on your rabbitMQ instance

$ 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.
James Butler
  • 3,852
  • 1
  • 26
  • 38
  • Thanks! That looks very similar to what I ended up with. Wish they could have just given us a good example :) – RachelD Aug 30 '13 at 17:42
  • It looks like they ran out of steam by the time they got to the node examples but there is github repo if you feel like making some pull requests :: https://github.com/rabbitmq/rabbitmq-tutorials/tree/master/javascript-nodejs It's also worth bearing in mind that the general attitude seems to be using zeroMQ instead of rabbitMQ (they are slightly different beasts though) – James Butler Sep 02 '13 at 08:49