1:进入到kafka目录下cmd指令,先运行zookeeper,:
运行:.\bin\windows\zookeeper-server-start.bat .\config\zookeeper.properties
zookeeper默认端口2181,如上执行成功;
2:重新打开dos窗口,执行kafak:.\bin\windows\kafka-server-start.bat .\config\server.properties
默认端口kafak9092;
3:新建一个topic,指令.\bin\windows\kafka-topics.bat --create --zookeeper localhost:2181 --replication-factor 1 --partitions 1 --topic test
4:验证主题:.\bin\windows\kafka-topics.bat --zookeeper localhost:2181 --describe --topic test
5:如果我们运行list topic命令,我们现在可以看到该主题:
.\bin\windows\kafka-topics.bat --list --zookeeper localhost:2181
返回topic(本人建立3个topic):
test
6:Kafka附带一个命令行客户端,它将从文件或标准输入中获取输入,并将其作为消息发送到Kafka集群。
默认情况下,每行将作为单独的消息发送。
重新打开一个dos窗口,运行生产者,然后在控制台中键入一些消息以发送到服务器。
.\bin\windows\kafka-console-producer.bat --broker-list localhost:9092 --topic test
输入:massage ..haha
7:启动消费者,Kafka还有一个命令行使用者,它会将消息转储到标准输出。
.\bin\windows\kafka-console-consumer.bat --bootstrap-server localhost:9092 --topic test --from-beginning
备注:看到消息内容也可以下载kafka可视化工具