title: Kafka last produced and committed offsets during rebalancing
body: <p>The below code snippet uses kafka admin client to retrieve the last committed and produced offsets of all partitions for  a certain consumer group namely CONSUMER_GROUP :</p>
  
  <pre class="lang-java prettyprint-override"><code>Map&lt;TopicPartition, OffsetAndMetadata&gt; offsets = admin.listConsumerGroupOffsets(CONSUMER_GROUP).partitionsToOffsetAndMetadata().get();
  Map&lt;TopicPartition, OffsetSpec&gt; requestLatestOffsets = new HashMap&lt;&gt;();
  for(TopicPartition tp: offsets.keySet()) {
      requestLatestOffsets.put(tp, OffsetSpec.latest());
  }
  Map&lt;TopicPartition, ListOffsetsResult.ListOffsetsResultInfo&gt; latestOffsets = admin.listOffsets(requestLatestOffsets).all().get();
  for (Map.Entry&lt;TopicPartition, OffsetAndMetadata&gt; e: offsets.entrySet()) {
      String topic = e.getKey().topic();
      int partition = e.getKey().partition();
      long committedOffset = e.getValue().offset();
      long latestOffset = latestOffsets.get(e.getKey()).offset();
      System.out.println(&quot;Consumer group &quot; + CONSUMER_GROUP + &quot; has committed offset &quot; + committedOffset + &quot; to topic &quot; + topic + &quot; partition &quot; + partition  + &quot;. The latest offset in the partition is &quot; + latestOffset + &quot; so consumer  group is &quot;+ (latestOffset - committedOffset) + &quot; records behind&quot;);
  }
  </code></pre>
  <p>Can you please hint me on the below points:</p>
  <ol>
  <li><p>if the consumer group is in rebalancing state (or another unstable state), would that (how) affect the returned last and committed offsets? [say I am committing the offsets manually and use the consumer rebalance listener to commit the latest processed offsets before rebalancing]</p>
  </li>
  <li><p>Given the code above, are there any specific way to know wether the group is undergoing a rebalance (or is generally in unstable state) when the admin request is being served by the Kafka brokers?</p>
  </li>
  <li><p>If I am interested in retrieving the latest offsets of specific topic partitions that are not member of any consumer group, how could I achieve this? and hence, why the latest offsets are bound to a specific consumer group, since they are sent by producer irrespective of any consumer group?</p>
  </li>
  </ol>
  <p>Thank you.</p>