All Products
Search
Document Center

ApsaraMQ for RabbitMQ:Creating resources

Last Updated:Mar 08, 2026

Create the required ApsaraMQ for RabbitMQ resources -- an instance, a vhost, an exchange, a queue, and a binding -- before you connect a producer or consumer.

Resource hierarchy

Instance
  └── Vhost (logical isolation)
        ├── Exchange (routes messages)
        └── Queue (stores messages)
              └── Binding (connects an exchange to a queue)

Resource

Role

Instance

An independent resource entity that holds all other resources.

Vhost

A logical boundary that isolates its own exchanges, queues, and bindings. An instance can contain multiple vhosts.

Exchange

Receives messages from producers and routes them to queues based on a routing key.

Queue

Holds messages until consumers retrieve them.

Binding

Links an exchange to a queue with a routing key so that messages reach the correct destination.

Data flow: Producer > Exchange > (routing key + binding) > Queue > Consumer

Prerequisites

If you use a Resource Access Management (RAM) user, grant the required ApsaraMQ for RabbitMQ permissions first. For more information, see Step 1: (Optional) Grant permissions to a RAM user.

Step 1: Create an instance

  1. Log on to the ApsaraMQ for RabbitMQ console. In the left-side navigation pane, click Instances.

  2. In the top navigation bar, select a region. On the Instances page, click Create Instance.

  3. On the buy page, configure the instance settings, read and accept the terms of service, and then click Buy Now.

  4. Complete the payment.

After the purchase, return to the Instances page and select the region where you created the instance to view it.

Step 2: Create a vhost

A vhost provides logical isolation of resources. Specify a vhost before you connect a producer or consumer.

  1. On the Instances page, click the name of your instance.

  2. In the left-side navigation pane, click Vhosts.

  3. On the Vhosts page, click Create Vhost.

  4. In the Create Vhost panel, enter a name in the vhost Name field and click OK.

Step 3: Create an exchange

An exchange routes messages from producers to queues based on a routing key. For more information, see Exchange.

  1. In the left-side navigation pane, click Exchanges.

  2. On the Exchanges page, click the drop-down arrow next to vhost. From the Change drop-down list, select the vhost in which you want to create an exchange. Then, click Create Exchange.

  3. In the Create Exchange panel, configure the following parameters and click OK.

Exchange parameters

Parameter

Required

Description

Exchange Name

Yes

The name of the exchange. amq. is a reserved prefix and cannot be used at the beginning of an exchange name. For example, amq.test is not allowed.

Type

Yes

The exchange type.

Internal

No

Whether the exchange is internal. Default: No. Set to Yes to bind this exchange to another exchange instead of a queue.

The following parameters appear only for specific exchange types:

Parameter

When to configure

Description

x-delayed-type

Type = x-delayed-message

The routing rule for the delayed-message exchange.

Hash value

Type = x-consistent-hash

The input for hash calculation. Valid values: RoutingKey, Header Value.

hash-header

Type = x-consistent-hash and Hash value = Header Value

The header used as the input for hash calculation.

Exchange types

Type

Routing logic

Description

direct

Exact match

Routes a message to the queue whose routing key exactly matches the routing key of the message.

topic

Pattern matching

Routes a message to one or more queues based on pattern matching between the message routing key and the routing keys used to bind queues to the exchange.

fanout

Broadcast

Routes all received messages to every queue bound to the exchange, regardless of routing keys.

headers

Header matching

Routes messages based on headers attributes (key-value pairs) instead of routing keys. Binding attributes and message headers must both be in key-value format. The exchange matches message headers against binding attributes to determine routing.

x-delayed-message

Delayed delivery

Delays message delivery by the duration specified in the x-delay header attribute (in milliseconds). After the delay elapses, the message is routed according to the rule defined by x-delayed-type.

x-consistent-hash

Consistent hashing

Performs hash calculation on routing keys or header values and uses consistent hashing to distribute messages across queues.

Step 4: Create a queue

A queue stores messages delivered by exchanges until consumers retrieve them.

  1. In the left-side navigation pane, click Queues.

  2. On the Queues page, click the drop-down arrow next to vhost. From the Change drop-down list, select the vhost in which you want to create a queue. Then, click Create Queue.

  3. In the Create Queue panel, configure the following parameters and click OK.

Queue parameters

Parameter

Required

Description

Queue Name

Yes

The name of the queue.

Auto Delete

No

Whether the queue is automatically deleted after the last consumer unsubscribes. Default: No.

Click Dead-letter Policy to configure optional parameters:

Parameter

Description

DeadLetterExchange

The exchange to which dead-letter messages are delivered.

DeadLetterRoutingKey

The routing key for dead-letter messages. The dead-letter exchange routes messages to the queue whose routing key matches this value.

MessageTTL

The message time-to-live (TTL), in milliseconds. A message that is not consumed within the TTL becomes a dead-letter message and is sent to the dead-letter exchange. For more information, see Message TTL.

Queue naming rules

  • Allowed characters: letters, digits, hyphens (-), underscores (_), periods (.), number signs (#), forward slashes (/), and at signs (@).

  • Length: 1 to 255 characters.

  • The name cannot be changed after creation. To rename a queue, delete it and create a new one.

  • amq. is a reserved prefix and cannot be used at the beginning of a queue name. For example, amq.test is not allowed.

Step 5: Create a binding

A binding connects an exchange to a queue so that messages can be routed from the exchange to the queue.

  1. On the Queues page, find your queue and click Details in the Actions column.

  2. On the Queue Details page, click the Bound as Destination tab. Then, click Add Binding.

  3. In the Add Binding panel, configure the Source Exchange and Routing Key parameters. Then, click OK.

If the source exchange is of the x-consistent-hash type, the routing key represents the weight of the queue. The weight must be an integer from 1 to 20.

Next steps

Step 3: Use an SDK to send and receive messages

References

You can also create resources by calling the following API operations: