Skip to content

li7nux/spring-boot-kafka-websocket

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

项目介绍

一个例子,使用 spring boot 构建一个应用,从 kafka 队列中获取要推送的内容,通过`websocket`将内容推送到`web`端。

项目依赖安装

项目依赖

  • kafka

  • zookeeper

zookeeper 安装

  • 下载 zookeeper

  • 解压, 进入 conf

  • zoo_sample.cfg 重命名为 zoo.cfg

  • 编辑 zoo.cfg, 指定 dataDir

  • 运行 cmd, 进入 bin`目录,输入`zkServer.cmd,启动 zookeeper.

kafka 安装

  • 下载 kafka

  • 解压

  • 运行 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

  • 在浏览器会看到发送的内容

Releases

No releases published

Packages

No packages published