There are different options of how to close connections in RabbitMQ. The web based UI can be used via the RabbitMQ Management Interface, a scripts can be used via rabbitmqadmin or HTTP API curl. A script is recommended if you need to close multiple connections.
Close connections via:
RabbitMQ Management Interface
A connection can be closed via the RabbitMQ Management Interface. Enter the connection tab and press on the connection. Go to the bottom of the page and press Close this connection, followed by pressing Force Close.
rabbitmqadmin
The management plugin ships with a command line tool rabbitmqadmin which can perform the same actions as the web-based UI (the RabbitMQ management interface).
Close one connection:
$ rabbitmqadmin -q close connection name=name_of_connection
In CloudAMQP the management plugin is assigned port 443 and the ssl flag has to be used, as shown below.
$ rabbitmqadmin --host=HOST --port=443 --ssl --vhost=VHOST --username=USERNAME --password=PASSWORD -q close connection name=name_of_connection
Close all connections
The script below will:
- Add all connections into a file called c.txt. You can open the file and remove the connections from the file that you would like to keep.
- Loop the list of connections and for each connection close it.
$ rabbitmqadmin -f tsv -q list connections name > c.txt
$ while read -r name; do rabbitmqadmin -q close connection name="${name}"; done < c.txt
In CloudAMQP the management plugin is assigned port 443 and the ssl flag has to be used, as shown below.
$ rabbitmqadmin --host=HOST --port=443 --ssl --vhost=VHOST --username=USERNAME --password=PASSWORD -f tsv -q list connections name > c.txt
$ while read -r name; do rabbitmqadmin -q --host=HOST --port=443 --ssl --vhost=VHOST --username=USERNAME --password=PASSWORD -q close connection name="${name}"; done < c.txt
HTTP API, curl
The RabbitMQ Management plugin provides an HTTP-based API for management and monitoring of your RabbitMQ server. In CloudAMQP the management plugin is assigned port 443 and SSL has to be used.
curl -i -XDELETE https://USERNAME:PASSWORD@HOST/api/connections/VHOST/CONNECTION_NAME
rabbitmqctl
The RabbitMQ CLI provides a way (since version 3.7.0) to close all connections for a vhost, or even the whole server. See all arguments in the rabbitmqctl documentation
rabbitmqctl close_all_connections --vhost $VHOST "Closed by request"
Please email us at contact@cloudamqp.com if you have any suggestions, questions or feedback.