How to gracefully delete a queue from rabbit when all consumers are disconnected?

255 views
Skip to first unread message

Ariel B

unread,
Jul 11, 2019, 5:25:03 PM7/11/19
to rabbitmq-users
Basically i would like to achieve the following -
I have multiple consumers on the same queue, consumers can increase and decrease.
When last consumer shuts down, i need to unbind the queue, move away all msgs so they wont be lost, and safely delete the queue.

Auto delete get rids of the q and the messages.
Any custom hook, or anyway to know besides a different watcher process when all subscribers got disconnected?

Stuart Johnston

unread,
Jul 12, 2019, 5:36:31 AM7/12/19
to rabbitmq-users
You should get all the logical built into your consumers/publishers and then use rabbitMQ to delete the queue and messages as intended else you will be supporting a watcher process as you described 

Why are you deleting the queue ? Do they declare the same queue name or a different one ? If so just put a TTL on the messages that are published and leave the queue in place

Ariel B

unread,
Jul 13, 2019, 2:27:26 AM7/13/19
to rabbitmq-users
Im building a sharded system, that can increase when another shard is needed, and decrease dynamically aswell.
I dont want a ttl to the msgs as i dont wanna lose them.

Ive found a decent solution - as im under kubernetes, ill make each shard a stateful set deployment, where the first pod is responsible in handling the queue.
When the pod X-0 is created, ill create the queue, bind it to the exchange (consistent hash) and thats it.

When the deployment needs to be removed, ill run a drainer pod - and use this:
https://medium.com/@marko.luksa/graceful-scaledown-of-stateful-apps-in-kubernetes-2205fc556ba9

Then ill unbind the queue, move the msgs away back to the exchange, and delete the q.

Ariel B

unread,
Jul 13, 2019, 2:28:49 AM7/13/19
to rabbitmq-users
Ill run the drainer pod logic when last pod is dying (X-0)
Reply all
Reply to author
Forward
0 new messages