配置
更新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
然后数据在进行对应的操作
本文详细介绍了如何配置Soul Admin和Soul Bootstrap的HTTP同步,包括POM文件的依赖添加、服务启动流程,以及DataRefresh接口的实现。重点讲解了HttpSyncDataService的启动过程和不同数据类型同步类的分工。
390

被折叠的 条评论
为什么被折叠?



