All Products
Search
Document Center

ApsaraMQ for RocketMQ:Clustering consumption mode and broadcasting consumption mode

Last Updated:Nov 02, 2023

ApsaraMQ for RocketMQ supports the clustering consumption mode and the broadcasting consumption mode. This topic describes the basic concepts, scenarios, usage notes, and configuration methods of the modes. This topic also describes the feature differences between the modes.

Background information

ApsaraMQ for RocketMQ is a messaging system that is based on the Publish-Subscribe pattern. In ApsaraMQ for RocketMQ, a consumer subscribes to a topic to obtain and consume messages.

In most cases, consumer applications are clustered and deployed in a distributed system. When you subscribe to a topic, you can specify the clustering consumption mode or the broadcasting consumption mode for your consumer clients based on your business requirements. Consumers in the same group consume messages based on the consumption mode that you specified.

Consumers that are identified by the same group ID belong to the same group and must use the same consumption logic and tags. For more information, see Subscription consistency.

Clustering consumption mode

Basic concept

Clustering consumption mode: In this mode, ApsaraMQ for RocketMQ delivers a message to only one of the consumers in the group.

Scenarios

This mode is suitable for scenarios in which consumer instances are deployed in a group and each message needs to be processed only once. The following figure shows an example on how to consume messages in clustering consumption mode.集群消费

Broadcasting consumption mode

Basic concept

Broadcasting consumption mode: In this mode, ApsaraMQ for RocketMQ broadcasts each message to all consumers in a group to ensure that the message is consumed by each consumer at least once.

Scenarios

This mode is suitable for scenarios in which consumer instances are deployed in a group and each message needs to be processed by each consumer in the group. The following figure shows an example on how to consume messages in broadcasting consumption mode.广播消费

Feature differences between the clustering consumption mode and the broadcasting consumption mode

The availability of features varies based on the consumption mode. The following table lists the features that are available in clustering consumption mode and the features that are available in broadcasting consumption mode.

Feature

Clustering consumption mode

Broadcasting consumption mode

TCP client SDKs

对号对号

HTTP client SDKs

对号错号

Ordered messages

对号错号

Consumer offset resetting

对号错号

Message retry

对号错号

Accumulated message query and message accumulation alerting

对号错号

Subscription query

对号错号

Consumer progress

Consumer progress is maintained by brokers.

  • The service reliability is higher in clustering consumption mode than that in broadcasting consumption mode. After a consumer is restarted, the consumer continues to consume messages based on the last consumption progress.

  • Message retry is supported by brokers. For more information, see Message retry.

Consumer progress is maintained by consumers.

The probability that a message is repeatedly consumed in broadcasting consumption mode is higher than that in clustering consumption mode. Each time a consumer is restarted, the consumer starts consumption from the latest message.

Note

对号: The feature is supported by the mode.

错号: The feature is not supported by the mode.

Usage notes

Make sure that you specify the same consumption mode for consumers in the same group. If you specify different consumption modes for consumers in the same group, the broadcasting consumption mode takes effect.

For example, you create a group with five consumers. If you specify the clustering consumption mode for two consumers in the group and the broadcasting consumption mode for the other three consumers in the group, the broadcasting consumption mode is used for all five consumers.

Clustering consumption mode

  • In clustering consumption mode, each message is delivered to only one consumer in a group for processing. If a message needs to be processed by each consumer in the group, use the broadcasting consumption mode.

  • In clustering consumption mode, a message may be routed to different consumers during message retries.

Broadcasting consumption mode

  • In broadcasting consumption mode, ApsaraMQ for RocketMQ ensures that a message is delivered to each consumer at least once for consumption, but does not redeliver messages that fail to be consumed. You need to manually handle consumption failures.

  • In broadcasting consumption mode, a consumer starts message consumption from the latest message each time the consumer is restarted. The consumer automatically skips the messages that are sent to the ApsaraMQ for RocketMQ broker when the consumer is stopped. Exercise caution when you use this mode.

  • In broadcasting consumption mode, each message is repeatedly processed by a large number of consumers. We recommend that you use the clustering consumption mode in most cases.

Configuration methods

If you use a client SDK to subscribe to messages, you can configure the relevant parameter in the SDK to specify a consumption mode.

TCP client SDKs

  • Clustering consumption mode

    // Set the MessageModel parameter to CLUSTERING. By default, the clustering consumption mode is used. 
    properties.put(PropertyKeyConst.MessageModel, PropertyValueConst.CLUSTERING);
  • Broadcasting consumption mode

    // Set the MessageModel parameter to BROADCASTING. 
    properties.put(PropertyKeyConst.MessageModel, PropertyValueConst.BROADCASTING); 

The preceding sample code is compiled in Java. For information about how to specify a consumption mode in other programming languages, see the following topics:

HTTP client SDKs

HTTP client SDKs support only the clustering consumption mode. You do not need to specify a consumption mode on HTTP client SDKs. For more information, see Usage notes.