You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@kafka.apache.org by ma...@kafkatool.com on 2016/04/18 02:16:08 UTC

Getting first/last offset of a partition using KafkaConsumer

How does one get the first/last offset for a given partition using the new
 KafkaConsumer/Producer? In the old SimpleConsumer you would just use the
getOffsetsBefore() method.

-- 
Best regards,
Marko
www.kafkatool.com


Re: Getting first/last offset of a partition using KafkaConsumer

Posted by ma...@kafkatool.com.
Thanks, this seems to do the trick.


Best regards,
Marko
www.kafkatool.com

> Hi
>
> For the Kafka Consumer, there are seekToBeginning and seekToEnd method
> that
> point your the beginning and end of the partition. You can use one of the
> methods to point the consumer to a certain position and use position(tp)
> method to get the corresponding position. There is also a seek(tp, offset)
> that you can use to point your consumer to the provided offset.
>
> Thanks,
> Liquan
>
> On Sun, Apr 17, 2016 at 5:16 PM, <ma...@kafkatool.com> wrote:
>
>> How does one get the first/last offset for a given partition using the
>> new
>>  KafkaConsumer/Producer? In the old SimpleConsumer you would just use
>> the
>> getOffsetsBefore() method.
>>
>> --
>> Best regards,
>> Marko
>> www.kafkatool.com
>>
>>
>
>
> --
> Liquan Pei
> Software Engineer, Confluent Inc
>



Re: Getting first/last offset of a partition using KafkaConsumer

Posted by Liquan Pei <li...@gmail.com>.
Hi

For the Kafka Consumer, there are seekToBeginning and seekToEnd method that
point your the beginning and end of the partition. You can use one of the
methods to point the consumer to a certain position and use position(tp)
method to get the corresponding position. There is also a seek(tp, offset)
that you can use to point your consumer to the provided offset.

Thanks,
Liquan

On Sun, Apr 17, 2016 at 5:16 PM, <ma...@kafkatool.com> wrote:

> How does one get the first/last offset for a given partition using the new
>  KafkaConsumer/Producer? In the old SimpleConsumer you would just use the
> getOffsetsBefore() method.
>
> --
> Best regards,
> Marko
> www.kafkatool.com
>
>


-- 
Liquan Pei
Software Engineer, Confluent Inc