wxmimperio
wxmimperio

Reputation: 115

How to get current offset in Kafka 0.10.x without shell?

Is there any way to get the current offset in Kafka 0.10.x? I do not want to use shell commands.

When I use the API's consumer.endOffsets(...), I can get the last offsets (logSize). However consumer.position(...) does not get me the current offset!

All in all, I want to get the current offset, log size and lag in one partition.

Upvotes: 0

Views: 1870

Answers (1)

Matthias J. Sax
Matthias J. Sax

Reputation: 62310

You can use KafkaConsumer#committed() to get the latest committed position. Thus, I you disable auto-commit and do manual commits, you can compute the exact lag each time you do a commit.

On the other hand, each record you do process, provide its offset via ConsumerRecord#offset(), thus, you can also compute the lag after reading a single record (for the record's partition).

Upvotes: 1

Related Questions