Soul Introduction chapter 11 Admin Synchronizing data to the gateway summary

Currently, the official data synchronization technologies include Websocket, HTTP long polling, ZooKeeper and NACOS. The following are the characteristics of the four ways.

  • 1, websocket

This mode is the default mode, does not rely on third-party components, is very lightweight, can achieve two-way real-time communication. Admin starts the Websocket service, waits for the gateway to connect (pushes all data to the gateway for the first connection), manages the connection, polls all connections and sends data to the gateway when the configuration data is changed. As a gateway, any configuration changes of the admin background must be truthfully transmitted to the gateway. How can this be guaranteed? Once the connection is disconnected, it’s a big problem. In order to solve the problem of websocket disconnection, a thread is set up on the gateway side to determine whether the connection is closed every three seconds. If the connection is closed, a reconnection will be initiated immediately. When the connection is reconnected, admin will also push the data in full. This approach is simple, reliable and high-performance. It is the default use mode.

  • 2. HTTP long polling

    This approach also does not depend on other components. The long polling mentioned here means that the gateway starts a thread and requests admin every five minutes to see if there is any change in data. If there is any change, the gateway will request data. So how do you know if there’s been a change, how do you know, a full data comparison? Soul takes the approach of calculating a digest for each record, which takes up less space and is more efficient to transfer or compare. When the gateway sends a request to Admin, Admin saves the connection as an asynchronous context. The next time there is a change, admin can use this context to send data to the gateway. This approach is also very lightweight, but the downside is that the implementation logic is slightly more complex.

  • 3, they are

    This method relies on third-party components and has not been carefully studied.

  • 4, nacos

    This method relies on third-party components and has not been carefully studied.