All Products
Search
Document Center

Topic and tag best practices

Last Updated: Sep 13, 2019

Topic and tag are defined as follows:

  • Topic: indicates the message topic, which is the first-level message type for classifying business messages.

  • Tag: indicates the message tag, which is the second-level message type for further classifying messages under the same topic. MQ allows consumers to consume only messages that they are concerned about by filtering messages by tag.

Both topic and tag are identifiers for message classification in business. The difference is that topic is for first-level classification, and tag is for second-level classification. The relationship is shown in the figure.

Tag

Differences

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 considerations:

  • 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 transaction 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, the system may “starve to death” due to a long wait time. Therefore, use different topics for messages with different quantity levels.

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 consumers filter messages, see Message filtering.