When a message is published to a topic in Simple Message Queue (formerly MNS), SMQ can automatically deliver it to one or more queues through subscriptions. This publish/subscribe pattern decouples producers from consumers: producers publish to a topic without knowing which queues process the messages, and each subscribed queue receives its own copy independently.
Common use cases include:
Order processing: An e-commerce system publishes order events to a topic. Separate queues handle inventory updates, payment processing, and notification delivery in parallel.
Log distribution: A centralized logging topic fans out log entries to different queues for real-time alerting, long-term archival, and analytics processing.
Cross-account event sharing: A shared topic delivers events to queues owned by different Alibaba Cloud accounts, enabling multi-team or multi-application architectures.
This guide walks through the full setup: create a queue, create a topic, link them with a subscription, publish a message, and verify delivery.
Prerequisites
Before you begin, make sure you have:
An Alibaba Cloud account with access to the SMQ console
(Cross-account only) A RAM role with cross-account authorization and its Alibaba Cloud Resource Name (ARN)
Step 1: Create a queue
The queue receives and stores messages pushed from the topic. Configure it based on how your consumer application processes messages.
Log on to the SMQ console.
In the left-side navigation pane, choose Queue Model > Queues.
In the top navigation bar, select a region.
On the Queues page, click Create Queue.
In the Create Queue panel, configure the following parameters and click OK.
Parameter Description Name The name of the queue. Example: order-processing-queue.Maximum Message Length The maximum size of a single message body sent to the queue, in bytes. Long Polling Period The maximum time (in seconds) that a ReceiveMessage request waits for a message to arrive before returning an empty response. Set to 0to disable long polling.Visibility Timeout Period After a consumer receives a message, the message becomes invisible to other consumers for this duration (in seconds). If the message is not deleted within this period, it becomes visible again. For more information, see Message visibility. Message Retention Period The maximum time (in seconds) that a message stays in the queue. After this period, the message is deleted regardless of whether it has been received. Message Delay Period The time (in seconds) that all messages sent to this queue are hidden before they become available for consumption. Enable Logging Feature Turn on logging to push queue operation logs to a Logstore. View message traces, delays, and other operational data from the logs. For more information, see Log management.
The queue appears on the Queues page after creation.
Step 2: Create a topic
The topic serves as the entry point for published messages. Every message published to the topic is delivered to all subscribed endpoints.
In the left-side navigation pane, choose Topic Model > Topics.
On the Topics page, click Create Topic.
In the Create Topic panel, configure the following parameters and click OK.
Parameter Description Name The name of the topic. Example: order-events-topic.Maximum Message Length The maximum size of a single message body published to the topic, in bytes. Enable Logging Feature Turn on logging to push topic operation logs to a Logstore. View message traces, delays, and other operational data from the logs. For more information, see Log management.
After the topic is created, the console redirects to the Topic Details page.
Step 3: Create a subscription
A subscription links a topic to a queue. When a message is published to the topic, SMQ pushes a copy to the subscribed queue. The setup differs based on whether the queue belongs to the same account or a different account.
Same-account subscription
Use this method when the topic and queue belong to the same Alibaba Cloud account.
In the left-side navigation pane, choose Topic Model > Subscriptions.
On the Subscriptions page, click Create Subscription.
In the Create Subscription panel, configure the following settings and click OK.
Parameter Description Topic Name The topic that this subscription listens to. Subscription Name A name for this subscription. Example: order-topic-to-queue.Subscription Select Queue. Cross-Account Select Intra-Account. Receiver Endpoint Select the queue created in Step 1. Message Filtering Tag (Optional) A tag string to filter messages. Only messages published with a matching tag are delivered to this queue. Retry Policy The retry behavior when message delivery fails. See Retry policies. Message Format The format in which messages are pushed to the queue.
Cross-account subscription
Use this method when the queue belongs to a different Alibaba Cloud account.
In the left-side navigation pane, choose Topic Model > Subscriptions.
On the Subscriptions page, click Create Subscription.
In the Create Subscription panel, configure the following settings and click OK.
Parameter Description Topic Name The topic that this subscription listens to. Subscription Name A name for this subscription. Example: cross-account-order-sub.Subscription Select Queue. Cross-Account Select Cross-Account. Receiver Endpoint The ARN of the destination queue. Find the ARN in the Basic Information section of the Queue Details page. Format: acs:mns:cn-hangzhou:${accountId}:/queues/${queueName}.Service-linked Role The ARN of the RAM role authorized for cross-account message delivery. For details on granting permissions and getting the ARN, see Cross-account push authorization. Message Filtering Tag (Optional) A tag string to filter messages. Only messages published with a matching tag are delivered to this queue. Retry Policy The retry behavior when message delivery fails. See Retry policies. Message Format The format in which messages are pushed to the queue.
Retry policies
| Policy | Behavior |
|---|---|
| BACKOFF_RETRY | Retries up to 3 times. The interval between retries is a random value between 10 and 20 seconds. |
| DECAY_RETRY | Retries up to 176 times over a 1-day period. The interval (in seconds) increases exponentially: 1, 2, 4, 8, ..., 512, then stays at 512 seconds for the remaining retries. |
Step 4: Publish a message
After the subscription is in place, publish a message to the topic. SMQ automatically delivers it to the subscribed queue.
On the Topics page, find the topic and click Publish Message in the Actions column.
On the Publish Message To Topic - Quick Start page, configure the following settings and click Publish Message.
Parameter Description Message Content The message body. Example: {"orderId": "123-456", "item": "Widget", "quantity": 2}.Message Tag (Optional) A tag string for filtering. Only subscriptions with a matching filtering tag receive this message. Subscription Type Select Queue.
Step 5: Verify message delivery
Confirm that the published message arrived in the queue.
On the Queues page, find the queue, and in the Action column, choose More > Send Messages.
(Optional) On the Send And Receive Messages In Queue - Quick Start page, in the Receive Message section, click Edit Parameters of Receiving Messages. In the Edit Parameters of Receiving Messages panel, configure Receive Times and Polling Period, and then click OK.
In the Receive Message section, click Receive Message. The received messages appear in a list below the button.
(Optional) In the message list, click Details in the Actions column to open the Message Details dialog box and verify the message content.
If the message content matches what you published in Step 4, the topic-to-queue push is working correctly.
Related topics
Message visibility: Learn about message states and visibility behavior.
Log management: Set up log monitoring for queues and topics.