All Products
Search
Document Center

:CreateExchange

更新時間:Sep 11, 2024

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.

InstanceId

String

Yes

amqp-cn-v0h1kb9nu***

The instance ID.

VirtualHost

String

Yes

test

The name of the vhost in which you want to create the exchange.

ExchangeName

String

Yes

DemoExchange

The exchange name. The exchange name must meet the following conventions:

  • The name must be 1 to 255 characters in length and can contain only letters, digits, and the following special characters: - _ . # / @

  • 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 exchange type. Valid values:

  • 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: An exchange of this type is similar to an exchange of the direct 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: An exchange of this type is similar to an exchange of the direct type. The only difference between a headers exchange and a direct exchange 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. 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 result between the headers attributes of the message and the binding attributes of the bound queue.

XDelayedType

String

No

DIRECT

The x-delayed-message exchange. You can use the x-delay header of a message to specify a period of time after which the message is delivered from an x-delayed-message exchange. Unit: milliseconds. The type of exchange to which messages in an x-delayed-message exchange are delivered is determined by the value of the x-delayed-type parameter. Valid values of the x-delayed-type parameter:

  • DIRECT: delivers delayed messages to queues that are bound to a direct exchange.

  • TOPIC: delivers delayed messages to queues that are bound to a topic exchange.

  • FANOUT: delivers delayed messages to queues that are bound to a fanout exchange.

  • HEADERS: delivers delayed messages to queues that are bound to a headers exchange.

  • X-JMS-TOPIC: delivers delayed messages to queues that are bound to an x-jms-topic exchange.

AutoDeleteState

Boolean

Yes

false

Specifies whether to enable automatic deletion. Valid values:

  • true. If the last queue that is bound to the exchange is unbound, the exchange is automatically deleted.

  • false. If the last queue that is bound to the exchange is unbound, the exchange is not automatically deleted.

Internal

Boolean

Yes

false

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

  • false

  • true

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-66B0A19A****

The request ID.

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

HTTP/1.1 200 OK
Content-Type:application/xml

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

JSON format

HTTP/1.1 200 OK
Content-Type:application/json

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

Error codes

For a list of error codes, see Service error codes.