Publish to RabbitMQ queue with HTTP API
System Design practice on Codemia
Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.
RabbitMQ is a widely utilized open-source message broker that supports a variety of messaging protocols. One of the primary ways to interact with RabbitMQ is through AMQP (Advanced Message Queuing Protocol), but it can also be extended to support accessing queues via HTTP using the RabbitMQ HTTP API. This API is particularly useful for environments where AMQP is not ideal or if integration with web technologies is required.
The RabbitMQ HTTP API allows you to manage exchanges, queues, bindings, and more, through standard HTTP requests. This means you can publish messages, read queue status, and manipulate the broker's objects from any application that can send HTTP requests.
How to Publish to a RabbitMQ Queue Using HTTP API
Prerequisites
Before you publish messages to a RabbitMQ queue using the HTTP API, ensure you meet the following prerequisites:
- RabbitMQ Server: Installed and running.
- Management Plugin: The RabbitMQ management plugin must be enabled because it provides the HTTP-based API.
Configuration
You must first configure your RabbitMQ server to accept and authenticate HTTP API requests. This involves enabling the management plugin if it's not already active. You can enable the plugin with the following command:
This plugin starts a web server by default on port 15672 and the HTTP API will be accessible at http://[your-rabbitmq-host]:15672/api/.
Authentication
To use the HTTP API, you will need credentials (username and password). These are the same credentials you use to access the RabbitMQ management interface.
Publishing a Message
To publish a message via the HTTP API, you need to make a POST request to the appropriate URL and with the correct payload. The endpoint for publishing a message is:
Here, replace [your-rabbitmq-host], [vhost], and [exchange_name] with your server details and the appropriate virtual host and exchange names.
Example JSON Payload
In this payload:
propertiescan contain various message attributes likecontent_type,delivery_mode, etc.routing_keyspecifies the queue or routing path for the message.payloadis the actual message you wish to send.payload_encodingtells RabbitMQ how to interpret the payload, typical values arestringorbase64.
Example cURL Command
Replace user and password with your RabbitMQ credentials. This command sends a simple message to the my_queue on the default exchange.
Table of Key Components
Here is a summary of the key components and parameters for publishing messages via the HTTP API:
| Component | Description | Example |
| Host | RabbitMQ server URL | localhost:15672 |
| Exchange Name | Name of the exchange | amq.default |
| vHost | Virtual host | %2f for the root |
| Routing Key | Queue or routing path | my_queue |
| Payload | Message content | my message |
| Payload Encoding | Encoding of the payload | string |
| Content-Type | Type of content being sent in the request | application/json |
Additional Considerations
- Security: Ensure that your RabbitMQ is secured, especially when accessible over the network. Consider using HTTPS for the HTTP API to encrypt the data in transit.
- Error Handling: Implement proper error handling around your HTTP requests to manage failed requests or bad responses from the API.
- Performance: HTTP API might not match the performance of the direct AMQP operations, so use it according to the specific needs and test accordingly.
This overview gives you an entry point into publishing messages to RabbitMQ using the HTTP API, which is a powerful tool for integrating RabbitMQ with web technologies and environments where AMQP might not be feasible.
Related reading
- Publishing to the default rabbitmq exchange using the http api
- Publish/Subscribe reliable messaging Redis VS RabbitMQ
- Publish/Subscribe samples with RabbitMQ in .NET
- Purpose and difference b/w Apache camel Kafka consumer URI option consumerStreams vs consumersCount
- Pushing to Git returning Error Code 403 fatal HTTP request failed
- Pushing to Git returning Error Code 403 fatal HTTP request failed
- Purpose of statestore and changelog topic in kafka streams?
- Push Messages from AWS Lambda to Kafka

System Design Fundamentals
Build a strong foundation in designing scalable, reliable distributed systems.
View the courseTrack what you have practised
A free account saves your progress, solutions and study plan across every problem on Codemia.
System Design practice on Codemia
Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.