简体   繁体   English

如何在java中的kafka中获取消费者群体的消费者滞后

[英]How to get Consumer Lag for a consumer group in kafka in java

I want to know the consumer lag for a consumer group using java. 我想知道使用java的消费者群体的消费者滞后。 I have tried using 我试过用

kafka-consumer-groups --describe --bootstrap-server localhost:9092 --group MyGroupName

and the lag is visible. 并且滞后是可见的。

How do i do this in Java ? 我如何用Java做到这一点?

I have tried using the org.apache.kafka.clients.admin.AdminClient , but could not get the lag per consumer group. 我尝试过使用org.apache.kafka.clients.admin.AdminClient ,但无法获得每个使用者组的延迟。

i am using confluent 5.0.1 which has kafka 2.0.1 org.apache.kafka - kafka-clients - 2.0.1 我正在使用confluent 5.0.1 which has kafka 2.0.1 org.apache.kafka - kafka-clients - 2.0.1

Lag is approximately endOffset-currentOffset . 滞后大约是endOffset-currentOffset You can use 您可以使用

AdminClient.listConsumerGroupOffsets("MyGroupName").partitionsToOffsetAndMetadata()

to get the current offset for the group. 获取组的当前偏移量。 To get the end offsets you need to create KafkaConsumer for the topic and use 要获得结束偏移,您需要为主题和使用创建KafkaConsumer

KafkaConsumer.endOffsets(partitions)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM