# spring-cloud-stomp **Repository Path**: yangbinclass/spring-cloud-stomp ## Basic Information - **Project Name**: spring-cloud-stomp - **Description**: 基于 Spring Cloud + RabbitMQ 的 STOMP 协议消息推送 - **Primary Language**: Java - **License**: Not specified - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 4 - **Created**: 2022-01-04 - **Last Updated**: 2024-11-20 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README ## 技术栈 #### 前端 - sockjs - stomp - jquery - websocket #### 后端 - spring cloud eureka - spring cloud gateway - rabbitmq - kafka - thymeleaf ## 项目介绍 基于 maven 父子层级结构 ![](img/项目层级结构.png) - frontend 基于 spring boot + thymeleaf,用于模拟前端展示 websocket 推送消息的页面,也模拟了前后端分离的场景。sockjs 自带 ping pong 机制,用于防止长连接因无消息推送的时间太长而断开。 - eureka 服务注册中心 - gateway 网关,实现 stomp 集群的负载均衡和反向代理。 - rabbitmq-stomp 基于 rabbitmq+ stomp 的 websocket实现,为了模拟集群多实例,此项目下有两个提供一致服务的实例。 - kafka-stomp 基于 kafka + stomp 的 websocket实现,为了模拟多实例,此项目下有两个提供一致服务的实例。 ## 使用教程 #### rabbitmq 安装 请戳[链接](https://blog.csdn.net/qq_15329947/article/details/84101852) #### 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` #### 项目运行 - 在本地 Intellij IDEA 中启动所有项目 ![](img/IDEA启动SpringBoot项目.png) - 浏览器打开地址:http://localhost:8070/ - Postman 依次调用以下接口,其中访问带有 9000 端口网关的接口时分别调用两次(测试是否能做到轮询): | 接口 | 实例 | 集群 | | :-----------------------------------------------: | :---------------: | :------: | | localhost:8061/screen/message | kafka - stomp1 | | | localhost:8062/screen/message | kafka - stomp2 | | | localhost:8071/screen/message | rabbitmq - stomp1 | | | localhost:8072/screen/message | rabbitmq - stomp2 | | | localhost:9000/JAKE-KAFKA-STOMP/screen/message | | kafka | | localhost:9000/JAKE-RABBITMQ-STOMP/screen/message | | rabbitmq | - 在打开的页面上会观察到以下文本输出: ![](img/websocket页面.png) 这说明页面能接收到 kafka / rabbitmq 集群中的不同实例推送的信息。