Update the consumption progress
Updates the checkpoint of a shard for a specified consumer group by calling the ConsumerGroupUpdateCheckPoint API.
Prerequisites
-
Simple Log Service is activated. For more information, see Activate Simple Log Service.
-
The Simple Log Service SDK for Python is initialized. For more information, see Initialize Simple Log Service SDK for Python.
Parameter description
def update_check_point(self, project, logstore, consumer_group, shard, check_point,
consumer='', force_success=True):
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. |
|
shard |
int |
Yes |
The ID of the shard. |
|
check_point |
String |
Yes |
The checkpoint of the shard from which the consumer group consumes data. |
|
consumer |
String |
No |
The name of the consumer. |
|
force_success |
bool |
No |
Specifies whether to force the update. If consumer is not specified, set this parameter to True.
|
Response parameters
For more information about response parameters, see ConsumerGroupUpdateCheckPoint.
Sample code
from aliyun.log import LogClient
import os
# 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)
# The name of the project
project = "project-1"
# The name of the logstore
logstore = "logstore-1"
# The name of the consumer group
consumer_group = "consumer_group_test"
# The ID of the shard
shard = 0
# The name of the checkpoint
check_point = "check_point_1"
# The name of the consumer
consumer = ''
force_success = True
try:
# Create the consumer group for the specified project.
response = client.update_check_point(project, logstore, consumer_group, shard, check_point,
consumer, force_success)
response.log_print()
except Exception as e:
print(f"An error occurred while creating the consumer group: {e}")
Sample response
header: {'Server': 'AliyunSLS', 'Content-Length': '0', 'Connection': 'keep-alive', 'Access-Control-Allow-Origin': '*', 'Date': 'Fri, 25 Oct 2024 02:11:00 GMT', 'x-log-time': '1729822260', 'x-log-requestid': '671AFE342B225A2F8FD03D85'}
References
-
For more information about log consumption APIs, see the following topics:
-
For more sample code, see Alibaba Cloud Simple Log Service SDK for Python on GitHub.