How to keep a queue active after a request is made in node.js amqp?


Do I really need to instantiate the queue "queue = connection.queue(...)" every time I want to use it?

Server (node.js):

 queue = connection.queue('incoming', { // <--- DO I REALLY NEED THAT FOR EVERY REQUEST?
        durable : true,
        exclusive : false }, function() {});

 queue.subscribe(function(msg) {
      // Unsubcribe here. Maybe there is something like a once listener?
     console.log("RECEIVED: "+msg)

   }).addCallback(function(ok) { ctag = ok.consumerTag; });

   exchange.publish('msg_queue', 'functional!', {  // request
      replyTo: 'incoming'

If queue = connection.queue(...); is instantiated with the server, the first request using the queue is successful, but the followings requests throw an error:

Error: NOT_FOUND - no queue 'incoming' in vhost '/'
at Queue._onMethod (/Users/cassiomelo/code/cubix/cubix_nodejs/node_modules/amqp/amqp.js:1720:15)
Problem courtesy of: ksiomelo


For an rpc example ,that keeps the reply queue hanging around, please have a look at How to create REP/REQ on Rabbit.js

Solution courtesy of: kmpm


There is currently no discussion for this recipe.

This recipe can be found in it's original form on Stack Over Flow.