This topic introduces the concepts, scenarios, and usage instructions of MQ ordered messages.
Use Java SDK 1.2.7 or a later version.
Sample code can be found in the following documents:
Ordered message is a type of message provided by MQ, which is delivered and consumed in order. Ordered message means the message is both delivered and consumed in order.
Ordered delivery: For a specified topic, the client sends the messages in order.
Ordered consumption: For a specified topic, the client receives messages in order, which means the message sent first is received first by the client.
For a specified topic, all messages are delivered and consumed in strict First-In-First-Out (FIFO) order.
- Globally ordered messages are typically used in scenarios where the performance requirements are not high, and all messages are delivered and consumed in strict FIFO order.
For a specified topic, all messages are sharded based on the sharding key. Messages in the same shard are delivered and consumed in strict FIFO order. Sharding key is a key field used in ordered message to distinguish different shards, which is completely different with the key in standard messages.
- Typically used in scenarios where the performance requirements are high. The sharding key is used as the sharding field, and messages in one shard are delivered and consumed in strict FIFO order.
[Example 1] A verification code needs to be sent for user registration, so user ID is used as the sharding key. Messages sent by the same user will be delivered and subscribed in FIFO order.
[Example 2] An order is created with the order ID as sharding key in e-commerce, then the order creation information, order payment information, order refunding information, and order shipping information related to the same order will be delivered and subscribed in FIFO order.
Alibaba Group’s internal e-commerce systems all use partitionally ordered messages, which can ensure both service order and performance.
Different topic types are used for creating different types of messages in the MQ console. The following table compares various types of topics.
|Topic Type||Support Transactional Message||Support Scheduled Message||Performance|
|Partitionally Ordered Message||No||No||High|
|Globally Ordered Message||No||No||Medium|
|Message Type||Support Reliable Synchronous Transmission||Support Reliable Asynchronous Transmission||Support Oneway Transmission|
|Partitionally Ordered Message||Yes||No||No|
|Globally Ordered Message||Yes||No||No|
- Order message does not support broadcast mode.
- The same producer ID or consumer ID can only correspond to one type of Topic. It cannot be used for sending or receiving ordered message and unordered message at the same time.
- Ordered message does not support asynchronous transmission, otherwise strict order cannot be ensured.
- For globally ordered message, instance >= 2 is recommended. Running multiple instances at the same time is to prevent service interruption caused by sudden failure of the running instance. When a running instance exits expectedly, another instance takes over the work immediately without any service interruption. Only one instance actually works at the same time.