RabbitMQ is a widely used message broker that facilitates communication between different services and applications. Monitoring active connections in RabbitMQ are crucial for debugging, performance analysis, and ensuring smooth operations. This tutorial shows how to get active connections in RabbitMQ.
1. CLI
RabbitMQ provides a built-in command line tool, rabbitmqctl
, which allows you to list active connections easily:
sudo rabbitmqctl -s list_connections
Example output:
test 127.0.0.1 51804 running
test 127.0.0.1 38724 running
Here, the output displays the connection name, IP address, port, and connection state.
2. HTTP API
RabbitMQ also exposes an HTTP API that allows you to retrieve active connections programmatically. You can use curl
to query the API as follows:
curl -u guest:guest http://localhost:15672/api/connections
The part of the output:
[
{
...
"name": "127.0.0.1:38724 -> 127.0.0.1:5672",
"peer_port": 38724,
"state": "running"
},
{
...
"name": "127.0.0.1:51804 -> 127.0.0.1:5672",
"peer_port": 51804,
"state": "running"
}
]
The API response provides detailed information about each connection.
Leave a Comment
Cancel reply