【问题标题】:How to get last offset for all topic partition?如何获取所有主题分区的最后一个偏移量?
【发布时间】:2019-08-07 21:53:09
【问题描述】:

我需要每 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()

【问题讨论】:

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


    【解决方案1】:

    致电consumer.endOffsets() 是更好的方法。

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-11-20
      • 2016-05-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-12-30
      相关资源
      最近更新 更多