每次我想使用它时,是否真的需要实例化队列“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)