For cloud migration or testing, you can enable automatic Group creation to create Groups directly from your code. This eliminates the need for manual creation in the console, which simplifies operations and improves efficiency.
Prerequisites
You have purchased and deployed an ApsaraMQ for Kafka instance. The instance must meet the following conditions:
Item | Description |
Status | Running. |
Version | The major version is 2.2.0, and the minor version is the latest. |
You can view the instance status and version in the Basic Information section on the Instance Details page of the ApsaraMQ for Kafka console.
Precautions
In a production environment, do not leave automatic Group creation enabled for long periods. Improper use by clients can lead to uncontrolled resource consumption. This increases O&M costs and can cause system instability. Create Groups manually in the ApsaraMQ for Kafka console or by calling the OpenAPI to manage them centrally. For more information, see Create a Group and CreateConsumerGroup.
Procedure
Log on to the ApsaraMQ for Kafka console. In the Resource Distribution section of the Overview page, select the region where the ApsaraMQ for Kafka instance that you want to manage resides.
On the Instances page, click the name of the instance that you want to manage.
In the Configuration Information section, turn on the Flexible Group Creation switch.
ImportantA custom Group name must follow the Group naming convention:
A Group name must be 3 to 128 characters in length.
A Group name can contain only letters, digits, hyphens (-), and underscores (_). It must contain at least one letter or digit.
The number of automatically created Groups cannot exceed the limit of your ApsaraMQ for Kafka instance specification. If the limit is reached, Groups cannot be automatically created. For more information, see Limits.
After you enable automatic Group creation in the ApsaraMQ for Kafka console, the automatically created Groups are displayed on the Groups page. The description for these Groups is "Automatically created."
For Groups created using this feature, the corresponding Group information is displayed on the Groups page in the console. The Auto Creation column is set to Yes.
When the Flexible Group Creation feature is enabled, ApsaraMQ for Kafka allows groups that are not created in the console to call APIs for operations such as message consumption and offset commits. If this feature is disabled, groups that are not created in the console cannot consume messages. Disable this feature with caution.
Disabling automatic Group creation is an asynchronous process. During this process, nodes are not restarted. The instance status changes to Upgrading. After the feature is disabled, the status returns to In Service. Avoid creating new Groups automatically while this feature is being disabled.
If you do not enable automatic Group creation but use the Assign method to commit consumer offsets, a corresponding Group is also created on the Kafka cluster. This capability is enabled by default. To disable it, submit a ticket.
The server-side cleans up automatically created Groups after their consumer offsets expire.
After you enable free usage for Groups, you can call an API on the consumer side to use a Group. The sample code is as follows:
props.put(ConsumerConfig.GROUP_ID_CONFIG, "newConsumerGroup"); consumer.subscribe(Collections.singletonList("newTopicName")); // If the Group does not exist and its name is valid, it is automatically created. consumer.poll(Duration.ofSeconds(1));
References
After you use an automatically created Group to subscribe to a topic, you can view the Groups that are subscribed to the topic in the console. For more information, see View Groups subscribed to a topic.
To create a Group using the console or an API, see Create a Group and CreateConsumerGroup.