- kafka啟動(dòng)
bin/kafka-server-start.sh -daemon config/server.properties
- 創(chuàng)建topic
bin/kafka-topics.sh -zookeeper localhost:2181 --create --partitions 1 --replication-factor 1 --topic test
--partitions指定分區(qū)數(shù),--replication-factor表示副本數(shù)
- 查看topic列表
bin/kafka-topics.sh --list --zookeeper localhost:2181
bin/kafka-topics.sh --list --bootstrap-server localhost:9092
-- 查看集群描述
bin/kafka-topics.sh --describe --zookeeper localhost:2181
- 刪除topic
./bin/kafka-topics --delete --zookeeper localhost:2181 --topic test
- 生產(chǎn)消息
bin/kafka-producer-perf-test.sh --topic test --throughput -1 --record-size 10 --num-records 500000 --producer-props bootstrap.servers=localhost:9092
- 消費(fèi)消息
./bin/kafka-console-consumer.sh --bootstrap-server localhost:9092 --topic test --from-beginning
- 獲取topic消息數(shù)
bin/kafka-run-class.sh kafka.tools.GetOffsetShell --broker-list localhost:9092 --topic test --time -1
bin/kafka-run-class.sh kafka.tools.GetOffsetShell --broker-list localhost:9092 --topic test --time -2
--time -1表示要獲取topic所有分區(qū)當(dāng)前的最大位移, --time -2表示獲取當(dāng)前最早位移。兩個(gè)命令輸出相減便可得到所有分區(qū)當(dāng)前的消息總數(shù)。在沒(méi)有刪除過(guò)消息的情況下,第二個(gè)命令的結(jié)果是0。
- 查詢消費(fèi)組列表
bin/kafka-consumer-groups.sh --bootstrap-server localhost:9092 --list
- 查詢某個(gè)消費(fèi)組的消費(fèi)詳情
bin/kafka-consumer-groups.sh --bootstrap-server localhost:9092 --describe --group my-group
- 壓力測(cè)試
bin/kafka-producer-perf-test.sh --topic test --num-records 100 --record-size 1 --throughput 100 --producer-props bootstrap.servers=localhost:9092