RabbitMQ: get messages from a queue with curl and the Management API
Codemia Knowledge Hub ·
To read messages from a RabbitMQ queue with curl, send a POST request to the Management API endpoint /api/queues/<vhost>/<queue>/get with a JSON body that sets count, ackmode and encoding. The Management API is RabbitMQ's HTTP interface for managing and inspecting the server, which makes it usable from shell scripts or systems that do not speak AMQP.
What you need first
- RabbitMQ Server installed and running.
- The management plugin enabled (
rabbitmq-plugins enable rabbitmq_management). It serves the HTTP API, by default on port 15672. - Valid credentials (username and password).
For context: messages are published to exchanges, which route them to queues (buffers that store messages) based on routing rules. The API reads from the queue.
The endpoint
-u username:passwordauthenticates with your RabbitMQ credentials.http://server_name:15672is the Management API URL. Replaceserver_namewith the hostname or IP address of your server./api/queues/vhost/queue_name/getis the endpoint. Replacevhostwith your virtual host andqueue_namewith your queue.
Fetching messages with a POST request
Although the endpoint ends in /get, retrieving messages is a POST request in which you describe how to interact with the queue:
-X POSTmakes it a POST request.-H "Content-Type: application/json"says the body is JSON.-dsends the JSON payload. In it,countsets how many messages to retrieve,ackmodesets how they are acknowledged, andencodingsets the encoding of the response.
The payload fields:
count: number of messages to fetch.ackmode: how messages are acknowledged (for example,ack_requeue_trueputs them back on the queue).encoding: encoding of the output (autolets RabbitMQ choose).
| Option | Description |
-u | Authentication with username and password. |
-X POST | Specifies the request type as POST. |
-H | Sets header values (e.g., Content-Type). |
-d | The JSON payload of the POST request. |
Security, load and error handling
- Security: use HTTPS for communication with the server where possible.
- Performance: frequent calls to retrieve messages can affect server performance, so use them sparingly.
- Errors: handle HTTP and API errors in your scripts.
Why use curl instead of an AMQP client
The Management API turns queue operations into plain HTTP calls. That lets you inspect or pull messages from shell scripts, cron jobs, or systems that do not support AMQP or the other protocols RabbitMQ speaks natively, without writing a consumer.
Related reading
- RabbitMQ - Get total count of messages enqueued
- RabbitMQ - How many queues can RabbitMQ handle on a single server?
- RabbitMQ - Message order of delivery
- Rabbitmq - multiple binding ( routing keys ) to a single queue
- RabbitMQ C# API Event based Message Consumption
- RabbitMQ Declare Exchange from Terminal - Access refused /api/exchanges/
- RabbitMQ - purge a queue from all of its unacked messages
- Rabbitmq - queues state shows as ''running'' , GUI shows status as IDLE
System design interview problems on this topic
- Design a Distributed Messaging System: solution and walkthrough
- Design a Log Collection and Analysis System: solution and walkthrough
- Design an Ad Click Aggregation System: solution and walkthrough
- Design a Webhook Notification Service: solution and walkthrough

System Design Fundamentals
Build a strong foundation in designing scalable, reliable distributed systems.
View the courseSystem Design practice on Codemia
Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.