Query consumer groups
Updated at:
Retrieves all consumer groups associated with a specific Logstore by calling the ListConsumerGroup API operation.
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 list_consumer_group(self, project, logstore):
Request parameters
|
Parameter |
Type |
Required |
Description |
|
project |
String |
Yes |
The name of the project. |
|
logstore |
String |
Yes |
The name of the logstore. |
Response parameters
For information about the response parameters, see ListConsumerGroup.
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"
try:
# Create a consumer group for the specified project.
response = client.list_consumer_group(project, logstore)
response.log_print()
except Exception as e:
print(f"An error occurred while creating the consumer group: {e}")
if __name__ == '__main__':
main()
Sample response
ListConsumerGroupResponse:
headers: {'Server': 'AliyunSLS', 'Content-Type': 'application/json', 'Content-Length': '59', 'Connection': 'keep-alive', 'Access-Control-Allow-Origin': '*', 'Date': 'Thu, 24 Oct 2024 11:34:05 GMT', 'x-log-time': '1729769645', 'x-log-requestid': '671A30AD19073AFD9D*****'}
count: 1
consumer_groups: [{'name': 'consumer_group_test', 'timeout': 30, 'order': False}]
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.
Is this page helpful?