Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What happens if offset specified by kafka consumer is not present in Broker?

I am new to kafka. I want to understand how kafka consumer behaves when offset specified by it is not present. Maybe the message at the given offset is deleted due to retention policy or consumer specified an invalid offset value.

like image 855
Rahul Vedpathak Avatar asked Nov 20 '19 14:11

Rahul Vedpathak


People also ask

Where does Kafka store offsets for consumers?

Kafka maintains a numerical offset for each record in a partition. This offset acts as a unique identifier of a record within that partition, and also denotes the position of the consumer in the partition.

What determines Kafka consumer offset?

The answer is it depends on the offset retention period. The default retention period for message offsets in Kafka is one week (7 days). If Kafka was configured using the default, then to answer the questions above, the offset would begin at 32.

What happens if Kafka consumer is down?

If the consumer crashes or is shut down, its partitions will be re-assigned to another member, which will begin consumption from the last committed offset of each partition. If the consumer crashes before any offset has been committed, then the consumer which takes over its partitions will use the reset policy.

Which consumer in Kafka will commit the current offset?

By default, as the consumer reads messages from Kafka, it will periodically commit its current offset (defined as the offset of the next message to be read) for the partitions it is reading from back to Kafka.


2 Answers

Your consumer will use your auto.offset.reset setting to reset its offset to a valid position. If no reset option has been specified, then the Broker will throw an InvalidOffsetException.

like image 126
Simon Clark Avatar answered Oct 16 '22 05:10

Simon Clark


It depends on the auto.offset.reset's mode that you have configured. Please find below about what will happen with each mode when you seek to an offset that doesn't exist in the given topic's partition.

auto.offset.reset=earliest

  • Partition's offset will be reset to 0 and all messages will be consumed enter image description here

auto.offset.reset=latest

  • Partition's offset will be reset to the last known offset and will be consuming only the new messages enter image description here

auto.offset.reset=none

  • Consumer application will fail with OffsetOutOfRangeException as shown below, enter image description here
like image 4
suresiva Avatar answered Oct 16 '22 05:10

suresiva