soul网关源码解析-数据同步-http同步

http同步

配置

更新soul-admin和soul-bootstrap的yml文件配置如下

soul :
  sync:
        http:
             url : http://localhost:9095
soul :
    sync:
      http:
        enabled: true

pom文件依赖(加入依赖后网关需要重启)

        <dependency>
            <groupId>org.dromara</groupId>
            <artifactId>soul-spring-boot-starter-sync-data-http</artifactId>
            <version>${project.version}</version>
        </dependency>

启动相关的服务

源码

我们都是soul在第一次启动的时候会进行一次全量的数据加载.
HttpSyncDataService 在方中都使用构造器注入的时候调用的
start()方法.

    private void start() {
        // It could be initialized multiple times, so you need to control that.
        if (RUNNING.compareAndSet(false, true)) {
            // fetch all group configs.
            this.fetchGroupConfig(ConfigGroupEnum.values());
            int threadSize = serverList.size();
            this.executor = new ThreadPoolExecutor(threadSize, threadSize, 60L, TimeUnit.SECONDS,
                    new LinkedBlockingQueue<>(),
                    SoulThreadFactory.create("http-long-polling", true));
            // start long polling, each server creates a thread to listen for changes.
            this.serverList.forEach(server -> this.executor.execute(new HttpLongPollingTask(server)));
        } else {
            log.info("soul http long polling was started, executor=[{}]", executor);
        }
    }

注意这里的构造器注入的方式也是官方推荐的方式.

保证依赖不可变(final关键字)
保证依赖不为空(省去了我们对其检查)
保证返回客户端(调用)的代码的时候是完全初始化的状态

我们在看下 soul-sync-data-http 项目中的类和方法.

public interface DataRefresh {

    /**
     * Refresh boolean.
     *
     * @param data the data
     * @return the boolean
     */
    Boolean refresh(JsonObject data);

    /**
     * Cache config data config data.
     *
     * @return the config data
     */
    ConfigData<?> cacheConfigData();
}

然后我们在看下类DataRefreshFactory
这个类的主要作用就是保存

下面就是就是实现这个接口的抽奖类AbstractDataRefresh
然后就是同步不同类型数据的类
MetaDataRefresh 元数据操作
PluginDataRefresh 插件数据操作
SelectorDataRefresh 选择器数据操作
RuleDataRefresh 规则数据操作
AppAuthDataRefresh
然后数据在进行对应的操作

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值