Create Exchange
This endpoint allows you to create a RabbitMQ exchange for message distribution.
Endpoint
POST /api/v1/rabbitmq/exchanges
Request
Headers
Key | Value |
---|---|
Content-Type | application/json |
Body
{
"name": "example_exchange",
"type": "direct"
}
Parameter | Type | Description | Required |
---|---|---|---|
name | string | The name of the RabbitMQ exchange. | Yes |
type | string | The type of exchange (e.g., direct , fanout , topic , or headers ). | Yes |
info
The type
of the exchange determines how messages are routed. For example:
- direct: Routes messages with a specific routing key.
- fanout: Broadcasts all messages to all queues.
- topic: Routes messages to queues based on wildcard matching of the routing key.
Response
Success Response
{
"status": 200,
"message": "Exchange created successfully",
"exchangeDetails": {
"name": "example_exchange",
"type": "direct"
}
}
Field | Type | Description |
---|---|---|
status | integer | The HTTP status code of the response. |
message | string | A message indicating the operation result. |
exchangeDetails | object | Details of the created RabbitMQ exchange. |
exchangeDetails.name | string | The name of the created exchange. |
exchangeDetails.type | string | The type of the created exchange. |
Error Response
{
"status": 400,
"error": "Invalid request: Exchange name is required"
}
Field | Type | Description |
---|---|---|
status | integer | The HTTP status code indicating the error. |
error | string | A detailed error message explaining the issue. |
Example Usage
cURL Command
curl --request POST --url http://localhost:5672/api/v1/rabbitmq/exchanges --header 'Content-Type: application/json' --data '{
"name": "example_exchange",
"type": "direct"
}'
note
Replace http://localhost:5672
with the base URL of your RabbitMQ server.