Kafka使用記錄

kafka啓動

  1. 啓動zookeeper
    使用./zkServer.sh status查看zookeeper啓動狀態 Node: standalone爲啓動狀態 否則執行./zkServer.sh start
  2. 配置kafka運行配置
    vi server.properties 修改listeners和advertised.listeners地址
  3. 啓動kafka
    使用守護進程模式運行nohup bin/kafka-server-start.sh config/server.properties
    使用jps檢查kafka進程
  4. 測試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
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章