Class PollContext<K,V>
- All Implemented Interfaces:
Iterable<RecordContext<K,V>>
public class PollContext<K,V> extends Object implements Iterable<RecordContext<K,V>>
Results sets can be iterated in a variety of ways. Explore the different methods available.
You can access for ConsumerRecords directly, or you can get the RecordContext wrappers, which provide
extra information about the specific records, such as RecordContext.getNumberOfFailedAttempts().
Note that if you are not setting a ParallelConsumerOptions.batchSize, then you can use the getSingleRecord(), and it's convenience accessors (value(), offset(), key() getSingleConsumerRecord()). But if you have configured batching, they will all throw an IllegalArgumentException, as it's not valid to have batches of messages and yet tread the batch input as a single
record.
-
Field Summary
-
Constructor Summary
Constructors Constructor Description PollContext() -
Method Summary
Modifier and Type Method Description protected booleancanEqual(Object other)booleanequals(Object o)voidforEach(Consumer<? super RecordContext<K,V>> action)Map<org.apache.kafka.common.TopicPartition,Set<RecordContext<K,V>>>getByTopicPartitionMap()List<org.apache.kafka.clients.consumer.ConsumerRecord<K,V>>getConsumerRecordsFlattened()List<RecordContext<K,V>>getContextsFlattened()Map<org.apache.kafka.common.TopicPartition,List<Long>>getOffsets()Map of partitions to offsets.List<Long>getOffsetsFlattened()Get all the offsets for the records in this result set.org.apache.kafka.clients.consumer.ConsumerRecord<K,V>getSingleConsumerRecord()Must not be using batching (ParallelConsumerOptions.batchSize).RecordContext<K,V>getSingleRecord()Must not be using batching (ParallelConsumerOptions.batchSize).inthashCode()Iterator<RecordContext<K,V>>iterator()Kkey()For backwards compatibility withConsumerRecord.key().longoffset()For backwards compatibility withConsumerRecord.offset().longsize()Spliterator<RecordContext<K,V>>spliterator()Stream<RecordContext<K,V>>stream()Stream<org.apache.kafka.clients.consumer.ConsumerRecord<K,V>>streamConsumerRecords()Stream<RecordContextInternal<K,V>>streamInternal()StringtoString()Vvalue()For backwards compatibility withConsumerRecord.value().
-
Field Details
-
Constructor Details
-
PollContext
public PollContext()
-
-
Method Details
-
streamInternal
- Returns:
- a flat
StreamofRecordContexts, which wrap theConsumerRecords in this result set
-
stream
- Returns:
- a flat
StreamofRecordContexts, which wrap theConsumerRecords in this result set
-
streamConsumerRecords
- Returns:
- a flat
StreamofConsumerRecordin this poll set
-
getSingleRecord
Must not be using batching (ParallelConsumerOptions.batchSize).- Returns:
- the single
RecordContextentry in this poll set - Throws:
IllegalArgumentException- if aParallelConsumerOptions.getBatchSize()has been set.
-
getSingleConsumerRecord
Must not be using batching (ParallelConsumerOptions.batchSize).- Returns:
- the single
ConsumerRecordentry in this poll set - See Also:
getSingleRecord()
-
value
For backwards compatibility withConsumerRecord.value().Must not be using batching (
ParallelConsumerOptions.batchSize).- Returns:
- the single
ConsumerRecord.value()entry in this poll set - See Also:
getSingleRecord()
-
key
For backwards compatibility withConsumerRecord.key().Must not be using batching (
ParallelConsumerOptions.batchSize).- Returns:
- the single
ConsumerRecord.key()entry in this poll set - See Also:
getSingleRecord()
-
offset
public long offset()For backwards compatibility withConsumerRecord.offset().Must not be using batching (
ParallelConsumerOptions.batchSize).- Returns:
- the single
ConsumerRecord.offset()entry in this poll set - See Also:
getSingleRecord()
-
getContextsFlattened
- Returns:
- a flat
ListofRecordContexts, which wrap theConsumerRecords in this result set
-
getConsumerRecordsFlattened
- Returns:
- a flat
ListofConsumerRecords in this result set
-
iterator
- Specified by:
iteratorin interfaceIterable<K>- Returns:
- a flat
Iteratorof theRecordContexts, which wrap theConsumerRecords in this result set
-
forEach
- Specified by:
forEachin interfaceIterable<K>- Parameters:
action- to perform on theRecordContexts, which wrap theConsumerRecords in this result set
-
spliterator
- Specified by:
spliteratorin interfaceIterable<K>- Returns:
- a flat
Spliteratorof theRecordContexts, which wrap theConsumerRecords in this result set
-
getByTopicPartitionMap
public Map<org.apache.kafka.common.TopicPartition,Set<RecordContext<K,V>>> getByTopicPartitionMap()- Returns:
- a
MapofTopicPartitiontoRecordContextSet, which wrap theConsumerRecords in this result set
-
size
public long size()- Returns:
- the total count of records in this result set
-
getOffsetsFlattened
Get all the offsets for the records in this result set.Note that this flattens the result, so if there are records from multiple
TopicPartitions, the partition they belong to will be lost. If you want that information as well, trygetOffsets().- Returns:
- a flat List of offsets in this result set
- See Also:
getOffsets()
-
getOffsets
Map of partitions to offsets.If you don't need the partition information, try
getOffsetsFlattened().- Returns:
- a map of
TopicPartitionto offsets, of the records in this result set - See Also:
getOffsetsFlattened()
-
toString
-
equals
-
canEqual
-
hashCode
public int hashCode()
-