Before we analyze four data synchronization methods, this paper mainly summarizes the data synchronization methods, and how we use Websocket, HTTP long polling, nacos, ZooKeeper.

Summary of Synchronous mode

We have analyzed the four synchronization methods before, and here we summarize from two aspects: whether third-party plug-ins are required and synchronization methods (incremental/full) :

HTTP long polling:

    1. No third party is required and as the name implies is Http based long polling.
    1. Synchronization mode: Full synchronization at startup and incremental synchronization at each update.

websocket:

    1. No third party required, full duplex communication protocol
    1. Full synchronization at startup and incremental synchronization at each update

Zookeeper:

    1. Depends on the third-party service Zookeeper.
    1. Full synchronization is performed during startup, and the updated data needs to be obtained from the node every time there is an update. So it’s full at startup, incremental at update

Nacos:

    1. Rely on third-party services, NACOS services.
    1. When data is updated, the subscription will be cancelled first and new data will be subscribed again, which is equivalent to full synchronization.

In the case of a small cluster, Websocket is fully competent for work. In the case of a large number of connections, third-party services such as Zookeeper are required.

Soul code base

The core modules involved are:

  • Soul-admin: indicates the background management module
  • Soul-bootstrap: indicates the gateway startup module
  • Soul-spring-boot-starter: automatic configuration class encapsulated by the soul custom
  • Soul-sync-data-center: indicates the soul data synchronization module

How to implement a custom synchronization mode

The admin side

    1. In the application.yml filesoul.syncEnter the required configuration
    1. Add the corresponding XXXProperties, XXXConfiguration to the admin > config folder.XXXConfigurationTo register ConfigService.
    1. Create a corresponding mode folder in the adimin > Listener folder and implement itDataChangedListenerAnd implement the corresponding logic in XXXDataChangedListener
    1. Register the corresponding Bean in the DataSyncConfiguration file in admin > config

The directory structure is as follows:

The bootstrap port

    1. The required configuration is configured in the application-dev.yml file of soul-bootstrap, corresponding to that of soul-admin
    1. Generate a customized bootstarter in the soul-spring-boot-starter-sync-data-center submodule of soul-spring-boot-starter. The Bean of the corresponding Service needs to be registered in the starter
    1. In the soul-sync-data-center module soul-sync-data-xxx, create XXXService to implement the corresponding logic.

conclusion

  1. The Admin side uses the ApplcationEvent mechanism to decouple the data synchronization mode, making this configuration convenient.
  2. Bootstrap uses the registration module to achieve decoupling, which is worth learning.
  3. Soul there is more to learn from this.

The resources

WebSocket for full-duplex communication