如何使用python列出Kafka消费者组 [英] How to list Kafka consumer group using python

查看:52
本文介绍了如何使用python列出Kafka消费者组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想用 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

推荐答案

您可以使用 轻松列出消费者群体卡夫卡蟒蛇.

只需向集群中的任何代理发送一个 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列出Kafka消费者组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆