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
You can easily list consumer groups with kafka-python.
Just send a ListGroupsRequest to any of the brokers in your cluster.
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)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With