当前位置:网站首页>Construction scheme of distributed websocket

Construction scheme of distributed websocket

2022-06-25 04:42:00 Over the abyss

One 、 background

  • The company is websocket The architecture is a single application , It needs to be changed to cluster .
    Two 、 Retrofit scheme
    2.1 Scheme 1 :
    utilize mq The publish subscribe feature implements :
    advantage : Implement a simple
    shortcoming : need mq Support broadcast mode , The message should be de duplicated at the receiver , Every machine receives messages .
    This content cannot be displayed outside the document for the time being

2.2 Option two :
1. utilize redis Store the relationship between the user and the machine (userid,topic identification )
2.mq Used for message communication between services , Each service has its own queue
advantage : Unwanted mq Broadcast mode , Reduce repeated message sending
shortcoming :
1. One for each machine topic, Expansion needs to be applied in advance topic Or it can be created randomly by code
2. One topic Corresponding to one sender, You need to dynamically create a new machine on the old machine topic Of sender
3.k8s To start, you need to configure environment variables separately for each service to determine the corresponding environment variables for each machine topic
4. machine hostname It needs to be fixed , Used to correspond to and topic The relationship between
This content cannot be displayed outside the document for the time being

2.3 Option three :
Consistent hash ring
advantage : decoupling , The expansion is convenient , Dynamic capacity reduction and expansion only affect some users , Reduce component dependencies
shortcoming : The implementation is complex , Longer time consuming , Big changes

This content cannot be displayed outside the document for the time being

2.3.1 Implementation steps of scheme III :
step :

  1. Build the gateway module project :
    1.1 Integrate zk/nacos, Listen for machine node change information
    1.2 Integrate mq, Receive business system requests
    1.3 Integration consistency hash Algorithm , Real virtual node planning , Dynamic routing , Dynamic update ha
原网站

版权声明
本文为[Over the abyss]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/176/202206250318125327.html