kafka啓動
- 啓動zookeeper
使用./zkServer.sh status
查看zookeeper啓動狀態Node: standalone
爲啓動狀態 否則執行./zkServer.sh start
- 配置kafka運行配置
vi server.properties
修改listeners和advertised.listeners地址 - 啓動kafka
使用守護進程模式運行nohup bin/kafka-server-start.sh config/server.properties
使用jps檢查kafka進程 - 測試kafka
創建一個topic 基於topic可發送消息
bin/kafka-topics.sh --create --zookeeper localhost:2181 --replication-factor 1 --partitions 1 --topic test
打開一個消息發送者的窗口發送一條消息 輸入如下命令會出現輸入框 輸入信息回車後發送信息
bin/kafka-console-producer.sh --broker-list localhost:9092 --topic test
接收消息
bin/kafka-console-consumer.sh --zookeeper localhost:2181 --topic test --from-beginning
kafka 0.9版本後寫法
bin/kafka-console-consumer.sh --bootstrap-server localhost:9092 --topic test --from-beginning
other
- 關閉kafka
bin/kafka-server-stop.sh
- 查看kafka topic
bin/kafka-topics.sh --list --zookeeper localhost:2181