This document mainly introduces the features and scenarios of clustering consumption and broadcasting consumption in TDMQ for RocketMQ.
Feature Introduction
Clustering consumption: In the clustering consumption mode, each message only needs to be processed by any of the consumers in the cluster.
Broadcasting consumption: In the broadcasting consumption mode, each message is pushed to all registered consumers in the cluster to ensure that the message is consumed at least once by each consumer.
Scenarios
Clustering consumption: Suitable for scenarios where each message only needs to be processed once.
Broadcasting consumption: Suitable for scenarios where each message needs to be processed by every consumer in the cluster.
Sample Code
Clustering subscription
The 5.0 SDK uses the clustering consumption mode by default, requiring no special configuration.
Note:
Make sure that the subscription relationships are consistent across all consumer instances under the same group ID.
All consumers identified by the same group ID share the consumption of messages on average. For example, if a topic has 9 messages and a group ID has 3 consumer instances, in the clustering consumption mode, each instance shares the load equally and consumes only 3 of those messages.
properties.put(PropertyKeyConst.MessageModel, PropertyValueConst.CLUSTERING);
Broadcast subscription
The 5.0 SDK no longer supports broadcasting consumption. If you need to use the mode, you can create a separate subscription group for each consumer to achieve similar functionality.
Note:
Make sure that the subscription relationships are consistent across all consumer instances under the same group ID.
All consumers identified by the same group ID will each consume every message once. For example, if a topic has 9 messages and a group ID has 3 consumer instances, in the broadcasting consumption mode, each instance will consume all 9 messages.
properties.put(PropertyKeyConst.MessageModel, PropertyValueConst.BROADCASTING);
Note
Make sure that the subscription relationships are consistent across all consumer instances under the same group ID.