# websocket-services **Repository Path**: syk1234/websocket-services ## Basic Information - **Project Name**: websocket-services - **Description**: websocket连接推送服务包含两个服务,websocket-connector和websocket-gateway。 - **Primary Language**: Java - **License**: MulanPSL-2.0 - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 1 - **Forks**: 0 - **Created**: 2024-04-12 - **Last Updated**: 2024-06-18 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # websocket-services #### 介绍 websocket连接推送服务包含两个服务,websocket-connector和websocket-gateway。 websocket-connector - 作为和客户端建立websocket连接的服务,负责消息的接收和推送 websocket-gateway - 作为后台服务,提供http接口给其他微服务,其他微服务可以通过http接口发送消息给指定的用户 #### 软件架构 ![架构图](images/推送服务架构.png) #### 安装教程 本项目需要本地启动rabbitmq消息中间件的支持。在启动应用程序前,请提前配置好rabbitmq的连接信息。 #### 使用说明 通过下面的步骤来进行调试 1. 分别启动项目websocket-connector和websocket-gateway 2. 访问下面接口,获取某个用户的token 下面示例是获取用户1001的token ````bash curl -X POST -H "Accept:*/*" -H "Content-Type:application/json" -d "{\"userId\":\"1001\"}" "http://localhost:8081/api/ws/token/get" ```` 3. 打开websocket-connector调试页面http://localhost:8080/index.html 将上一个接口获取到的token作为参数,与服务器建立连接 ![获取token](images/001.png) 4. 通过页面的send按钮,发送一条消息给服务器,同时服务器会将此消息回复给前端页面。参考上图 5. 通过websocket-gateway的接口,发送用户单播消息 ````bash curl -X POST -H "Accept:*/*" -H "Content-Type:application/json" -d "{\"appCode\":\"test2\",\"messageData\":{\"body\":\"single message\",\"headers\":{}},\"topic\":\"/user/topic/single/hello\",\"userIds\":[1001]}" "http://localhost:8081/api/ws/message/single/send" ```` 前端页面可以收到该消息的推送 6.通过websocket-gateway的接口,发送广播消息 ````bash curl -X POST -H "Accept:*/*" -H "Content-Type:application/json" -d "{\"appCode\":\"test1\",\"messageData\":{\"body\":\"hello board message1\",\"headers\":{}},\"topic\":\"/topic/boardCast/hello\"}" "http://localhost:8081/api/ws/message/boardCast/send" ```` #### 参与贡献 1. Fork 本仓库 2. 新建 Feat_xxx 分支 3. 提交代码 4. 新建 Pull Request