一个例子,使用 spring boot
构建一个应用,从 kafka
队列中获取要推送的内容,通过`websocket`将内容推送到`web`端。
-
解压, 进入
conf
-
将
zoo_sample.cfg
重命名为zoo.cfg
-
编辑
zoo.cfg
, 指定dataDir
-
运行
cmd
, 进入bin`目录,输入`zkServer.cmd
,启动zookeeper
.
-
解压
-
运行
cmd
, 输入输入bin\windows\kafka-server-start.bat config\server.properties
,启动kafka
-
测试:
-
运行以下命令
-
kafka-topics.bat --create --zookeeper localhost:2181 --replication-factor 1 --partitions 1 --topic test1 kafka-console-producer.bat --broker-list localhost:9092 --topic test1 kafka-console-consumer.bat --zookeeper localhost:2181 --topic test1
-
启动项目
-
使用浏览器访问
http://localhost:8080/ws
,点击连接
-
通过运行单元测试
KafkaProducerTest
或者发送post
请求到/message/send
-
在浏览器会看到发送的内容