edit-icon download-icon

Ordered messages

Last Updated: Jul 17, 2018

This topic introduces the concepts, scenarios, and usage instructions of MQ ordered messages.

SDK Support

Use Java SDK 1.2.7 or a later version.

Sample code can be found in the following documents:

Concept introduction

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.

Globally ordered message

For a specified topic, all messages are delivered and consumed in strict First-In-First-Out (FIFO) order.

ordered msg-1

Scenarios

  • 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.

Partitionally ordered message

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.

ordered msg-2

Scenarios

  • 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

  • [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.

Comparison between globally ordered messages and partitionally ordered messages

Different topic types are used for creating different types of messages in the MQ console. The following table compares various types of topics.

Message Type

Topic Type Support Transactional Message Support Scheduled Message Performance
Unordered Message Yes Yes Highest
Partitionally Ordered Message No No High
Globally Ordered Message No No Medium

Sending Method

Message Type Support Reliable Synchronous Transmission Support Reliable Asynchronous Transmission Support Oneway Transmission
Unordered Message Yes Yes Yes
Partitionally Ordered Message Yes No No
Globally Ordered Message Yes No No

Notes

  • 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.
Thank you! We've received your feedback.