[BUG] KafkaConsumer.position() Method should give the offset one larger than the last record
See original GitHub issueDescribe the bug According to Kafka Conusmer API Doc: https://kafka.apache.org/22/javadoc/index.html?org/apache/kafka/clients/consumer/KafkaConsumer.html
The position of the consumer gives the offset of the next record that will be given out. It will be one larger than the highest offset the consumer has seen in that partition. It automatically advances every time the consumer receives messages in a call to poll(Duration).
While currently, KoP will return the offset of the last record, without adding one to it
To Reproduce Steps to reproduce the behavior:
- Suscribe to a Kafka topic or a KoP topic
- Call
conusmer.seekToEnd()
and then printconusmer.position()
result - Kafka will return the offset one larger than last record, while KoP not.
Expected behavior KafkaConsumer.position() Method should give the offset one larger than the last record
Issue Analytics
- State:
- Created 3 years ago
- Comments:8
Top Results From Across the Web
KafkaConsumer Position() vs Committed() - Stack Overflow
It will be one larger than the highest offset the consumer has seen in that partition. It automatically advances every time the consumer ......
Read more >KafkaConsumer (kafka 2.4.0 API)
The position of the consumer gives the offset of the next record that will be given out. It will be one larger than...
Read more >Apache Kafka Offset Management - Learning Journal
The offset is a simple integer number that is used by Kafka to maintain the current position of a consumer. That's it. The...
Read more >Chapter 4. Kafka Consumers: Reading Data from Kafka
Applications that need to read data from Kafka use a KafkaConsumer to ... If the committed offset is larger than the offset of...
Read more >KafkaConsumer (clients 5.3.0-ccs API)
The position of the consumer gives the offset of the next record that will be given out. It will be one larger than...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Got it. I’ll try to fix this issue after KoP 2.7.0 is released.
When Kafka handles fetch requests, it reads data from
request.offset
.However when KoP handles fetch requests, the workflow is:
request.offset
to a message id;Kafka consumer maintains an internal offset to construct FETCH request. The offset will be updated after
resetOffsetsAsync
. Currently KoP returns alatestOffset
notlatestOffset + 1
if consumer resets offset to latest. If we change it tolatestOffset + 1
, the consumer may fetch afterlatestOffset + 1
.As for how to fix this issure, please allow me to make a few comments. I’am not familiar with this project, so if any wrong, please correct me.
Can we add one to lastOffset only for the postsion() request ?
, and I’am a little comfused why we need to
request.offset - 1
when fetch.