postwait / node-amqp

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

Dynamically update prefetchCount #311

Open chad-oliver opened 10 years ago

chad-oliver commented 10 years ago

Is it possible to dynamically update the prefetchCount after you have subscribed to a queue? I have a need to adjust the prefetchCount based on downstream capacity.

barshow commented 10 years ago

you can with https://github.com/dropbox/amqp-coffee

glenjamin commented 10 years ago

It's not the cleanest, but you can do it, see https://github.com/postwait/node-amqp/blob/master/lib/queue.js#L51

var methods = require('amqp/lib/definitions').methods;
queue.connection._sendMethod(queue.channel, methods.basicQos,
        { reserved1: 0
        , prefetchSize: 0
        , prefetchCount: 1234
        , global: false
        });

It wouldn't be too hard to extract this method and add it to the queue prototype if there's an appetite for it.