1. Topic: A message topic classifies different service messages.
2. Tag: A message tag further distinguishes the messages under a topic. RocketMQ allows consumers to filter messages based on tags, ensuring that consumers only consume the desired messages.
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.
Application Scenario
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: Use dedicated topics for different types of messages, for example, normal messages, ordered messages, transaction messages, and scheduled (delayed) messages. Messages of different types cannot be classified by tags.
Business association: Use topics to distinguish messages without direct association. Use tags to classify messages with different subtypes of the same business.
Message priority: Use topics to classify messages by priority. In different business scenarios, the consumer has different priority requirements for messages. Some messages are urgent, and some messages are more tolerant of delay.
Message quantity: 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 deteriorate in terms of performance 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, namely, messages of different types in different sectors of the same business.