All Products
Search
Document Center

Simple Message Queue (formerly MNS):Ordered message

Last Updated:Jun 20, 2026

Simple Message Queue (formerly MNS) supports ordered messages. This topic describes core concepts, differences from normal messages, creation and usage methods, API instructions, and related limits and best practices.

Feature definition

Simple Message Queue (formerly MNS) provides first-in-first-out (FIFO) processing for messages within the same group, ensuring sequential handling in business scenarios.

Scenarios

Ordered messages are ideal for business scenarios that require strict message sequencing:

  • Order status transitions

    In E-commerce order systems, states such as order creation → payment → shipment → delivery confirmation must be processed in chronological order to maintain correct business state.

  • Financial transaction processing

    In securities or stock trading systems, orders with identical bid prices must be processed strictly in the order they were placed. Downstream systems must handle these orders according to their submission sequence.

  • Database synchronization

    Upstream databases perform insert, delete, or update operations. Binary operation logs are transmitted as messages to downstream systems, which replay them to refresh state data sequentially and avoid data inconsistency.

  • Business log recording

    Logs of critical business operations must be stored strictly in chronological order to support auditing and troubleshooting.

Key concepts

  • MessageGroupId: A message group identifier. The system guarantees message order within each group: messages with the same MessageGroupId are processed strictly in sequence, while messages from different groups can be processed in parallel.

  • Visibility timeout: After a message is successfully pulled, it remains invisible to other consumers until the timeout expires. This prevents multiple consumers from processing the same message simultaneously. If the message is not confirmed as deleted before the timeout, it becomes visible again.

  • Group locking mechanism: In an ordered queue, once a message with a specific MessageGroupId is pulled but not confirmed as deleted (i.e., remains invisible), all subsequent messages in the same MessageGroupId are blocked. This ensures strict consumption order. Only after the current message is confirmed as deleted or its visibility timeout expires can the next message in the same group be pulled.

Differences from normal messages

  • Ordering semantics:

    • Normal messages (standard queue/topic): Deliver at least once by best effort, with no guaranteed order.

    • Ordered messages (FIFO queue/topic): Within the same MessageGroupId, messages are consumed strictly in the order they arrive at the server. Earlier messages must be fully processed before later ones can be consumed.

  • Concurrency model:

    • Normal messages: No grouping restrictions; optimized for overall throughput.

    • Ordered messages: Use MessageGroupId as the concurrency unit—serial within a group, parallel across groups.

  • Message requirements:

    • Sending an ordered message requires specifying a MessageGroupId (applies to both queues and topics).

Getting Started

FIFO queue

  • Create a queue:

    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, set Queue Type to FIFO Queue, configure other parameters, and then click OK.

      Other configurable parameters include Maximum message size, Long polling period, Message visibility timeout, Message retention period, Message delay time, Enable logging, Dead-letter policy, and Rate limiting policy.

  • Send messages:

    • Use SendMessage and include a MessageGroupId. Use a stable business key such as an order ID.

    • If you omit MessageGroupId, the system returns error code FifoMissingMessageGroupId.

  • Receive and confirm:

    • Use ReceiveMessage to pull messages. The response includes MessageGroupId. After processing, call DeleteMessage to confirm.

FIFO topic

  • Create a topic:

    1. Log on to the SMQ console.

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

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

    4. On the Topics page, click Create Topic.

    5. In the Create Topic panel, set Topic Type to FIFO Topic, configure other parameters, and then click OK.

  • Create a subscription:

    Subscribe to a FIFO queue to ensure message ordering. Normal topics can only subscribe to standard queues. For details, see Step 3: Create a subscription.

  • Publish messages:

    • Use PublishMessage and include a MessageGroupId.

    • If you omit MessageGroupId, the system returns error code FifoMissingMessageGroupId.

  • Consume and confirm:

    • On the subscribed FIFO queue side, use ReceiveMessage to pull messages and DeleteMessage to confirm, maintaining sequential processing within each group.

API usage

Queue-related APIs

API name

Parameter description

Return description

CreateQueue-Create queue

Input parameter QueueType:

  • normal (standard queue)

  • fifo (FIFO queue)

Creates a queue of the specified type.

GetQueueAttributes-Get queue attributes

No special parameters

Returns queue information, including the QueueType field.

ListQueue-List all queues under an Alibaba Cloud account

No special parameters

Returns a list of queues. Each queue includes the QueueType field.

Topic-related APIs

API name

Parameter description

Return description

CreateTopic-Create topic

Input parameter TopicType:

  • normal (standard topic)

  • fifo (FIFO topic)

Creates a topic of the specified type.

GetTopicAttributes-Get topic attributes

No special parameters

Returns topic information, including the TopicType field.

ListTopic-List topics under an Alibaba Cloud account

No special parameters

Returns a list of topics. Each topic includes the TopicType field.

Message send/receive APIs

API name

Parameter requirements

Return Description

Notes

SendMessage

FIFO queues require MessageGroupId.

Standard response.

Sends a single message to a queue.

BatchSendMessage

FIFO queues require MessageGroupId.

Standard response.

Sends multiple messages to a queue in a batch.

PublishMessage

FIFO topics require MessageGroupId.

Standard response.

Publishes a message to a topic.

ReceiveMessage

No special parameters.

The response body includes MessageGroupId.

Receives a single message from a queue.

BatchReceiveMessage

Supports the numOfMessages parameter.

The response body includes MessageGroupId.

May return messages from multiple groups. Order is preserved within each group.

Limits

  • Supported regions include China (Shenzhen), China (Shanghai), and China (Hangzhou). To request FIFO support in other regions, submit a ticket.

  • Group ID required: Sending messages to a FIFO queue or topic requires a MessageGroupId.

  • Type compatibility:

    • Dead-letter queues (DLQs): Only queues of the same type can be bound. FIFO messages can only bind to FIFO dead-letter queues, and normal messages can only bind to standard dead-letter queues.

    • Subscriptions: Standard topics can only subscribe to standard queues. For ordered delivery, subscribe FIFO topics to FIFO queues.

  • Peek not supported: FIFO queues do not support the message peeking interface (PeekMessage).

Best practices

  • Group design:

    • Use stable and evenly distributed MessageGroupId values (such as order IDs) to prevent a few hot-spot groups from becoming performance bottlenecks.

    • For extremely hot-spot workloads, subdivide groups at the application layer to increase concurrency.

  • Visibility timeout: Set this based on actual processing duration to ensure your application completes processing and confirms the message before timeout, reducing duplicate deliveries.

  • Idempotency and retries: Implement idempotent processing and retry logic in consumers to ensure end-to-end consistency.

  • Batch receiving: Increase numOfMessages to improve throughput, as long as per-message processing delay remains acceptable.

FAQ

How is ordering defined?

Messages with the same MessageGroupId are delivered and processed strictly in send order. Messages from different groups can be processed in parallel.

Must I provide MessageGroupId?

Yes. Sending messages to a FIFO queue or topic requires MessageGroupId. Without it, ordering cannot be guaranteed.

How do I choose between FIFO and standard queues/topics?

Use FIFO queues or topics if your business requires strict ordering (such as order status transitions). Use standard queues or topics if you prioritize overall throughput and elasticity and do not require message ordering. To get started, create a FIFO Queue or FIFO Topic in the console, include MessageGroupId when sending, and read this attribute on the consumer side for ordered processing and confirmation.