All Products
Search
Document Center

ApsaraMQ for Kafka:Use the flexible group creation feature

Last Updated:Jan 15, 2024

In cloud migration or testing scenarios, you can enable the flexible group creation feature for an ApsaraMQ for Kafka instance. This way, you can create groups by writing code instead of using the ApsaraMQ for Kafka console. The flexible group creation feature helps simplify operations and improve efficiency.

Prerequisites

An ApsaraMQ for Kafka instance that meets the following conditions is purchased and deployed.

Item

Description

Status

Running

Version

Major version: 2.2.0. Minor version: latest.

Note

You can view the status and version of the instance in the Basic Information section of the Instance Details page in the ApsaraMQ for Kafka console.

Usage notes

In production environments, we recommend that you create and manage groups in the ApsaraMQ for Kafka console or by calling API operations. If you use the flexible group creation feature for a long time, excessive use of groups that do not exist in the console may cause resource waste, complicate O&M, and poor system stability. For more information, see Step 2: Create a group and CreateConsumerGroup.

Procedure

  1. 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.

  2. On the Instances page, click the name of the instance that you want to manage.

  3. In the Configuration Information section, turn on the Flexible Group Creation switch.

    Important
    • If you want to use the flexible group creation feature, you must specify a group name that complies with the following naming conventions:

      • The group name must be 3 to 128 characters in length.

      • The group name can contain only letters, digits, hyphens (-), and underscores (_) and must contain at least one letter or digit.

    • The maximum number of groups that you can use cannot exceed the group limit specified for ApsaraMQ for Kafka instances. For more information, see Limits.

    • If you turn on the Flexible Group Creation switch in the ApsaraMQ for Kafka console, the groups that you can use are displayed on the Groups page. The description Automatically created is displayed for a group that is automatically created.

    • If a group is automatically created, the information about the group is displayed on the Groups page and Yes is displayed in the Auto Creation column of the corresponding group.

    • If you turn on the Flexible Group Creation switch, ApsaraMQ for Kafka allows groups that are automatically created in the ApsaraMQ for Kafka console to call API operations to consume messages and commit consumer offsets. If you turn off the Flexible Group Creation switch, the groups that are automatically created cannot consume messages as expected. We recommend that you take necessary precautions when you perform this action.

    After you turn on the Flexible Group Creation switch, you can call API operations to use groups that are automatically created. Sample code:

    props.put(ConsumerConfig.GROUP_ID_CONFIG, "newConsumerGroup");
    consumer.subscribe(Collections.singletonList("newTopicName"));
    // If the group does not exist in the ApsaraMQ for Kafka console and the group name complies with the naming conventions, you can use the group to consume messages. 
    consumer.poll(Duration.ofSeconds(1));

References