如何使用python列出卡夫卡消费者群 [英] How to list Kafka consumer group using python
本文介绍了如何使用python列出卡夫卡消费者群的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想使用python获取Kafka消费者组列表,但我不能.
I want to get Kafka consumer group list with python but I couldn't.
我使用过Zookeeper的python客户端(kazoo),但是消费者组列表为空,因为这种方法适用于旧消费者,而我们没有使用旧消费者.
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.
如何获取带有python代码的消费者组列表?
How can I get consumer group list with python code?
./kafka-consumer-groups.sh -bootstrap-server localhost:9092 -list
推荐答案
您可以使用 kafka轻松列出消费者组-python .
只需向集群中的任何代理发送ListGroupsRequest
.
Just send a ListGroupsRequest
to any of the brokers in your cluster.
例如:
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)
这篇关于如何使用python列出卡夫卡消费者群的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文