kafka在window下的使用

基於上篇介紹各種中間件的優點與缺點,最後選擇kafka做爲開發消息中間件的系統。

以下介紹kafka在windows中的使用

  1. 下載與安裝
  1. 下載Kafka運行需求的環境zookeeper,http://mirror.bit.edu.cn/apache/zookeeper/zookeeper-3.5.7/apache-zookeeper-3.5.7-bin.tar.gz
  2. 安裝zookeeper,首先進入zookeeper下載文件目錄,使用 tar -xzf apache-zookeeper-3.5.7-bin.tar.gz解壓zookeeper文件,複製conf文件夾下的zoo_sample.cfg重命名成zoo.cfg, 配置文件可以使用默認的(爲什麼重命名配置文件,暫時不清楚)
  3. 安裝與配置Kafka,進入到Kafka文件目錄,解壓文件 tar -xzf kafka_2.13-2.4.0.tgz 配置文件,進入config到server.properties修改消息存儲地址
# 配置數據存儲位置
# A comma separated list of directories under which to store log files
log.dirs=D:\Software\kafka\log
修改zookeeper集羣配置地址:
# Zookeeper connection string (see zookeeper docs for details).
# This is a comma separated host:port pairs, each corresponding to a zk
# server. e.g. "127.0.0.1:3000,127.0.0.1:3001,127.0.0.1:3002".
# You can also append an optional chroot string to the urls to specify the
# root directory for all kafka znodes.
zookeeper.connect=localhost:2181
  1. 環境變量配置,Java環境變量配置必須的,zookeeper環境變量配置, 系統環境變量配置ZOOKEEPER_HOME D:\Software\zk\zookeeper-3.4.14 path添加%ZOOKEEPER_HOME%\bin
  2. 啓動zookeeper,打開命令行工具,執行zkServer.cmd,zookeeper啓動;啓動kafka,進入到Kafka安裝目錄的bin文件下,執行.\bin\windows\kafka-server-start.bat .\config\server.properties;
  3. 創建topic主題,進入bin\window文件夾下,執行>.\kafka-topics.bat --create --zookeeper localhost:2181 --replication-factor 1 --partitions 1 --topic test創建testtopic主題。使用.\kafka-topics.bat --zookeeper 127.0.0.1:2181 --list查看創建的主題
  4. 啓動生產者進入到bin\window下執行.\kafka-console-producer.bat --broker-list localhost:9092 --topic test
  5. 啓動消費者,bin\window下執行.\kafka-console-consumer.bat --bootstrap-server localhost:9092 --topic test
  6. 在生產者命令窗口輸入字符,消費者對應顯示,到此window下Kafka簡單使用完成
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章