如何获得所有主题分区的最后偏移量?

时间:2019-03-17 10:13:50

标签: java apache-kafka kafka-consumer-api

我需要每N秒获取所有主题分区的最后偏移量(出于缓存目的)。我应该为此使用什么API?我认为,我需要最可靠,最快捷的方法。

我知道两种方法:

1)First one

//assign the topic
consumer.assign();

//seek to end of the topic
consumer.seekToEnd();

//the position is the latest offset
consumer.position();

2)第二个:

consumer.endOffsets()

1 个答案:

答案 0 :(得分:1)

调用consumer.endOffsets()是更好的方法。

第一种方法需要实际分配主题,听起来好像不需要。

相关问题