postwait / node-amqp

[UNMAINTAINED] node-amqp is an AMQP client for nodejs
MIT License
1.69k stars 357 forks source link

Can not unsubscribe #261

Closed crzidea closed 10 years ago

crzidea commented 10 years ago

This is my code:

 var conn = amqp.createConnection({
     port: 5673
 });
var ctag;
 conn.on('ready', function() {
     console.log('consumer ready');
     var queue = conn.queue('topic1', {
         durable: true
     }, addQueue);
     var queue = conn.queue('topic2', {
         durable: true
     }, addQueue);
     setTimeout(function() {
         console.log(ctag);
         queue.unsubscribe(ctag)
     }, 3000);
 })

 function addQueue(q) {
     console.log('queue added')
     q.subscribe({
         ack: true
     }, function(message) {
         console.log(message.data.toString());
         q.shift();
     }).addCallback(function(ok) {
         if (q.name == 'topic2') {
             ctag = ok.consumerTag;
             console.log('consumerTag:', ctag);
         }
     })
 }

It can receive message after running. But error's shown after 3 seconds:

Error: Unmatched field {"name":"consumerTag","domain":"shortstr"}
    at serializeFields (/home/lixin/test/rabbitmq/node_modules/amqp/amqp.js:781:17)
    at Connection._sendMethod (/home/lixin/test/rabbitmq/node_modules/amqp/amqp.js:1236:3)
    at Object.cb (/home/lixin/test/rabbitmq/node_modules/amqp/amqp.js:1648:21)
    at Queue.Channel._tasksFlush (/home/lixin/test/rabbitmq/node_modules/amqp/amqp.js:1540:10)
    at Queue.Channel._taskPush (/home/lixin/test/rabbitmq/node_modules/amqp/amqp.js:1530:8)
    at Queue.unsubscribe (/home/lixin/test/rabbitmq/node_modules/amqp/amqp.js:1647:15)
    at null._onTimeout (/home/lixin/test/rabbitmq/index.js:20:9)
    at Timer.listOnTimeout [as ontimeout] (timers.js:110:15)

Helppppppppp!

crzidea commented 10 years ago

I'm sorry for using v0.1.7. Nothing goes wrong with v0.1.8 now.