title: Code to find the lag in the consumer offset using kafka library?
body: <p>I want to get the progress of the kafka consumer i.e. Lag. I know the following commands give me the lag and other valuable description.</p>
  
  <p><code>bin/kafka-run-class.sh kafka.admin.ConsumerGroupCommand --zookeeper localhost:2182 --describe --group DemoConsumer</code></p>
  
  <p><code>bin/kafka-consumer-groups.sh --zookeeper localhost:2182 --describe --group DemoConsumer</code></p>
  
  <p>I can also get the current consumer offset using following code snippet with the help of kafka-client </p>
  
  <pre><code>ConsumerRecords&lt;Integer, String&gt; records = consumer.poll(100);
  for (ConsumerRecord&lt;Integer, String&gt; record : records) {
  
               System.out.println("Received message: (" + record.topic()+ ",
               " + record.partition()+ ", " + record.key() + ", " +
               record.value() + ") at offset " + record.offset());
  }
  </code></pre>
  
  <p>But I can't find a code to get the details as the above two commands. Is there any code to find the lag and other details using kafka library? </p>