All Products
Search
Document Center

ApsaraMQ for RocketMQ:Ordered messages

Last Updated:Mar 11, 2026

Ordered messages are consumed in the exact order they were sent, following a strict first in, first out (FIFO) model. Use ordered messages when your business logic depends on sequential processing -- for example, in financial securities and e-commerce fields.

Key concepts

Ordered messages are a dedicated message type in ApsaraMQ for RocketMQ. Within a topic, ordered messages are published and consumed in strict FIFO order.

Sharding key determines which partition a message is routed to. Messages with the same sharding key are always sent to the same partition, which preserves their relative order.

Partitionally ordered messages provide FIFO ordering within each partition of a topic. Messages are partitioned by sharding key, and FIFO ordering is guaranteed only among messages that share the same sharding key. Messages across different partitions have no ordering guarantee relative to each other.

Note: Ordered messages, scheduled messages, and transactional messages are mutually exclusive types. A single message cannot belong to more than one of these types.

Use cases

Partitionally ordered messages suit high-throughput systems that require strict sequencing within logical groupings but not across them.

Use caseSharding keyWhy ordering matters
E-commerce ordersOrder IDCreation, payment, and refund events for the same order must be processed sequentially to maintain consistent order state.
User verificationUser IDVerification code messages for the same user must arrive in the order they were requested.

All internal e-commerce systems in Alibaba Group use partitionally ordered messages for stable performance and sequential processing of online orders.

How it works

ApsaraMQ for RocketMQ enforces FIFO ordering across three phases: publishing, storage, and consumption.

Ordered message workflow

Message publishing

In the diagram above, messages for Orders A and B are produced in this sequence: A1, B1, A2, A3, B2, B3. Each order's messages must be consumed in the same relative order they were produced: A1 then A2 then A3, and B1 then B2 then B3.

With normal (unordered) messages, the broker distributes messages across queues in round-robin fashion, which does not preserve order. With ordered messages, the broker routes all messages that share the same sharding key (for example, the same order ID) to the same queue, preserving their sequence.

Ordering depends on the sender. The broker determines message order based on the sequence in which a single producer or thread sends them. If multiple producers or threads send messages concurrently, the broker orders messages by arrival time, which may differ from the intended business sequence.

Message storage

Each logical queue in an ordered message topic maps to exactly one physical queue. Messages arrive at a logical queue in order and are persisted in the corresponding physical queue in the same order.

Message consumption

The broker delivers messages to consumers in the order they were stored. Messages that share the same sharding key are consumed by a single thread, which ensures the consumption order matches both the storage order and the original publishing order.

Usage notes

  • One group, one message type. Each group is bound to a single topic type. Do not use the same group to send or receive both ordered and unordered messages.

  • Single-producer ordering. The broker preserves ordering based on the sequence in which a single producer or thread sends messages. If multiple producers or threads send concurrently, the broker orders by arrival time, which may differ from the business-side sequence. To guarantee strict ordering across producers, route all messages in the same business sequence through a single producer instance.

  • Synchronous send only. Ordered messages require reliable synchronous transmission. Asynchronous transmission is not supported, because async sends cannot guarantee delivery order.

  • Clustering consumption only. Ordered messages support clustering consumption but not broadcasting consumption.

FAQ

Can a message be an ordered message, a scheduled message, and a transactional message at the same time?

No. Ordered, scheduled, and transactional messages are mutually exclusive types.

Which regions support ordered messages?

Ordered messages are available in all Alibaba Cloud regions and Finance Cloud regions where ApsaraMQ for RocketMQ is deployed.

What transmission modes do ordered messages support?

Only reliable synchronous transmission. Asynchronous transmission is not supported because it cannot guarantee strict ordering.

Do ordered messages support broadcasting consumption?

No. Ordered messages support clustering consumption only.

Sample code

TCP SDKs

HTTP SDKs