QnaList > Groups > Incubator-Kafka-Users > Apr 2015
faq

Number Of Messages In A Kafka Topic

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

asked Apr 9 2015 at 02:43

Hafiz Mujadid 's gravatar image



2 Replies for : Number Of Messages In A Kafka Topic
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

answered Apr 9 2015 at 17:03

Jiangjie Qin 's gravatar image


thanks Jiangjie (Becket) Qin
Regards: HAFIZ MUJADID

answered Apr 10 2015 at 00:41

Hafiz Mujadid 's gravatar image


Related discussions

Tagged

Group Incubator-kafka-users

asked Apr 9 2015 at 02:43

active Apr 10 2015 at 00:41

posts:3

users:2

©2013 QnaList.com