目标
获取某 topic 共生产多少条消息。
创建测试 topic
bin/kafka-topics.sh -zookeeper localhost:2181 --create --partitions 5 --replication-factor 1 --topic test765
生产测试消息
为 topic test765 生产 500000 条消息:
bin/kafka-producer-perf-test.sh --topic test765 --throughput -1 --record-size 10 --num-records 500000 --producer-props bootstrap.servers=localhost:9092
获取 topic 消息数
bin/kafka-run-class.sh kafka.tools.GetOffsetShell --broker-list localhost:9092 --topic test765 --time -1
# 输出信息
test765:0:100000
test765:1:100000
test765:2:100000
test765:3:100000
test765:4:100000
bin/kafka-run-class.sh kafka.tools.GetOffsetShell --broker-list localhost:9092 --topic test765 --time -2
# 输出信息
test765:0:0
test765:1:0
test765:2:0
test765:3:0
test765:4:0
--time-1 表示要获取指定topic所有分区当前的最大位移,-