This document describes the features and use cases of cluster consumption and broadcast consumption in the RocketMQ.
Feature Introduction
Cluster consumption: In the cluster consumption mode, any message only needs to be processed by any consumer in the cluster.
Broadcast consumption: In the broadcast consumption mode, each message will be pushed to all registered consumers in the cluster, ensuring that each message is consumed at least once by each consumer.
Use Cases
Cluster consumption: Suitable for scenarios where each message needs to be processed only once.
Broadcast consumption: Suitable for scenarios where each message needs to be processed by every consumer in the cluster.
Sample Code
Cluster subscription
The SDK 5.0 defaults to cluster consumption mode with no need for special settings.
Notes:
Make sure that all consumer instances under the same group ID have consistent subscription configurations.
All consumers identified by the same Group ID share consumption messages equally. For example, if a Topic has 9 messages and a Group ID has 3 Consumer instances, then in cluster consumption mode, each instance evenly distributes and only consumes 3 of them.
properties.put(PropertyKeyConst.MessageModel, PropertyValueConst.CLUSTERING);
Broadcast subscription
5.0 SDK does not support broadcast consumption. If required, you can create a separate subscription group for each consumer to implement similar functionality.
Notes:
Make sure that all consumer instances under the same group ID have consistent subscription configurations.
All consumers identified by the same Group ID consume each message once. For example, if a Topic has 9 messages and a Group ID has 3 Consumer instances, then in broadcast consumption mode, each instance consumes all 9 messages.
properties.put(PropertyKeyConst.MessageModel, PropertyValueConst.BROADCASTING);
Note
Make sure that all consumer instances under the same group ID have consistent subscription configurations.