Class ConsumerRecords<K,V>
java.lang.Object
org.apache.kafka.clients.consumer.ConsumerRecords<K,V>
- All Implemented Interfaces:
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 Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionConsumerRecords(Map<TopicPartition, List<ConsumerRecord<K, V>>> records) Deprecated, for removal: This API element is subject to removal in a future version.Since 4.0.ConsumerRecords(Map<TopicPartition, List<ConsumerRecord<K, V>>> records, Map<TopicPartition, OffsetAndMetadata> nextOffsets) Constructs a new ConsumerRecords with the given records and next offsets. -
Method Summary
Modifier and TypeMethodDescriptionintcount()The number of records for all topicsstatic <K,V> ConsumerRecords <K, V> empty()Returns an empty ConsumerRecords instance.booleanisEmpty()Returns whether this container has any records.iterator()Get the next offsets and metadata corresponding to all topic partitions for which the position have been advanced in this poll callGet the partitions which have records contained in this record set.Get just the records for the given topicList<ConsumerRecord<K, V>> records(TopicPartition partition) Get just the records for the given partitionMethods inherited from class Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface Iterable
forEach, spliterator
-
Field Details
-
EMPTY
-
-
Constructor Details
-
ConsumerRecords
@Deprecated(since="4.0", forRemoval=true) public ConsumerRecords(Map<TopicPartition, List<ConsumerRecord<K, V>>> records) Deprecated, for removal: This API element is subject to removal in a future version.Since 4.0. UseConsumerRecords(Map, Map)instead. -
ConsumerRecords
public ConsumerRecords(Map<TopicPartition, List<ConsumerRecord<K, V>>> records, Map<TopicPartition, OffsetAndMetadata> nextOffsets) Constructs a new ConsumerRecords with the given records and next offsets.- Parameters:
records- The records for each partitionnextOffsets- The next offset and metadata for each partition whose position was advanced during the poll call. These represent the offsets that the consumer will start reading from on the next poll.
-
-
Method Details
-
records
Get just the records for the given partition- Parameters:
partition- The partition to get records for
-
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
Get just the records for the given topic -
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
-
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
Returns an empty ConsumerRecords instance.- Type Parameters:
K- The key typeV- The value type- Returns:
- An empty ConsumerRecords
-