Skip to content

Instantly share code, notes, and snippets.

@noonedeadpunk
Last active December 27, 2019 16:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save noonedeadpunk/4a22b2dcc3b22fcc295445ed18c66247 to your computer and use it in GitHub Desktop.
Save noonedeadpunk/4a22b2dcc3b22fcc295445ed18c66247 to your computer and use it in GitHub Desktop.
Drop rabbitmq queues without consumers
### Classis FOR ###
vhost="/"; for queue in `rabbitmqctl list_queues name consumers -p $vhost --formatter csv`; do name=`echo $queue | cut -d "," -f 1 | tr -d '"'`; consumers=`echo $queue | cut -d "," -f 2 | tr -d '"'`; if [[ "$consumers" == "0" ]]; then rabbitmqctl delete_queue $name -p $vhost ; fi; done
### Faster XARGS ###
vhost="/"; rabbitmqctl list_queues name consumers -p $vhost --formatter csv | xargs -P 20 -I {} env vhost=$vhost bash -c 'name=$(echo {} | cut -d "," -f 1); consumers=$(echo {} | cut -d "," -f 2); if [[ "$consumers" != "0" ]]; then rabbitmqctl delete_queue $name -p $vhost ; fi'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment