All Products
Search
Document Center

Simple Message Queue (formerly MNS):Push messages from a topic to a queue

Last Updated:Mar 11, 2026

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.

  1. Log on to the SMQ console.

  2. In the left-side navigation pane, choose Queue Model > Queues.

  3. In the top navigation bar, select a region.

  4. On the Queues page, click Create Queue.

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

    ParameterDescription
    NameThe name of the queue. Example: order-processing-queue.
    Maximum Message LengthThe maximum size of a single message body sent to the queue, in bytes.
    Long Polling PeriodThe maximum time (in seconds) that a ReceiveMessage request waits for a message to arrive before returning an empty response. Set to 0 to disable long polling.
    Visibility Timeout PeriodAfter 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 PeriodThe 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 PeriodThe time (in seconds) that all messages sent to this queue are hidden before they become available for consumption.
    Enable Logging FeatureTurn 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.

  1. In the left-side navigation pane, choose Topic Model > Topics.

  2. On the Topics page, click Create Topic.

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

    ParameterDescription
    NameThe name of the topic. Example: order-events-topic.
    Maximum Message LengthThe maximum size of a single message body published to the topic, in bytes.
    Enable Logging FeatureTurn 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.

  1. In the left-side navigation pane, choose Topic Model > Subscriptions.

  2. On the Subscriptions page, click Create Subscription.

  3. In the Create Subscription panel, configure the following settings and click OK.

    ParameterDescription
    Topic NameThe topic that this subscription listens to.
    Subscription NameA name for this subscription. Example: order-topic-to-queue.
    SubscriptionSelect Queue.
    Cross-AccountSelect Intra-Account.
    Receiver EndpointSelect 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 PolicyThe retry behavior when message delivery fails. See Retry policies.
    Message FormatThe 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.

  1. In the left-side navigation pane, choose Topic Model > Subscriptions.

  2. On the Subscriptions page, click Create Subscription.

  3. In the Create Subscription panel, configure the following settings and click OK.

    ParameterDescription
    Topic NameThe topic that this subscription listens to.
    Subscription NameA name for this subscription. Example: cross-account-order-sub.
    SubscriptionSelect Queue.
    Cross-AccountSelect Cross-Account.
    Receiver EndpointThe 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 RoleThe 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 PolicyThe retry behavior when message delivery fails. See Retry policies.
    Message FormatThe format in which messages are pushed to the queue.

Retry policies

PolicyBehavior
BACKOFF_RETRYRetries up to 3 times. The interval between retries is a random value between 10 and 20 seconds.
DECAY_RETRYRetries 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.

  1. On the Topics page, find the topic and click Publish Message in the Actions column.

  2. On the Publish Message To Topic - Quick Start page, configure the following settings and click Publish Message.

    ParameterDescription
    Message ContentThe 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 TypeSelect Queue.

Step 5: Verify message delivery

Confirm that the published message arrived in the queue.

  1. On the Queues page, find the queue, and in the Action column, choose More > Send Messages.

  2. (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.

  3. In the Receive Message section, click Receive Message. The received messages appear in a list below the button.

  4. (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