我的kafka是在/Applications/kafka_2.11-0.10.2.1目錄下,下面都在kafka_2.11-0.10.2.1/bin路徑下操作的,mac跟linux指令差不多,Mac是通過(guò)sh腳本傳參執(zhí)行命令的
啟動(dòng)
1.先啟動(dòng)zookeeper(kafka自帶的)
sh zookeeper-server-start.sh ../config/zookeeper.properties
2.啟動(dòng)kafka
sh kafka-server-start.sh ../config/server.properties
kafka基本指令
創(chuàng)建一個(gè)topic
sh kafka-topics.sh --create --zookeeper localhost:2181 --partitions 2 --replication-factor 1 --topic test1
#輸出:Created topic "test1".
--partitions:分區(qū)數(shù)量
--replication-factor:副本數(shù)量(要<=broker數(shù)量)
查看topic列表
sh kafka-topics.sh --list --zookeeper localhost:2181
# 輸入:test1
創(chuàng)建生產(chǎn)者
sh kafka-console-producer.sh --broker-list localhost:9092 --topic test1
創(chuàng)建消費(fèi)者
sh kafka-console-consumer.sh --bootstrap-server localhost:9092 --topic test1 --from-beginning
--from-beginning:從頭開(kāi)始消費(fèi)
在生產(chǎn)端輸入信息后回車,到消費(fèi)者端可以看到生產(chǎn)端發(fā)送的信息