kafka在windows环境下的搭建和使用
1. 首先下载kafka (这里是下载连接:https://www.apache.org/dyn/closer.cgi?path=/kafka/2.2.0/kafka_2.11-2.2.0.tgz) 注意到一点就是:kafaka下载时要下载二进制文件版本(binary)
2. 新版本kafka内置了 zookeeper ,所有下载后解压后,不用配置。
3. 进入目录下面直接启动就好
首先启动zookeeper : >>bin\windows\zookeeper-server-start.bat config\zookeeper.properties(注意cofing 和bin在同一目录下 )
然后启动kafka : bin\windows\kafka-server-start.bat config\server.properties
创建topic topic =test :
>bin\windows\kafka-topics.bat --create --zookeeper localhost:2181 --replication-factor 1 --partitions 1 --topic test
查看创建的topic :
>bin\windows\kafka-topics.bat --list --zookeeper localhost:2181
启动producer:
bin\windows\kafka-console-producer.bat --broker-list localhost:9092 --topic test 生产 hello kafka 消息
启动消费者:
注意:bin\windows\kafka-console-consumer.bat --bootstrap-server localhost:9092 --topic test --from-beginning 这是最新版本的启动方式,要是使用旧版本的启动方式会报错(zookeeper is not a recognized option)