mirror of
https://gitee.com/durcframework/SOP.git
synced 2025-08-11 21:57:56 +08:00
路由管理优化
This commit is contained in:
@@ -74,7 +74,6 @@ public abstract class BaseRouteManager<R extends BaseServiceRouteInfo<E>, E exte
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void refresh() {
|
public void refresh() {
|
||||||
log.info("刷新本地接口信息");
|
|
||||||
try {
|
try {
|
||||||
String zookeeperServerAddr = environment.getProperty("spring.cloud.zookeeper.connect-string");
|
String zookeeperServerAddr = environment.getProperty("spring.cloud.zookeeper.connect-string");
|
||||||
if (StringUtils.isEmpty(zookeeperServerAddr)) {
|
if (StringUtils.isEmpty(zookeeperServerAddr)) {
|
||||||
@@ -104,13 +103,13 @@ public abstract class BaseRouteManager<R extends BaseServiceRouteInfo<E>, E exte
|
|||||||
* 监听微服务更改
|
* 监听微服务更改
|
||||||
*
|
*
|
||||||
* @param client
|
* @param client
|
||||||
* @param sopServiceApiPath
|
* @param sopRouteRootPath
|
||||||
* @throws Exception
|
* @throws Exception
|
||||||
*/
|
*/
|
||||||
protected void watchServiceChange(CuratorFramework client, String sopServiceApiPath) throws Exception {
|
protected void watchServiceChange(CuratorFramework client, String sopRouteRootPath) throws Exception {
|
||||||
// 为子节点添加watcher
|
// 为子节点添加watcher
|
||||||
// PathChildrenCache: 监听数据节点的增删改,可以设置触发的事件
|
// PathChildrenCache: 监听数据节点的增删改,可以设置触发的事件
|
||||||
PathChildrenCache childrenCache = new PathChildrenCache(client, sopServiceApiPath, true);
|
PathChildrenCache childrenCache = new PathChildrenCache(client, sopRouteRootPath, true);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* StartMode: 初始化方式
|
* StartMode: 初始化方式
|
||||||
@@ -123,7 +122,7 @@ public abstract class BaseRouteManager<R extends BaseServiceRouteInfo<E>, E exte
|
|||||||
// 列出子节点数据列表,需要使用BUILD_INITIAL_CACHE同步初始化模式才能获得,异步是获取不到的
|
// 列出子节点数据列表,需要使用BUILD_INITIAL_CACHE同步初始化模式才能获得,异步是获取不到的
|
||||||
List<ChildData> childDataList = childrenCache.getCurrentData();
|
List<ChildData> childDataList = childrenCache.getCurrentData();
|
||||||
log.info("========== 加载路由信息 ==========");
|
log.info("========== 加载路由信息 ==========");
|
||||||
log.info("{} # 根节点", sopRouteRootPath);
|
log.info("{} # 根节点", this.sopRouteRootPath);
|
||||||
for (ChildData childData : childDataList) {
|
for (ChildData childData : childDataList) {
|
||||||
String serviceNodeData = new String(childData.getData());
|
String serviceNodeData = new String(childData.getData());
|
||||||
R serviceRouteInfo = JSON.parseObject(serviceNodeData, getServiceRouteInfoClass());
|
R serviceRouteInfo = JSON.parseObject(serviceNodeData, getServiceRouteInfoClass());
|
||||||
@@ -131,7 +130,7 @@ public abstract class BaseRouteManager<R extends BaseServiceRouteInfo<E>, E exte
|
|||||||
log.info("\t{} # service节点,节点数据:{}", servicePath, serviceNodeData);
|
log.info("\t{} # service节点,节点数据:{}", servicePath, serviceNodeData);
|
||||||
this.loadServiceRouteItem(client, serviceRouteInfo, servicePath);
|
this.loadServiceRouteItem(client, serviceRouteInfo, servicePath);
|
||||||
}
|
}
|
||||||
log.info("监听服务节点增删改,rootPath:{}", sopRouteRootPath);
|
log.info("监听服务节点增删改,rootPath:{}", this.sopRouteRootPath);
|
||||||
// 监听根节点下面的子节点
|
// 监听根节点下面的子节点
|
||||||
childrenCache.getListenable().addListener(new PathChildrenCacheListener() {
|
childrenCache.getListenable().addListener(new PathChildrenCacheListener() {
|
||||||
@Override
|
@Override
|
||||||
|
Reference in New Issue
Block a user