RabbitMQ implements distributed WebSocket communication

Basic operation of RabbitMQ: https://blog.csdn.net/Michael_lcf/article/details/124677268
5 core concepts of RabbitMQ: https://blog.csdn.net/Michael_lcf/article/details/126435452
RabbitMQ implements distributed WebSocket Communication: https://blog.csdn.net/Michael_lcf/article/details/126403772

1. Implementation idea

1. When WebSocket receives the data from the user or the interface, it will be sent to RabbitMQ uniformly.

2. Each server listens to the RabbitMQ data and obtains the data. By judging whether the persons in the data are empty, it is judged whether it is a single send or a group send. If the persons are not empty and have a user id, each server compares whether it has the user id in its own session. If not, do not operate, if there is, push a message to the user.
Link:

3. Using the websocket online test ( websocket-test.com ) test tool, you can send JSON data to specify which user to send to. The data format is as follows:

{
    
    
	"persons":["101","201"],
	"msg":"你好啊 XXX 啊哈"
}

2. Effect screenshot

2.1 Single user push message

2.1 Multi-user push message

2.1 Sending messages between multiple users

3. Code implementation

gitee link: https://gitee.com/michael_linux/spring-security-study/tree/master/websocket

Guess you like

Origin blog.csdn.net/Michael_lcf/article/details/126403772