前置条件:进入Kafka所在目录,按下shift+鼠标右键,选择"在此处打开命令窗口",打开命令行,在命令行中输入:.\bin\windows\kafka-server-start.bat .\config\server.properties 回车。
1、打开cmd输入zkserver(打开服务器)
2、打开另一个cmd,找到对应Kafka路径,如:D:\tool\kafka_2.12-2.1.0
1)输入.\bin\windows\zookeeper-server-start.bat .\config\zookeeper.properties,末尾无分号
此步骤为启动内置的zookeeper,出现binding to port...表示zookeeper启动成功
2)在此cmd下继续输入.\bin\windows\kafka-server-start.bat .\config\server.properties,末尾无分号,
此步骤为Kafka服务启动
3)继续输入.\bin\windows\kafka-topics.bat --create --zookeeper localhost:2181 --replication-factor 1 --partitions 1 --topic test
创建topic测试主题Kafka
4)继续输入.\bin\windows\kafka-console-producer.bat --broker-list localhost:9092 --topic test
创建生产者产生消息
5)打开另一个cmd,打开路径D:\tool\kafka_2.12-2.1.0,
输入.\bin\windows\kafka-console-consumer.bat --bootstrap-server localhost:9092 --topic test --from-beginning
创建消费者接收消息
注意点:
1:topic 后面的值都要相同才可接收数据
其他指令:
查看创建的topic:bin\windows\kafka-topics.bat --list --zookeeper localhost:2181