|
|
|
@ -74,7 +74,6 @@ public abstract class BaseRouteManager<R extends BaseServiceRouteInfo<E>, E exte |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
public void refresh() { |
|
|
|
|
log.info("刷新本地接口信息"); |
|
|
|
|
try { |
|
|
|
|
String zookeeperServerAddr = environment.getProperty("spring.cloud.zookeeper.connect-string"); |
|
|
|
|
if (StringUtils.isEmpty(zookeeperServerAddr)) { |
|
|
|
@ -104,13 +103,13 @@ public abstract class BaseRouteManager<R extends BaseServiceRouteInfo<E>, E exte |
|
|
|
|
* 监听微服务更改 |
|
|
|
|
* |
|
|
|
|
* @param client |
|
|
|
|
* @param sopServiceApiPath |
|
|
|
|
* @param sopRouteRootPath |
|
|
|
|
* @throws Exception |
|
|
|
|
*/ |
|
|
|
|
protected void watchServiceChange(CuratorFramework client, String sopServiceApiPath) throws Exception { |
|
|
|
|
protected void watchServiceChange(CuratorFramework client, String sopRouteRootPath) throws Exception { |
|
|
|
|
// 为子节点添加watcher
|
|
|
|
|
// PathChildrenCache: 监听数据节点的增删改,可以设置触发的事件
|
|
|
|
|
PathChildrenCache childrenCache = new PathChildrenCache(client, sopServiceApiPath, true); |
|
|
|
|
PathChildrenCache childrenCache = new PathChildrenCache(client, sopRouteRootPath, true); |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* StartMode: 初始化方式 |
|
|
|
@ -123,7 +122,7 @@ public abstract class BaseRouteManager<R extends BaseServiceRouteInfo<E>, E exte |
|
|
|
|
// 列出子节点数据列表,需要使用BUILD_INITIAL_CACHE同步初始化模式才能获得,异步是获取不到的
|
|
|
|
|
List<ChildData> childDataList = childrenCache.getCurrentData(); |
|
|
|
|
log.info("========== 加载路由信息 =========="); |
|
|
|
|
log.info("{} # 根节点", sopRouteRootPath); |
|
|
|
|
log.info("{} # 根节点", this.sopRouteRootPath); |
|
|
|
|
for (ChildData childData : childDataList) { |
|
|
|
|
String serviceNodeData = new String(childData.getData()); |
|
|
|
|
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); |
|
|
|
|
this.loadServiceRouteItem(client, serviceRouteInfo, servicePath); |
|
|
|
|
} |
|
|
|
|
log.info("监听服务节点增删改,rootPath:{}", sopRouteRootPath); |
|
|
|
|
log.info("监听服务节点增删改,rootPath:{}", this.sopRouteRootPath); |
|
|
|
|
// 监听根节点下面的子节点
|
|
|
|
|
childrenCache.getListenable().addListener(new PathChildrenCacheListener() { |
|
|
|
|
@Override |
|
|
|
|