How can I get unacked messages count of a RabbitMQ queue using NodeJs (amqplib)

881 Views Asked by At

How can I get unacked messages count of a RabbitMQ queue using NodeJs (amqplib).

we can easily get the total message count of a queue using checkQueue or assertQueue method.

I have many dynamic queues and those queues are consumed by multiple consumers, I want to delete the queue after the process of all jobs.

The problem is when a consumer attached to a queue then I am checking the message count is zero or not, if the message count is zero then I deletes the queue, but at that time if that queue has some unacked messages but the message count is zero then how can I handle that.

1

There are 1 best solutions below

0
On

In this case you can set auto-delete flag to queue on create and check queue size on consume.

When queue size will be 0 you just stop consume process for this consumer and close channel for this consumer. When all consumers close their channels queue will be auto-deleted by RabbitMQ.