Automatically delete empty queues

1,836 views
Skip to first unread message

Ivan Yurchenko

unread,
Feb 13, 2015, 10:40:10 AM2/13/15
to rabbitm...@googlegroups.com
Hello.

I have a bunch of queues which are used for delayed message delivery (x-message-ttl). I want them to be deleted from time to time but only if they are empty.

I've considered setting auto-delete to true when declare a queue, but this automatic deletion works when the consumer count reduces to zero from a positive number, and the queues never have a single consumer.

AMQP have an option if-empty for queue's delete. So it's possible to do what I want from a piece of code run by cron. But is there a way to do this without writing code, via Rabbit's REST API, rabbitmqadmin etc?

Thank you,

- Ivan.

Michael Klishin

unread,
Feb 13, 2015, 10:53:15 AM2/13/15
to Ivan Yurchenko, rabbitm...@googlegroups.com
Since queue TTL presumably is not good enough for you, I'm afraid an external tool or plugin would be necessary.

MK
--
You received this message because you are subscribed to the Google Groups "rabbitmq-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rabbitmq-user...@googlegroups.com.
To post to this group, send email to rabbitm...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Simon MacMullen

unread,
Feb 13, 2015, 11:06:57 AM2/13/15
to Ivan Yurchenko, rabbitm...@googlegroups.com
On 13/02/15 15:40, Ivan Yurchenko wrote:
> AMQP have an option if-empty for queue's delete. So it's possible to do
> what I want from a piece of code run by cron. But is there a way to do
> this without writing code, via Rabbit's REST API, rabbitmqadmin etc?

There is no way to do this in the HTTP API as yet, although we do have a
bug open for it.

You can (as always!) use rabbitmqctl eval though:

$ rabbitmqctl eval 'IfUnused = false, IfEmpty = true, MatchRegex =
<<"^prefix-">>, [rabbit_amqqueue:delete(Q, IfUnused, IfEmpty) || Q <-
rabbit_amqqueue:list(), re:run(element(4, element(2, Q)), MatchRegex)
=/= nomatch ].'

The above will delete all empty queues in all vhosts that have a name
beginning with "prefix-". You can edit the variables IfUnused, IfEmpty,
and MatchRegex to taste.

Cheers, Simon

Ivan Yurchenko

unread,
Feb 13, 2015, 12:27:52 PM2/13/15
to rabbitm...@googlegroups.com, ivan0yu...@gmail.com
[Sorry, some replies were accidentally private. Summary:]

Simon, thank you for rabbitmqctl eval.

If I redeclare a queue every time I post a message and set the queue TTL greater than the message TTL (in this redeclaration), the queue will outlive any message that will be put in it. Thank you Michael.

- Ivan

Simon MacMullen

unread,
Feb 13, 2015, 12:38:35 PM2/13/15
to Ivan Yurchenko, rabbitm...@googlegroups.com
On 13/02/15 16:06, Simon MacMullen wrote:
> There is no way to do this in the HTTP API as yet, although we do have a
> bug open for it.

Upon looking at this further, it turns out to be quite simple. So now
3.5.0 will support DELETE /api/queues/%2f/my-queue?if-empty=true and soon.

Cheers, Simon

Simon MacMullen

unread,
Feb 13, 2015, 12:39:56 PM2/13/15
to rabbitm...@googlegroups.com
On 13/02/15 17:38, Simon MacMullen wrote:
> and soon

"and so on". Meaning if-empty and if-unused for queues, and if-unused
for exchanges.

Cheers, Simon

Nikhil Khatwani

unread,
Aug 16, 2016, 3:36:46 AM8/16/16
to rabbitmq-users, si...@rabbitmq.com
Hi Simon,

I would like to delete all unused and empty mqtt queues. While running the above "rabbitmqctl eval" command to with IfUnused = true, IfEmpty = true and MatchRegex = <<"^mqtt-">>, i get [{error,in_use}]

However, if i change MatchRegex =  <<"^mqt-">> OR  IfUnused = false, it works without error. Any suggestion how to fix this?

Thanks,

Nikhil

Michael Klishin

unread,
Aug 16, 2016, 3:41:45 AM8/16/16
to rabbitm...@googlegroups.com, Nikhil Khatwani
Please  start new threads for new questions.

Thank you.

On 16 August 2016 at 10:36:54, Nikhil Khatwani (nkhat...@gmail.com) wrote:
> Hi Simon,
>
> I would like to delete all unused and empty mqtt queues. While running the
> above "rabbitmqctl eval" command to with IfUnused = true, IfEmpty = true
> and MatchRegex = <<"^*mqtt*-">>, i get [{error,in_use}]
>
> However, if i change MatchRegex = <<"^*mqt*-">> OR IfUnused = false, it
> works without error. Any suggestion how to fix this?
>
> Thanks,
>
> Nikhil
>
> On Friday, February 13, 2015 at 11:09:56 PM UTC+5:30, Simon MacMullen wrote:
> >
> > On 13/02/15 17:38, Simon MacMullen wrote:
> > > and soon
> >
> > "and so on". Meaning if-empty and if-unused for queues, and if-unused
> > for exchanges.
> >
> > Cheers, Simon
> >
>
> --
> You received this message because you are subscribed to the Google Groups "rabbitmq-users"
> group.
> To unsubscribe from this group and stop receiving emails from it, send an email to rabbitmq-user...@googlegroups.com.
> To post to this group, send an email to rabbitm...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
>

--
MK

Staff Software Engineer, Pivotal/RabbitMQ


Reply all
Reply to author
Forward
0 new messages