Function
This API is used to create an exchange.
URI
PUT /v2/rabbitmq/{project_id}/instances/{instance_id}/vhosts/{vhost}/exchanges
Table 1 Path Parameters | Parameter | Mandatory | Type | Description |
| project_id | Yes | String | Project ID. For details, see Obtaining a Project ID. |
| instance_id | Yes | String | Instance ID. |
| vhost | Yes | String | Virtual host name. If the name contains a slash (/), replace it with __F_SLASH__. Otherwise, the calling fails. For example, if the virtual host name is /test, the input parameter is __F_SLASH__test. |
Request Parameters
Table 2 Request body parameters | Parameter | Mandatory | Type | Description |
| name | Yes | String | Definition Exchange name. Constraints -
The value can only include letters, digits, periods (.), percent signs (%), vertical bars (|), hyphens (-), underscores (_), and slashes (/). -
Version 3.x.x: The range is 2 to 128 characters. -
Version AMQP-0-9-1: The range is 2 to 64 characters. When calculating the length of an exchange name for an AMQP-0-9-1 instance, each special character (period, percent sign, vertical bar, and slash) counts as three characters. Range N/A Default Value N/A |
| type | Yes | String | Definition x-delayed-type Constraints N/A Range -
direct: Exchanges route messages to matching queues based on the routing keys. -
fanout: Exchanges route messages to all bound queues. -
topic: Exchanges route messages to queues based on routing key wildcard matching. -
headers: Exchanges are related to the message headers. Routing keys are not used. Exchanges route messages based on matching between key-value pairs in the message headers and the binding (a key-value pair). Default Value N/A |
| durable | No | Boolean | Indicates whether to enable data persistence (The AMQP version does not have this parameter because data persistence is enabled by default). |
| auto_delete | Yes | Boolean | Indicates whether to enable automatic deletion. |
| internal | No | Boolean | Internal exchange (The AMQP version does not support this parameter). |
| arguments | No | Object | Parameter list. |
Response Parameters
Status code: 200
Table 3 Response body parameters | Parameter | Type | Description |
| durable | Boolean | Indicates whether data persistence is enabled. |
| default | Boolean | Indicates whether the exchange is default. |
| internal | Boolean | Indicates whether the exchange is internal. |
| arguments | Object | Parameter list. |
| name | String | Exchange name. |
| auto_delete | Boolean | Indicates whether automatic deletion is enabled. |
| type | String | Definition x-delayed-type Range -
direct: Exchanges route messages to matching queues based on the routing keys. -
fanout: Exchanges route messages to all bound queues. -
topic: Exchanges route messages to queues based on routing key wildcard matching. -
headers: Exchanges are related to the message headers. Routing keys are not used. Exchanges route messages based on matching between key-value pairs in the message headers and the binding (a key-value pair). |
| vhost | String | Virtual host. |
Example Requests
Creating an exchange
POST /v2/rabbitmq/{project_id}/instances/{instance_id}/vhosts/{vhost}/exchanges
{
"name" : "exchange_name_demo",
"type" : "direct",
"durable" : true,
"auto_delete" : false,
"internal" : false
} Example Responses
Status code: 200
Exchange created.
{
"name" : "exchange_name_demo",
"type" : "direct",
"durable" : true,
"auto_delete" : false,
"internal" : false,
"vhost" : "default",
"arguments" : { }
} Status Codes
| Status Code | Description |
| 200 | Exchange created. |