I want to know the consumer lag for a consumer group using 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 ?
I have tried using the org.apache.kafka.clients.admin.AdminClient
, but could not get the lag per consumer group.
i am using confluent 5.0.1 which has kafka 2.0.1 org.apache.kafka - kafka-clients - 2.0.1
Lag is approximately 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.endOffsets(partitions)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.