All Products
Search
Document Center

ApsaraMQ for RabbitMQ:CreateExchange

Last Updated:Oct 16, 2025

A producer sends a message to an exchange. The exchange then routes the message to one or more queues based on the routing key and the binding key, or discards the message.

Try it now

Try this API in OpenAPI Explorer, no manual signing needed. Successful calls auto-generate SDK code matching your parameters. Download it with built-in credential security for local usage.

Test

RAM authorization

The table below describes the authorization required to call this API. You can define it in a Resource Access Management (RAM) policy. The table's columns are detailed below:

  • Action: The actions can be used in the Action element of RAM permission policy statements to grant permissions to perform the operation.

  • API: The API that you can call to perform the action.

  • Access level: The predefined level of access granted for each API. Valid values: create, list, get, update, and delete.

  • Resource type: The type of the resource that supports authorization to perform the action. It indicates if the action supports resource-level permission. The specified resource must be compatible with the action. Otherwise, the policy will be ineffective.

    • For APIs with resource-level permissions, required resource types are marked with an asterisk (*). Specify the corresponding Alibaba Cloud Resource Name (ARN) in the Resource element of the policy.

    • For APIs without resource-level permissions, it is shown as All Resources. Use an asterisk (*) in the Resource element of the policy.

  • Condition key: The condition keys defined by the service. The key allows for granular control, applying to either actions alone or actions associated with specific resources. In addition to service-specific condition keys, Alibaba Cloud provides a set of common condition keys applicable across all RAM-supported services.

  • Dependent action: The dependent actions required to run the action. To complete the action, the RAM user or the RAM role must have the permissions to perform all dependent actions.

Action

Access level

Resource type

Condition key

Dependent action

amqp:CreateExchange

create

*Exchange

acs:amqp:{#regionId}:{#accountId}:/instances/{#instanceId}/vhosts/{#vhostName}/exchanges/*

None
  • amqp:GetVhost

Request parameters

Parameter

Type

Required

Description

Example

InstanceId

string

Yes

The instance ID.

amqp-cn-v0h1kb9nu***

VirtualHost

string

Yes

The name of the vhost to which the exchange belongs.

test

ExchangeName

string

Yes

The name of the exchange. Note:

  • The name can contain only letters, digits, hyphens (-), underscores (_), periods (.), number signs (#), forward slashes (/), and at signs (@). The name must be 1 to 255 characters in length.

  • The name of an exchange cannot be changed after the exchange is created. To change the name, delete the exchange and create a new one.

DemoExchange

ExchangeType

string

Yes

The type of the exchange. Valid values:

  • DIRECT: This routing rule type routes messages to a queue whose binding key exactly matches the routing key of the message.

  • TOPIC: This type is similar to the DIRECT type. It routes messages to bound queues using routing key pattern matching and string comparison.

  • FANOUT: This routing rule type is simple. It routes all messages sent to the exchange to all queues that are bound to the exchange. This works like a broadcast feature.

  • HEADERS: This type is similar to the DIRECT type. It uses header properties instead of a routing key for routing. When a queue is bound to a headers exchange, key-value pairs are defined for the binding. When a message is sent to the exchange, key-value pairs are defined in the message header. The exchange routes the message by comparing the key-value pairs in the header with the key-value pairs of the binding.

DIRECT

XDelayedType

string

No

An x-delayed-message exchange lets you use the x-delay header property to specify a delivery delay for a message in milliseconds. The routing rule for the delayed message is determined by the exchange type that you specify for the XDelayedType parameter. This parameter sets the actual exchange type to which the message is delivered after the delay. Valid values:

  • DIRECT: Delivers the delayed message to the specified queue that is bound to a DIRECT exchange.

  • TOPIC: Delivers the delayed message to queues that are bound to a TOPIC exchange.

  • FANOUT: Delivers the delayed message to queues that are bound to a FANOUT exchange.

  • HEADERS: Delivers the delayed message to queues that are bound to a HEADERS exchange.

  • X-JMS-TOPIC: Delivers the delayed message to queues that are bound to an X-JMS-TOPIC exchange.

DIRECT

AutoDeleteState

boolean

Yes

Specifies whether to automatically delete the exchange. Valid values:

  • true: Yes. The exchange is automatically deleted after the last queue is unbound from it.

  • false: No. The exchange is not automatically deleted after the last queue is unbound from it.

false

Internal

boolean

Yes

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

  • false: No

  • true: Yes

false

AlternateExchange

string

No

The alternate exchange. Configure an alternate exchange to receive messages that fail to be routed.

DemoAE

Response elements

Element

Type

Description

Example

object

RequestId

string

The request ID.

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

Examples

Success response

JSON format

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

Error codes

See Error Codes for a complete list.

Release notes

See Release Notes for a complete list.