title: How to read all the records in a Kafka topic
body: <p>I am using kafka : kafka_2.12-2.1.0, spring kafka on client side and have got stuck with an issue.</p>
  
  <p>I need to load an in-memory map by reading all the existing messages within a kafka topic. I did this by starting a new consumer (with a unique consumer group id and setting the offset to <code>earliest</code>). Then I iterate over the consumer (poll method) to get all messages and stop when the consumer records become empty.</p>
  
  <p>But I noticed that, when I start polling, the first few iterations return consumer records as empty and then it starts returning the actual records. Now this breaks my logic as our code thinks there are no records in the topic.</p>
  
  <p>I have tried few other ways (like using offsets number) but haven't been able to come up with any solution, apart from keeping another record somewhere which tells me how many messages there are in the topic which needs to be read before I stop.</p>
  
  <p>Any idea's please ?</p>