Class ConsumerRecords<K,V>

java.lang.Object
org.apache.kafka.clients.consumer.ConsumerRecords<K,V>
All Implemented Interfaces:
Iterable<ConsumerRecord<K,V>>

@Public public class ConsumerRecords<K,V> extends Object implements Iterable<ConsumerRecord<K,V>>
A container that holds the list ConsumerRecord per partition for a particular topic. There is one ConsumerRecord list for every topic partition returned by a Consumer.poll(java.time.Duration) operation.
  • Field Details

  • Constructor Details

  • Method Details

    • records

      public List<ConsumerRecord<K,V>> records(TopicPartition partition)
      Get just the records for the given partition
      Parameters:
      partition - The partition to get records for
    • nextOffsets

      public Map<TopicPartition, OffsetAndMetadata> nextOffsets()
      Get the next offsets and metadata corresponding to all topic partitions for which the position have been advanced in this poll call
      Returns:
      The next offsets that the consumer will consume
    • records

      public Iterable<ConsumerRecord<K,V>> records(String topic)
      Get just the records for the given topic
    • partitions

      public Set<TopicPartition> partitions()
      Get the partitions which have records contained in this record set.
      Returns:
      The set of partitions with data in this record set (may be empty if no data was returned)
    • iterator

      public Iterator<ConsumerRecord<K,V>> iterator()
      Specified by:
      iterator in interface Iterable<K>
    • count

      public int count()
      The number of records for all topics
    • isEmpty

      public boolean isEmpty()
      Returns whether this container has any records.
      Returns:
      True if there are no records, false otherwise
    • empty

      public static <K,V> ConsumerRecords<K,V> empty()
      Returns an empty ConsumerRecords instance.
      Type Parameters:
      K - The key type
      V - The value type
      Returns:
      An empty ConsumerRecords