Push messages to a queue
Lightweight Message Queue (formerly MNS) lets you push messages from a topic to a queue. This guide describes the steps.
Step 1: Create a queue
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 then click OK.
Name: the name of the queue.
Maximum Message Length: the maximum length of the message that is sent to the queue.
Long Polling Period: the maximum duration for which long polling requests are held after the ReceiveMessage operation is called. The value 0 indicates that long polling is disabled.
Visibility Timeout Period: the duration for which a message stays in the Inactive state after the message is received from the queue. For more information, see Message visibility.
Message Retention Period: the maximum duration for which a message exists in the queue. After the specified retention period, the message is deleted regardless of whether the message is received.
Message Delay Period: the period after which all messages sent to the queue are consumed.
Enable Logging Feature: specifies whether to enable the logging feature. If this feature is enabled, SMQ automatically pushes the operation logs of this queue to the specified Logstore. You can then view the message trace, delay, and other information from the logs. For more information, see Log management.
The new queue appears on the Queues page.
Step 2: Create a topic
In the , choose Topic Model > Topics.
On the Topics page, click Create Topic.
In the Create Topic panel, configure the following parameters, and then click OK.
Name: the name of the topic.
Maximum Message Length: the maximum length of the message that is sent to the topic.
Enable Logging Feature: specifies whether to enable the logging feature. If this feature is enabled, SMQ automatically pushes the operation logs of this topic to the specified Logstore. You can then view the message trace, delay, and other information from the logs. For more information, see Log management.
The Topic Details page for the new topic is displayed.
Step 3: Create a subscription
Current account
In the , choose Topic Model > Subscriptions.
On the Subscriptions page, click Create Subscription.
In the Create Subscription panel, configure the following settings, and then click OK.
Topic Name: The name of the topic for the subscription.
Subscription Name: Enter a name for the subscription.
Subscription: Select Queue.
Cross-Account: Select Intra-Account.
Receiver Endpoint: Select the queue that you created in Step 1.
(Optional) Message Filtering Tag: Enter a tag to filter messages.
Retry Policy: Select a retry policy.
BACKOFF_RETRY: Retries three times at random intervals between 10 and 20 seconds.
DECAY_RETRY: Retries 176 times over one day. The retry interval, in seconds, increases exponentially (2^0, 2^1, ..., 512) and then remains 512 for subsequent retries.
Message Format: Select the message push format.
Cross-account
In the , choose Topic Model > Subscriptions.
On the Subscriptions page, click Create Subscription.
In the Create Subscription panel, configure the following settings, and then click OK.
Topic Name: The name of the topic for the subscription.
Subscription Name: Enter a name for the subscription.
Subscription: Select Queue.
Cross-Account: Select Cross-Account.
Receiver Endpoint: Enter the Alibaba Cloud Resource Name (ARN) of the destination queue. Find the queue ARN in the Basic Information section of the Queue Details page. The format is
acs:mns:cn-hangzhou:${accountId}:/queues/${queueName}.Service-linked Role: Enter the ARN of the RAM role authorized for cross-account access. For information about how to grant permissions and obtain the RAM role ARN, see Cross-account push authorization.
(Optional) Message Filtering Tag: Enter a tag to filter messages.
Retry Policy: Select a retry policy.
BACKOFF_RETRY: Retries three times at random intervals between 10 and 20 seconds.
DECAY_RETRY: Retries 176 times over one day. The retry interval, in seconds, increases exponentially (2^0, 2^1, ..., 512) and then remains 512 for subsequent retries.
Message Format: Select the message push format.
Step 4: Publish a message
On the Topics page, find the target topic and click Publish Message in the Actions column.
On the Quick Experience of Publishing Messages to Topic page, configure the following settings, and then click Publish Message.
Message Content: Enter the message body.
(Optional) Message Tag: Enter a tag to filter messages.
Subscription Type: Select Queue.
Step 5: Receive messages
On the Queues page, find the target queue, and in the Action column, choose .
Optional: On the Quick Experience of Sending and Receiving Messages in Queue 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.
On the Quick Experience of Sending and Receiving Messages in Queue page, in the Receive Message section, click Receive Message.
A list of messages in the queue appears in the Receive Message section.
Optional: In the message list, find the target message, and in the Actions column, click Details. The Message Details dialog box shows information such as the message body.