title: can I consume kafka messages based on given list of partition ids and offset#?
body: <p>given I have a kafka topic with 4 partitions and each has a few committed messages in it. For some reason I would like to re-play some of the committed messages based on given partition id and offset# , what is the best way to do that with java client lib ?</p>
  
  <p>for example I have </p>
  
  <p>TopicA:</p>
  
  <p>Partition1 : ...offset-1,offset-3,offset-7...</p>
  
  <p>Partition2 : ...offset-2,offset-4,offset-8...</p>
  
  <p>Partition3 : ...offset-5,offset-6,offset-9...</p>
  
  <p>Partition4 : ...offset-10,offset-11,offset-12...</p>
  
  <p>I would like to re-play only</p>
  
  <p>Partition1 : offset-3</p>
  
  <p>Partition2 : offset-8</p>
  
  <p>Partition3 : offset-5</p>
  
  <p>so I have psudo-code like below</p>
  
  <pre><code>props.put("max.poll.records", "1"); // to make sure I only get exactly one desired message on that offset 
  
  ({(1,3),(2,8),(3,5)}).stream(part_offset-&gt; {
    int i=1; // used as loop count down latch
  while(i&gt;=0){
   consumer.assign(get_partition(part_offset.part));
   consumer.seek(new TopicPartition("TopicA", part_offset.part), part_offset.offset);
   records=consumer.pool(Duration.ofSeconds(1)); // I read somewhere kafka is lazy , so should I poll before this ?
   for ( record : records) {
    //do something
    i--;
   }
  
  }
  
  })
  </code></pre>
  
  <p>but code above is not working, it is just hanging there doing nothing.
  just wondering what would be the best approach to replay some messages with given partition id and offset information ? or , do I consume in a wrong fashion ? Please advise</p>
  
  <p>Thanks a lot</p>