My code snippets

When you have a lot of unwanted queues/exchanges on rabbitmq, either by legacy or spawned by a bad configuration, deleting them by hand is very painful. The rabbitmq management plugin offers an API where you can delete all those queues automatically, here is the command I ended up with:

rabbitmqctl list_queues -p rabbit |\
grep -v "top\|medium\|low" |\
tr "[:blank:]" " " |\
cut -d " " -f 1 |\
xargs -I{} curl -i -u guest:guest -H "content-type:application/json" -XDELETE http://localhost:15672/api/queues/rabbit/{}

Let’s break it down:

This same command can also be applied to delete exchanges by changing the initial command to rabbitmqctl list_exchanges.