1.首先启动kafka服务器:
window环境需要执行如下命令:
windows\kafka-server-start.bat ..\config\server.properties
2.创建主题: 我们创建一个名为“test”的主题,它只包含一个分区,只有一个副本:
bin/windows/kafka-topics.bat --create --zookeeper localhost:2181 --replication-factor 1 --partitions 1 --topic helloword
创建完之后查看一下:
如果我们运行list topic命令,我们现在可以看到该主题:
12 > bin/windows/kafka-topics.bat --list --zookeeper localhost:2181 helloword
3.启动生产者发送一些消息:
bin/windows/kafka-console-producer.bat --broker-list localhost:9092 --topic helloword
此处需要将配置文件中的C:\ProgramFiles\kafka_2.12-1.1.0\config\server.properties下圈起来的listeners放开,因为默认情况下是注释掉的。
4.启动消费者监听生产者发送的消息:
windows>kafka-console-consumer.bat --bootstrap-server localhost:9092 --topic helloword --from-beginning