I'm using amqplib
in a nodejs application. There's some heavy processing on the front-end side inducing some delay in the reception of rabbitmq messages. When monitoring my queues with rabbitmqctl list_queues
, the number of messages waiting to be processed never stops climbing.
Is there a way to setup my channel so as to drop messages when the queue has a given number of messages waiting?
Below is how I setup my channel:
amqp.connect('amqp://localhost')
.then(conn => {
return conn.createChannel();
})
.then(channel => {
channel.assertQueue(q, {durable: false, autoDelete: true});
channel.prefetch(1);
channel.bindQueue(q.queue, topic, 'myroutingkey');
return channel.consume(q, (msg) => {
mycallback(channel, msg);
});
})
.then(() => {})
.catch(err => {});
Thanks to Jørgen's pointer to the rabbitmq doc, I found the equivalent in the amqplib doc, and I can enforce the dropping behaviour by adding maxLength: 1
to my queue settings
channel.assertQueue(q, {durable: false, autoDelete: true, maxLength: 1});