All Products
Search
Document Center

ApsaraMQ for RabbitMQ:CreateExchange

Last Updated:Sep 10, 2026

Creates an exchange.

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 exchange name.

Note

Note

  • The exchange 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.

  • After an exchange is created, its name cannot be modified. You can only delete the exchange and create a new one.

DemoExchange

ExchangeType

string

Yes

The exchange type. Valid values:

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

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

  • FANOUT: This type uses a simple routing rule that routes all messages sent to the exchange to all queues bound to it, which is equivalent to broadcasting.

  • HEADERS: This type is similar to the DIRECT type. A HEADERS exchange uses headers attributes instead of routing keys for route matching. When you bind a HEADERS exchange to a queue, you set key-value pairs for the binding attributes. When you send a message to a HEADERS exchange, you set key-value pairs for the message headers attributes. The exchange routes messages to bound queues by comparing the message headers key-value pairs with the binding attribute key-value pairs.

Valid values:

  • FANOUT :

    fanout.

  • HEADERS :

    headers attribute matching.

  • X_DELAYED_MESSAGE :

    delayed message.

  • X_CONSISTENT_HASH :

    consistent hash.

  • TOPIC :

    topic.

  • DIRECT :

    direct.

  • X_JMS_TOPIC :

    JMS topic.

DIRECT

XDelayedType

string

No

An x-delayed-message exchange allows you to customize the header attributes of a message. The x-delay header specifies the delay period for message delivery, in milliseconds. The routing rule of this exchange type depends on the exchange type specified by the x-delayed-type parameter, which specifies the actual exchange type to which delayed messages are ultimately delivered. Valid values:

  • DIRECT: Delivers delayed messages to the specified queue bound to a DIRECT exchange.

  • TOPIC: Delivers delayed messages to queues bound to a TOPIC exchange.

  • FANOUT: Delivers delayed messages to queues bound to a FANOUT exchange.

  • HEADERS: Delivers delayed messages to queues bound to a HEADERS exchange.

  • X-JMS-TOPIC: Delivers delayed messages to queues bound to an X-JMS-TOPIC exchange.

Valid values:

  • FANOUT :

    fanout.

  • HEADERS :

    headers attribute matching.

  • TOPIC :

    topic.

  • DIRECT :

    direct.

  • X_JMS_TOPIC :

    JMS topic.

DIRECT

AutoDeleteState

boolean

Yes

Specifies whether to automatically delete the exchange. Valid values:

  • true: The exchange is automatically deleted when the last queue bound to it is unbound.

  • false: The exchange is not automatically deleted when the last queue bound to it is unbound.

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. An alternate exchange is used to receive messages that fail to be routed by the exchange.

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.