Archive

Archive for June, 2012

Closing orphaned RabbitMQ connections

June 29, 2012 Leave a comment

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: , , ,