目录
分布式的WebSocket方案
分布式的WebSocket布置了多态socket服务端,并且所有服务端都订阅了消息队列。假如A想把消息发送给B,A的SessionID在第一个socket服务器中,B的sessionIP在第二个服务器中。正确的通信流程是:socket客户端中A把消息发送到Session为A的socket服务端,socket服务端再把消息发送给消息系统,因为我们的三个socket服务端都订阅了消息系统,所以3个服务端都能收到A->B的这条消息,每个socket服务端都去找自己有没有存B的sessionID,由存有B的sessionID的那台服务器做处理。
实现分布式消息发送
导入RocketMQ相关依赖
下面我们就开始整合分布式websocket项目,先添加依赖,starter2.0.0添加不了的可以参考下面的博客
https://blog.csdn.net/Delicious_Life/article/details/105300816
<!--RocketMQ相关依赖-->
<dependency>
<groupId>org.apache.rocketmq</groupId>
<artifactId>rocketmq-spring-boot-starter</artifactId>
<version>2.0.0</version>
</dependency>
<dependency>
<groupId>org.apache.rocketmq</groupId>
<artifactId>rocketmq-client</artifactId>
<version>4.3.2</version>
</dependency>
添加RocketMQ配置
我们需要手动指定nameserver和分组