All Products
Search
Document Center

ApsaraMQ for RocketMQ:Subscriptions

Last Updated:Oct 27, 2025

This topic describes the definition, model relationship, internal attributes, and usage recommendations for subscriptions in ApsaraMQ for RocketMQ.

Definition

A subscription is a set of rules and status configurations that consumers use to obtain and process messages in the ApsaraMQ for RocketMQ system.

Consumer groups dynamically register subscriptions with the server. During message transmission, messages are matched and consumption progress is maintained based on the filter rules that are defined in the subscription.

By configuring a subscription, you can control the following transmission behaviors:

  • Collection of subscribed messages: This controls which messages a consumer subscribes to and which messages within a topic the consumer consumes.

  • Consumption progress: ApsaraMQ for RocketMQ servers provide subscription persistence by default. After a consumer group registers a subscription with the server, if a consumer goes offline and then comes back online, the consumer can retrieve its previous consumption progress and resume consumption.

Mapping relationship between topics and consumer groups

A topic can be subscribed to by multiple consumer groups

ApsaraMQ for RocketMQ supports a one-to-many subscription model. The subscription of each consumer group to a topic is independent. Each group can subscribe to all or a portion of the messages in the topic.

image.png

A consumer group can subscribe to multiple topics

As shown in the following figure, the consumer group Group A subscribes to two topics: Topic A and Topic B. For consumers in Group A, the subscription to Topic A is one subscription relationship, and the subscription to Topic B is another. The two subscriptions are independent and can be defined separately without affecting each other.

image.png

Internal attributes

Consumption mode

  • Definition: The mode in which consumers consume messages.

  • Values:

    • CLUSTERING: This mode is used to subscribe to topics that are not Lite-type topics. Messages are delivered to one consumer in the consumer group based on load balancing rules.

    • LITE_SELECTIVE: This mode is used to subscribe to Lite-type topics. Different consumers in the same consumer group can subscribe to different collections of Lite topics.

Message filtering properties

When the consumption mode is CLUSTERING, you can use message filtering configurations.

Filter type

  • Definition: The type of a message filtering rule. After you set a message filtering rule for a subscription, the system matches messages in the topic based on the rule. Only messages that meet the specified conditions are delivered to consumers. This feature allows for further message categorization.

  • Values:

    • TAG filtering: Filters and matches messages based on the full text of tag strings.

    • SQL92 filtering: Filters and matches message attributes based on SQL syntax.

Filter expression

Behavioral constraints

When the consumption mode is CLUSTERING

When the consumption mode is CLUSTERING, the subscription relationships and consumption logic for every consumer within the same consumer group must be consistent. Otherwise, consumption conflicts occur, which can cause abnormal consumption for some messages.

  • Correct example

    //Consumer c1
    Consumer c1 = ConsumerBuilder.build(groupA);
    c1.subscribe(topicA,"TagA");
    //Consumer c2
    Consumer c2 = ConsumerBuilder.build(groupA);
    c2.subscribe(topicA,"TagA");
  • Incorrect example

    //Consumer c1
    Consumer c1 = ConsumerBuilder.build(groupA);
    c1.subscribe(topicA,"TagA");
    //Consumer c2
    Consumer c2 = ConsumerBuilder.build(groupA);
    c2.subscribe(topicA,"TagB");

When the consumption mode is LITE_SELECTIVE

When the consumption mode is LITE_SELECTIVE, different consumers within the same consumer group can subscribe to different collections of Lite topics. As shown in the following figure, Consumer 1 subscribes to LiteTopic1 and LiteTopic2, and Consumer 2 subscribes to LiteTopic3 and LiteTopic4.

Lite topics can be dynamically added to or removed from each consumer's subscription collection in real time.

image.png