Update a consumer group

Updated at:

Modify the timeout period and data consumption order of a consumer group by calling the UpdateConsumerGroup operation.

Prerequisites

Parameter description

def update_consumer_group(self, project, logstore, consumer_group, timeout=None, in_order=None):

Request parameters

Parameter

Type

Required

Description

project

String

Yes

The name of the project.

logstore

String

Yes

The name of the logstore.

consumer_group

String

Yes

The name of the consumer group, which must be unique within the logstore.

timeout

int

No

The timeout period, in seconds. If Simple Log Service does not receive a heartbeat from a consumer within this period, the consumer is deleted.

Important

Either timeout or in_order must be configured.

in_order

bool

No

Specifies whether to consume data in the order it was written. This parameter affects only the consumption order across shards before and after split or merge operations. Default value: False.

  • True: The data in a shard is consumed in sequence.

    • After a shard is split, the original shard data is consumed first, followed by the newly split shard data.

    • After a shard is merged, the original shard data is consumed first, followed by the merged shard data.

  • False: Data is not consumed in sequence across shards. Consumption starts in all shards at the same time. Data in new shards created by shard splits or merges is consumed immediately.

Important

Either timeout or in_order must be configured.

Response parameters

For information about the response parameters, see UpdateConsumerGroup.

Sample code

from aliyun.log import LogClient
import os


def main():
    # In this example, the AccessKey ID and AccessKey Secret are obtained from environment variables.
    access_key_id = os.environ.get('ALIBABA_CLOUD_ACCESS_KEY_ID', '')
    access_key_secret = os.environ.get('ALIBABA_CLOUD_ACCESS_KEY_SECRET', '')
    # Specify a Simple Log Service endpoint.
    endpoint = "cn-hangzhou.log.aliyuncs.com"

    client = LogClient(endpoint, access_key_id, access_key_secret)

    project = "ali-test-peoject"
    logstore = "test-logstore"
    consumer_group = "consumer_group_test"
    timeout = 30
    in_order = False

    try:
        # Update the consumer group for the specified project.
        response = client.update_consumer_group(project, logstore, consumer_group, timeout, in_order)
        response.log_print()
    except Exception as e:
        print(f"An error occurred while updating the consumer group: {e}")


if __name__ == '__main__':
    main()

References