是否可以从java应用程序中获取Kafka的消费者列表?目前我只是按照以下方式执行 shell 脚本:
Runtime.getRuntime().exec(/opt/kafka/bin/kafka-consumer-groups.sh --bootstrap-server localhost:9092 --list)
但这似乎是错误的。到目前为止我没有任何其他方法...
最佳答案
当我遇到同样的问题时,我使用了 scala 中的以下内容并将其转换为 Java:
scala.collection.immutable.List<GroupOverview> consumerList = getAdminClient().listAllConsumerGroupsFlattened();
GroupOverview 对象将为您提供开始所需的所有详细信息。
关于Java api 从 Kafka 获取消费者列表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42848198/