Max
Max

Reputation: 1903

How to get last offset for all topic partition?

I need to get last offset for all topic partitions each N seconds (for cache purpose). What API should I use for that? I think, I need the most reliable and fast way.

I know two approaches:

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) Second one:

consumer.endOffsets()

Upvotes: 0

Views: 975

Answers (1)

Malt
Malt

Reputation: 30335

A call to consumer.endOffsets() is the better approach.

The first approach requires actually assigning the topic, which sounds like you don't need.

Upvotes: 1

Related Questions