How to list Kafka consumer group using python

How to list Kafka consumer group using python



I want to get Kafka consumer group list with python but I couldn't.



I use to zookeeper python client( kazoo) but consumer group list empty because this method for old consumer and we are not using old consumer.



How can I get consumer group list with python code?


./kafka-consumer-groups.sh -bootstrap-server localhost:9092 -list




2 Answers
2



You can easily list consumer groups with kafka-python.



Just send a ListGroupsRequest to any of the brokers in your cluster.


ListGroupsRequest



For example:


from kafka import BrokerConnection
from kafka.protocol.admin import *
import socket

bc = BrokerConnection('localhost', 9092, socket.AF_INET)
bc.connect_blocking()

list_groups_request = ListGroupsRequest_v1()

future = bc.send(list_groups_request)
while not future.is_done:
for resp, f in bc.recv():
f.success(resp)

for group in future.value.groups:
print(group)





Thank you for your answer.
– BigData
Sep 12 at 20:30



KIP-222 was recently introduced to enable Java clients to retrieve all consumer groups. Maybe it needs more time to have librdkafka or python client support this. See details in this issue.





There's other Python libraries than the Confluent librd based ones, though
– cricket_007
Aug 30 at 13:51



Required, but never shown



Required, but never shown






By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.