0

每次我想使用队列“queue = connection.queue(...)”时,我真的需要实例化它吗?

服务器(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)
      //res.send(msg.data);
      queue.unsubscribe(ctag);
     res.redirect('/home');

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

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

如果queue = connection.queue(...);用服务端实例化,第一个使用队列的请求是成功的,但是下面的请求会抛出错误:

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

1 回答 1

1

对于一个 rpc 示例,它可以保持回复队列挂起,请查看如何在 Rabbit.js 上创建 REP/REQ

于 2012-05-18T09:56:32.573 回答