Kafka - Know if Consumer is up to date

2019-08-12 08:21发布

问题:

I am using Kafka 0.9.0 with the native Java consumer client. If I have 1 Topic with 1 Partition Can someone tell me if I do: seekToEnd(MyTopic); poll(x);

I will only get the last record, hence I will know that I am in the last position?

回答1:

Yes, you will only get the last (newest) record, because the seekToEnd() method "evaluates lazily" so the end is not calculated until poll() is called. Of course, by the time the poll() method returns, more messages could have been added; so there is no guarantee your offset is "in the last position" except at the instant that the method executes.