每次我想使用队列“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)