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 the Auto Delete attribute is configured. Valid values:

  • true: The Auto Delete attribute is configured. If the last queue that is bound to an exchange is unbound, the exchange is automatically deleted.
  • false: The Auto Delete attribute is not configured. If the last queue that is bound to an exchange is unbound, the exchange is not automatically deleted.
ExchangeName String Yes DemoExchange

The name of the exchange. Description:

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

The type of the exchange. Valid values:

  • 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.
  • DIRECT: An exchange of this type routes a message to the queue whose binding key is exactly 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 fuzzy match or multi-condition match result between the routing key of the message and the binding keys of the current exchange.
InstanceId String Yes amqp-cn-v0h1kb9nu***

The ID of the instance.

Internal Boolean Yes false

Specifies whether an 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 your instance resides.

VirtualHost String Yes test

The vhost where an exchange resides.

AlternateExchange String No DemoAE

The alternate exchange. An alternate exchange is configured for an existing exchange. It is used to receive messages that fail to be routed to queues from the existing exchange.

Response parameters

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

The ID of the request.

Examples

Sample requests

http(s)://[Endpoint]/?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.