In ApsaraMQ for RocketMQ, both topics and tags are identifiers for message classification in business. The difference is that topics are the first-level classification while tags are the second-level classification. This topic describes how to filter messages by using topics and tags.

Background

Topics and tags in ApsaraMQ for RocketMQ are defined as follows:

Topic
The message topic, which is used to classify business messages.
Tag
The message tag, an attribute of a message sent from the producer, which is used to further classify messages under a topic.

The relationship between topics and tags is shown in the following figure.

Relationship between topics and tags

Scenarios

You may wonder when you should use a topic and when you should use a tag.

We recommend that you select a topic or tag based on the following items:

  • Message type consistency: Use dedicated topics for different types of messages, for example, normal messages, transactional messages, scheduled messages, and ordered messages. Messages of different types cannot be classified by tag.
  • Business association: Use topics to distinguish messages without direct association, such as Taobao transactional messages and JD logistics messages. Use tags to classify messages about electrical appliance orders, women's clothing orders, and cosmetics orders among Tmall transactional messages.
  • Message priority consistency: Use topics to classify messages by priority, for example, Hema (1-hour delivery) logistics messages, Tmall Supermarket (24-hour delivery) logistics messages, and Taobao (relatively slower delivery) logistics messages.
  • Message quantity equivalence: Messages of some businesses may be of a small quantity but have high real-time requirements. If they share a topic with trillions of messages, these businesses may "starve to death" due to a long wait time. Therefore, use different topics for messages with different quantity levels.

To classify messages, you can create multiple topics, or create multiple tags under the same topic. However, in general, there is no relationship between messages in different topics, and tags are used to distinguish related messages within the same topic, such as the relationship between the full set and the subset, and the relationship between the processes in sequence.

Example

Take the Tmall transaction platform as an example. Order messages and payment messages are of different business types. Therefore, create Topic_Order and Topic_Pay respectively. Then, further classify order messages by product category with tags, for example, electrical appliances, men's wear, women's wear, and cosmetics, for dedicated systems to process.

Reasonable use of topics and tags makes the business structure clear and improves the business efficiency.

For more information about how to use tags to filter messages, see Message filtering.

References

Subscription consistency.