Reputation: 115
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
Upvotes: 6
Views: 8058
Reputation: 190
You may do this just by using kafka-python module.
from kafka import KafkaAdminClient
client = KafkaAdminClient(bootstrap_servers="localhost:9092")
for group in client.list_consumer_groups():
print(group[0])
Upvotes: 3
Reputation: 26950
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)
Upvotes: 5
Reputation: 7091
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.
Upvotes: 0