问题描述
我将 Kafka 0.9.0 与原生 Java 消费者客户端一起使用.如果我有 1 个主题和 1 个分区有人可以告诉我,如果我这样做:寻求结束(我的主题);民意调查(x);
I am using Kafka 0.9.0 with the native Java consumer client.If I have 1 Topic with 1 PartitionCan 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?
推荐答案
是的,你只会得到最后(最新)的记录,因为 seekToEnd()
方法延迟评估",因此直到 poll()
被调用时才会计算结束.当然,当 poll()
方法返回时,可以添加更多消息;所以不能保证你的偏移量是在最后一个位置",除非在方法执行的那一刻.
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.
这篇关于Kafka - 知道消费者是否是最新的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!