All Products
Search
Document Center

ApsaraMQ for RabbitMQ:CreateExchange

Last Updated:Sep 12, 2024

Creates an exchange. In ApsaraMQ for RabbitMQ, an exchange is used to route a message that is received from a producer to one or more queues or to discard the message. An exchange routes a message to queues by using the routing key and binding keys.

Debugging

OpenAPI Explorer automatically calculates the signature value. For your convenience, we recommend that you call this operation in OpenAPI Explorer.

Authorization information

The following table shows the authorization information corresponding to the API. The authorization information can be used in the Action policy element to grant a RAM user or RAM role the permissions to call this API operation. Description:

  • Operation: the value that you can use in the Action element to specify the operation on a resource.
  • Access level: the access level of each operation. The levels are read, write, and list.
  • Resource type: the type of the resource on which you can authorize the RAM user or the RAM role to perform the operation. Take note of the following items:
    • The required resource types are displayed in bold characters.
    • If the permissions cannot be granted at the resource level, All Resources is used in the Resource type column of the operation.
  • Condition Key: the condition key that is defined by the cloud service.
  • Associated operation: other operations that the RAM user or the RAM role must have permissions to perform to complete the operation. To complete the operation, the RAM user or the RAM role must have the permissions to perform the associated operations.
OperationAccess levelResource typeCondition keyAssociated operation
amqp:CreateExchangecreate
  • Exchange
    acs:amqp:{#regionId}:{#accountId}:/instances/{#instanceId}/vhosts/{#vhostName}/exchanges/*
    none
none

Request parameters

ParameterTypeRequiredDescriptionExample
InstanceIdstringYes

The ID of the ApsaraMQ for RabbitMQ for which you want to create an exchange.

amqp-cn-v0h1kb9nu***
VirtualHoststringYes

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

test
ExchangeNamestringYes

The name of the exchange that you want to create. The exchange name must meet the following conventions:

  • The name must be 1 to 255 characters in length, and can contain only letters, digits, hyphens (-), underscores (_), periods (.), number signs (#), forward slashes (/), and at signs (@).
  • After the exchange is created, you cannot change its name. If you want to change its name, delete the exchange and create another exchange.
DemoExchange
ExchangeTypestringYes

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: This type of exchange is similar to direct exchanges. 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 received messages to all queues bound to this exchange. You can use a fanout exchange to broadcast messages.
  • HEADERS: This type of exchange is similar to direct exchanges. 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.
  • X-CONSISTENT-HASH: An exchange of this type allows you to perform hash calculations on routing keys or header values and use consistent hashing to route a message to different queues.
DIRECT
AutoDeleteStatebooleanYes

Specifies whether to automatically delete the exchange. 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.
false
InternalbooleanYes

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

  • false
  • true
false
AlternateExchangestringNo

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

DemoAE

Response parameters

ParameterTypeDescriptionExample
object
RequestIdstring

The request ID.

021788F6-E50C-4BD6-9F80-66B0A19A6***

Examples

Sample success responses

JSONformat

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

Error codes

For a list of error codes, visit the Service error codes.

Change history

Change timeSummary of changesOperation
2024-07-11The request parameters of the API has changedView Change Details
2024-03-19The internal configuration of the API is changed, but the call is not affectedView Change Details