The lag in Kafka topic calculated in the following way: endOffsets - committedOffsets
To fetch this the following steps can be made:
- Get available
TopicPartitions
withAdminClient
describeTopics(java.util.Collection<java.lang.String> topicNames) API. - Create a consumer and fetch the endOffsets with endOffsets(java.util.Collection<TopicPartition> partitions) API.
This can be fetched with AdminClient
listConsumerGroupOffsets(java.lang.String groupId) API.