天天看點

kafka常用指令

1、啟動kafka服務

bin/kafka-server-start.sh config/server.properties &      

2、停止kafka服務

./kafka-server-stop.sh       

3、檢視所有的話題

./kafka-topics.sh --list --zookeeper localhost:9092
      

4、檢視所有話題的詳細資訊

./kafka-topics.sh --zookeeper localhost:2181 --describe      

5、列出指定話題的詳細資訊

./kafka-topics.sh --zookeeper localhost:2181 --describe  --topic demo      

6、删除一個話題

./kafka-topics.sh --zookeeper localhost:2181 --delete  --topic test      

7、建立一個叫test的話題,有兩個分區,每個分區3個副本

./kafka-topics.sh --zookeeper localhost:2181 --create --topic test --replication-factor 3 --partitions 2      

 8、測試kafka發送和接收消息(啟動兩個終端)

#發送消息(注意端口号為配置檔案裡面的端口号)
./kafka-console-producer.sh --broker-list localhost:9092 --topic test
#消費消息(可能端口号與配置檔案保持一緻,或與發送端口保持一緻)
./kafka-console-consumer.sh --bootstrap-server localhost:9092 --topic test --from-beginning   #加了--from-beginning 重頭消費所有的消息
./kafka-console-consumer.sh --bootstrap-server localhost:9092 --topic test         #不加--from-beginning 從最新的一條消息開始消費      

9、檢視某個topic對應的消息數量

./kafka-run-class.sh  kafka.tools.GetOffsetShell --broker-list localhost:9092 --topic test --time -1      

10、顯示所有消費者

./kafka-consumer-groups.sh --bootstrap-server localhost:9092 --list      

11、擷取正在消費的topic(console-consumer-63307)的group的offset

./kafka-consumer-groups.sh --describe --group console-consumer-63307 --bootstrap-server localhost:9092      

11、顯示消費者

./kafka-consumer-groups.sh --bootstrap-server localhost:9092 --list      

部落格裡大都是轉載的内容,其目的主要使用者知識的組織和管理。