Java, How to get number of messages in a topic in apache kafka

后端 未结 17 1493
不思量自难忘°
不思量自难忘° 2020-11-30 19:11

I am using apache kafka for messaging. I have implemented the producer and consumer in Java. How can we get the number of messages in a topic?

17条回答
  •  盖世英雄少女心
    2020-11-30 19:34

    Run the following (assuming kafka-console-consumer.sh is on the path):

    kafka-console-consumer.sh  --from-beginning \
    --bootstrap-server yourbroker:9092 --property print.key=true  \
    --property print.value=false --property print.partition \
    --topic yourtopic --timeout-ms 5000 | tail -n 10|grep "Processed a total of"
    

提交回复
热议问题