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