developer_009
developer_009

Reputation: 367

RabbitMQ auto-delete queues with timeouts

I have a k8s service, using rabbitMQ as message broker. I want to be able to delete a specific queue if the service deployment which may have multiple pods is stopped.

Reading the documentation RabbitMq Queues Docs I found that the best case for me in this case is to use the auto-deleted property of the queue.

Is there any option so the auto-deleted queue will not be deleted immediately after the clients are disconnected, instead to wait some seconds to wait for reconnection ?

Upvotes: 3

Views: 874

Answers (1)

learner
learner

Reputation: 950

Set expires policy on queues as per https://www.rabbitmq.com/ttl.html#queue-ttl.

rabbitmqctl set_policy ZeroConsumerQueExpiry "myProjectQueue.*" '{"expires":10000}' --apply-to queues

It will support your use case in following ways

  1. waits for reconnection for 10 seconds
  2. Auto Deletes Queue if no consumer connects or reconnects for 10 seconds

There will be a difference in using auto-delete vs expires policy

  1. Auto-delete will not delete an inactive queue unless a consumer connects to it
  2. expires policy will will delete the queue whether a consumer has ever connected or never connected. Only catch is that within if there is no activity for given milliseconds, the queue gets deleted.

Upvotes: 0

Related Questions