Modern C++ Kafka API
Public Member Functions | List of all members
KAFKA_API::clients::consumer::UnorderedOffsetCommitQueue Class Reference

The queue can be used to determine the right offset to commit. More...

#include <UnorderedOffsetCommitQueue.h>

Public Member Functions

 UnorderedOffsetCommitQueue (const Topic &topic, Partition partition)
 
std::size_t size () const
 Return how many received offsets have not been popped to commit (with popOffsetToCommit()).
 
void waitOffset (Offset offset)
 Add an offset (for a ConsumerRecord) to the waiting list, until it being acked (with ackOffset). More...
 
void ackOffset (Offset offset)
 Ack the record has been handled and ready to be committed. More...
 
Optional< Offset > popOffsetToCommit ()
 Pop the offset which is ready for the consumer (if any).
 
Optional< Offset > lastPoppedOffset ()
 Return the offset last popped.
 

Detailed Description

The queue can be used to determine the right offset to commit.

A KafkaManuallyCommitConsumer might forward the received records to different handlers, while these handlers could not ack the records in order. Then, the UnorderedOffsetCommitQueue would help,

  1. Prepare an UnorderedOffsetCommitQueue for each topic-partition.
  2. Make sure call waitOffset() for each record received.
  3. Make sure call ackOffset() while a handler acks for an record.
  4. Figure out whether there's offset to commit with popOffsetToCommit() and commit the offset then.

Member Function Documentation

◆ ackOffset()

void KAFKA_API::clients::consumer::UnorderedOffsetCommitQueue::ackOffset ( Offset  offset)
inline

Ack the record has been handled and ready to be committed.

Note: If all offsets ahead has been acked, then with popOffsetToCommit(), we'd get offset + 1, which is ready to be committed for the consumer.

◆ waitOffset()

void KAFKA_API::clients::consumer::UnorderedOffsetCommitQueue::waitOffset ( Offset  offset)
inline

Add an offset (for a ConsumerRecord) to the waiting list, until it being acked (with ackOffset).

Note: Make sure the offset would be ack later with ackOffset().


The documentation for this class was generated from the following file: