Don’t say much, get up and do

This article we from the source point of view to analyze the configuration of websocket communication protocol, soul gateway management background how to dynamically synchronize data to soul gateway.

The soul gateway management background page modifies the configuration data, synchronizes the data to the Soul Gateway core service, and updates the relevant configuration information stored in the local cache.

Soul gateway configuration data support dynamic modification, so it is very necessary to understand the configuration data synchronization of soul gateway.

Start with the sync data link chart on the official websiteAdmin: > event distributor -> Event distributor -> WebSocket -> WebSocket Cache handler -> Soul Gateway local cache

We will do source analysis from these points

The basic preparation

Start the soul – admin service, soul. The configuration file sync. Websocket. Enabled = true

Start the soul – the bootstrap service, soul. The configuration file sync. Websocket. Urls: ws: / / localhost: 9095 / websocket, the urls refers to the IP address of the soul – amdin

Example Modify admin management data

To modify any configuration data weight, click SureYou can see that it’s the selector/{id} interface of the request

Event publisher

Enter the soul-admin service code, Find the selector controller layer and methods of the related SelectorController. UpdateSelector (@ PathVariable (” id “) final String id, @RequestBody final SelectorDTO selectorDTO)Key code is selectorService createOrUpdate (selectorDTO), point in, found a way to releaseThe publish method calls soul’s own data change eventsDataChangedEvent There are two key parameters in the data-change event constructor:

EventType: eventType (such as adding, deleting, modifying, and viewing events)

GroupKey: event groupKey (soul custom module groups, including permissions, plug-ins, selectors, etc.)

Publish events are finally supported through Spring’s context

Data update event distributor

In the soul – admin, DataChangedEventDispatcher dispenser implements listener, listen for an eventSwitch to selector, and ultimately send data through webSocket’s send method

websoket

The SOUL data synchronization center listens to websockets for event data Then through websocketDataHandler. Executor (groupEnum, json, eventType) to perform synchronization

Websocket cache handler

In the doUpdate method of the selector data handler, the subscription method is calledFinally through subscription method CommonPluginDataSubscriber. SubscribeDataHandler () to update the local cache configuration data

Soul Gateway local cache

Call the Submit method to invoke the local cache

This source tracking soul here, many places are still relatively rough, need to further debug into the view, I hope readers can point out my mistakes or shortcomings, to self-examination