kafka操作命令

  • 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
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容