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