
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).
Note: When using rabbitmqadmin externally, you will need to connect to your instance with TLS and a username and password must be provided. In CloudAMQP, the management plugin is assigned port 443.
If you do not have a TLS certificate you can find one here. You can obtain all other information from the dashboard of the CloudAMQP console for your instance. It is recommended that you collect your login information into a config file, "admin.conf", shown below. You can also run the commands without the config by setting each part of the config as a flag in the command (eg. password becomes --password=PASSWORD)Rabbitmqadmin config example, ensure all text is contained in quote marks as shown:
[default]
hostname = "CLUSTER_URL"
port = 443
username = "USERNAME"
password = "PASSWORD"
vhost = "VHOST"
Close one connection:
$ rabbitmqadmin -q close connection name=CONNECTION_NAME
The example below shows how the command is used for a CloudAMQP instance.
$ rabbitmqadmin --use-tls --tls-ca-cert-file=$CERTIFICATE_LOCATION --config=$CONFIG_LOCATION -q close connection name=$CONNECTION_NAME
Close connections by user
You are able to affect connections on a user-by-user basis, using the list_of_user and close_of_user commands. You can use list_of_user to confirm which connections may be deleted and then close_of_user to delete all connections from that user
$ rabbitmqadmin -q connections list_of_user -u $CLOSE_USERNAME
$ rabbitmqadmin -q connections close_of_user -u $CLOSE_USERNAME
The example below shows how the command is used for a CloudAMQP instance.
$ rabbitmqadmin --use-tls --tls-ca-cert-file=$CERTIFICATE_LOCATION --config=$CONFIG_LOCATION -q connections list_of_user --username=$CLOSE_USERNAME
$ rabbitmqadmin --use-tls --tls-ca-cert-file=$CERTIFICATE_LOCATION --config=$CONFIG_LOCATION -q connections close_of_user --username=$CLOSE_USERNAME
Close all connections
You are able to close many/all connections at once by using a script to collect and obtain the names of all connections within an instance and then iterating through to close them one at a time.
The script below will:
- Put the output from listing all connections into a file
- Obtain the names of the connections and put them in their own file, "names.txt". In this step you can open the file and remove the names of any connections you wish to keep.
- Loop the list of connections and close each one.
If there are connections within the list that you would like to keep, you can simply remove them from the "names.txt" file to keep them.
$ rabbitmqadmin --non-interactive list connections > connections.txt
$ while read name; do
echo "$name" | awk 'BEGIN {FS=" "}; {print $1}' >>name.txt
done < connections.txt
$ while read name; do
rabbitmqadmin close connection --name "${name}"
done < name.txt
The example below shows how the script is used for a CloudAMQP instance.
$ rabbitmqadmin --use-tls --non-interactive --tls-ca-cert-file=$CERTIFICATE_LOCATION --config=$CONFIG_LOCATION list connections > connections.txt
$ while read name; do
echo "$name" | awk 'BEGIN {FS=" "}; {print $1}' >>name.txt
done < connections.txt
$ while read name; do
rabbitmqadmin --use-tls --tls-ca-cert-file=$CERTIFICATE_LOCATION --config=$CONFIG_LOCATION close connection --name "${name}"
done < name.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.