You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@kafka.apache.org by Hafiz Mujadid <ha...@gmail.com> on 2015/04/09 11:43:41 UTC

Number of messages in a kafka topic

Hi Kafka Users!

how to check number of messages in a kafka topic using java api?

Thanks

Re: Number of messages in a kafka topic

Posted by Hafiz Mujadid <ha...@gmail.com>.
thanks Jiangjie (Becket) Qin

On Fri, Apr 10, 2015 at 5:03 AM, Jiangjie Qin <jq...@linkedin.com.invalid>
wrote:

> This could be a little bit work... You can do the following,
> use simple consumer,
> 1. Get all the partition information of the topic by issuing a topic
> metadata request.
> 2. Send OffsetRequest to each of the partitions to get the earliest and
> latest offset of a partition so you get number of messages there.
> 3. Sum up the numbers you got in step 2 from each partition.
>
> You can also use KafkaConsumer,
> 1. Call seekToBeginning() and seeKToEnd() for each TopicPartition to get
> the message number in each partition.
> 2. Sum up the numbers in step 1.
>
> I¹m not sure if there is a better way to do this...
>
> Jiangjie (Becket) Qin
>
> On 4/9/15, 2:43 AM, "Hafiz Mujadid" <ha...@gmail.com> wrote:
>
> >Hi Kafka Users!
> >
> >how to check number of messages in a kafka topic using java api?
> >
> >Thanks
>
>


-- 
Regards: HAFIZ MUJADID

Re: Number of messages in a kafka topic

Posted by Jiangjie Qin <jq...@linkedin.com.INVALID>.
This could be a little bit work... You can do the following,
use simple consumer,
1. Get all the partition information of the topic by issuing a topic
metadata request.
2. Send OffsetRequest to each of the partitions to get the earliest and
latest offset of a partition so you get number of messages there.
3. Sum up the numbers you got in step 2 from each partition.

You can also use KafkaConsumer,
1. Call seekToBeginning() and seeKToEnd() for each TopicPartition to get
the message number in each partition.
2. Sum up the numbers in step 1.

I¹m not sure if there is a better way to do this...

Jiangjie (Becket) Qin

On 4/9/15, 2:43 AM, "Hafiz Mujadid" <ha...@gmail.com> wrote:

>Hi Kafka Users!
>
>how to check number of messages in a kafka topic using java api?
>
>Thanks