RabbitMQ
Message Queue
curl
API
Programming

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

bash
curl -u username:password http://server_name:15672/api/queues/vhost/queue_name/get
  • -u username:password authenticates with your RabbitMQ credentials.
  • http://server_name:15672 is the Management API URL. Replace server_name with the hostname or IP address of your server.
  • /api/queues/vhost/queue_name/get is the endpoint. Replace vhost with your virtual host and queue_name with 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:

bash
curl -u username:password -X POST http://server_name:15672/api/queues/vhost/queue_name/get \
-H "Content-Type: application/json" \
-d '{"count":5,"ackmode":"ack_requeue_true","encoding":"auto"}'
  • -X POST makes it a POST request.
  • -H "Content-Type: application/json" says the body is JSON.
  • -d sends the JSON payload. In it, count sets how many messages to retrieve, ackmode sets how they are acknowledged, and encoding sets the encoding of the response.

The payload fields:

  • count: number of messages to fetch.
  • ackmode: how messages are acknowledged (for example, ack_requeue_true puts them back on the queue).
  • encoding: encoding of the output (auto lets RabbitMQ choose).
OptionDescription
-uAuthentication with username and password.
-X POSTSpecifies the request type as POST.
-HSets header values (e.g., Content-Type).
-dThe 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.


Course
Beginner
27 lessons
10 hours
System Design Fundamentals

Build a strong foundation in designing scalable, reliable distributed systems.

View the course
System Design practice on Codemia

Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.

Practice system design