Creates an exchange.

Request parameters

Parameter Type Required Example Description
Action String Yes CreateExchange

The operation that you want to perform. Set the value to CreateExchange.

AutoDeleteState Boolean Yes false

Specifies whether to enable automatic deletion. Valid values:

  • true: enables automatic deletion. If the last queue that is bound to the exchange is unbound, the exchange is automatically deleted.
  • false: disables automatic deletion. If the last queue that is bound to the exchange is unbound, the exchange is not automatically deleted.
ExchangeName String Yes DemoExchange

The name of the exchange to be created. Take note of the following rules:

  • The name must be 1 to 255 characters in length, and can contain only letters, digits, hyphens (-), underscores (_), periods (.), and at signs (@). Excess characters are automatically discarded.
  • After the exchange is created, you cannot modify its name. If you want to modify its name, delete the exchange and create another exchange.
ExchangeType String Yes direct

The type of the exchange. Valid values:

  • DIRECT: An exchange of this type routes a message to the queue whose binding key is the same as the routing key of the message.
  • TOPIC: This type is similar to the direct exchange type. An exchange of this type routes a message to one or more queues based on the results of the fuzzy match or multi-condition match between the routing key of the message and the binding keys of the current exchange.
  • FANOUT: An exchange of this type routes all the received messages to all the queues bound to this exchange. You can use a fanout exchange to broadcast messages.
  • HEADERS: This type is similar to the direct exchange type. The only difference is that a headers exchange routes messages based on the headers attributes instead of routing keys. When you bind a headers exchange to a queue, you must configure binding attributes in the key-value format for the binding. When you send a message to a headers exchange, you must configure the headers attributes in the key-value format for the message. After a headers exchange receives a message, the exchange routes the message based on the matching results between the headers attributes of the message and the binding attributes of the bound queues.
InstanceId String Yes amqp-cn-v0h1kb9nu***

The ID of the Message Queue for RabbitMQ instance.

Internal Boolean Yes false

Specifies whether the exchange is an internal exchange. Valid values:

  • false: The exchange is not an internal exchange.
  • true: The exchange is an internal exchange.
RegionId String Yes cn-hanghzou

The ID of the region where the instance resides.

VirtualHost String Yes test

The vhost where you want to create the exchange.

AlternateExchange String No DemoAE

The alternate exchange. An alternate exchange is used to receive messages that fail to be routed to queues from the current exchange.

Response parameters

Parameter Type Example Description
RequestId String 021788F6-E50C-4BD6-9F80-66B0A19A6***

The ID of the request.

Examples

Sample requests

http(s)://amqp-open.cn-hangzhou.aliyuncs.com/?Action=CreateExchange
&AutoDeleteState=false
&ExchangeName=DemoExchange
&ExchangeType=direct
&InstanceId=amqp-cn-v0h1kb9nu***
&Internal=false
&RegionId=cn-hanghzou
&VirtualHost=test
&<Common request parameters>

Sample success responses

XML format

<CreateExchangeResponse>
      <RequestId>021788F6-E50C-4BD6-9F80-66B0A19A6***</RequestId>
</CreateExchangeResponse>

JSON format

{
    "RequestId": "021788F6-E50C-4BD6-9F80-66B0A19A6***"
}

Error codes

For a list of error codes, visit the API Error Center.