Low Orbit Flux Logo 2 F

RabbitMQ How to Close a Channel

If you have found your way to this page you are probably wondering how to close a channel in RabbitMQ. Channels should be closed when they are no longer in use. There are multiple different ways of going about doing this that we are going to cover.

To close a RabbitMQ channel do one of the following:

Programmatically Close a RabbitMQ Channel

Option 1: Close Channel

A channel can be programmatically closed like this:

channel.close()

Option 2: Close Connection

All channels on a connection will be closed when you close that connection. You can close a connection programmatically like this:

connection.close()

Using the CLI

You can close a channel from the CLI by closing it’s connection.

To close a channel using the CLI you will first need to find the channel and it’s associated connection. Use the following command to list out channels and connections.

rabbitmqctl list_channels connection

You can close the channel’s connection using the following command. You need to specify the connection which we found previously. The last parameter is a message explaining why the connection is being closed. This will be included in the error message that is output by the consumer.

rabbitmqctl close_connection "<rabbit@zippy-zap.1608598465.5412.0
>" "go away"