Home > RabbitMQ > Closing orphaned RabbitMQ connections

Closing orphaned RabbitMQ connections

I’ve been working with RabbitMQ a lot lately, and one problem I’ve run into is that occasionally during the course of development, something goes wrong and we leave a lot of connections open.  Enabling the heartbeat will take care of this for the most part, but if someone didn’t do that, you can end up with connections left open on the server.  Here is a quick shell script to close all the connections from a particular IP address:


#!/bin/sh
peerToDisconnect=1.2.3.4
for c in `rabbitmqctl list_connections peer_address pid | grep $peerToDisconnect`;
do
if [ $c != $peerToDisconnect ];
then rabbitmqctl close_connection $c "Orphaned - disconnecting";
fi;
done

Advertisements
Categories: RabbitMQ Tags: , , ,
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: