gpt4 book ai didi

com.github.dapeng.registry.zookeeper.ZkServiceInfo.routes()方法的使用及代码示例

转载 作者:知者 更新时间:2024-03-18 15:17:31 27 4
gpt4 key购买 nike

本文整理了Java中com.github.dapeng.registry.zookeeper.ZkServiceInfo.routes()方法的一些代码示例,展示了ZkServiceInfo.routes()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。ZkServiceInfo.routes()方法的具体详情如下:
包路径:com.github.dapeng.registry.zookeeper.ZkServiceInfo
类名称:ZkServiceInfo
方法名:routes

ZkServiceInfo.routes介绍

[英]路由规则
[中]路由规则

代码示例

代码示例来源:origin: dapeng-soa/dapeng-soa

/**
 * process zk data 解析route 信息
 */
private void processRouteData(ZkServiceInfo serviceInfo, byte[] data) {
  try {
    String routeData = new String(data, StandardCharsets.UTF_8);
    List<Route> zkRoutes = RoutesExecutor.parseAll(routeData);
    serviceInfo.routes(zkRoutes);
  } catch (Exception e) {
    LOGGER.error(getClass() + "::processCookieRuleData, parser routes 信息 失败,请检查路由规则写法是否正确:" + e.getMessage());
  }
}

代码示例来源:origin: dapeng-soa/dapeng-soa

/**
 * 服务路由
 *
 * @param serviceInfo
 * @param compatibles
 * @return
 */
private List<RuntimeInstance> router(ZkServiceInfo serviceInfo, List<RuntimeInstance> compatibles) throws SoaException {
  List<Route> routes = serviceInfo.routes();
  if (routes == null || routes.size() == 0) {
    logger.debug("router 获取 路由信息为空或size为0,跳过router,服务实例数:{}", compatibles.size());
    return compatibles;
  } else {
    InvocationContextImpl context = (InvocationContextImpl) InvocationContextImpl.Factory.currentInstance();
    List<RuntimeInstance> runtimeInstances = RoutesExecutor.executeRoutes(context, routes, compatibles);
    if (runtimeInstances.size() == 0) {
      throw new SoaException(SoaCode.NoMatchedRouting);
    }
    return runtimeInstances;
  }
}

代码示例来源:origin: dapeng-soa/dapeng-soa

/**
 * route 根据给定路由规则对可运行实例进行过滤
 */
private void syncZkRouteInfo(ZkServiceInfo serviceInfo) {
  LOGGER.warn("ClientZKAgent::syncZkRouteInfo service:" + serviceInfo.serviceName());
  String servicePath = ROUTES_PATH + "/" + serviceInfo.serviceName();
  int retry = 5;
  do {
    if (zk == null || !zk.getState().isConnected()) {
      LOGGER.warn("ClientZKAgent::syncZkRouteInfo service:"
          + serviceInfo.serviceName() + ", zk status:"
          + (zk == null ? null : zk.getState()) + ", retry:"
          + retry + " times after 300ms");
      sleep(300);
    } else {
      try {
        byte[] data = zk.getData(servicePath, this, null);
        processRouteData(serviceInfo, data);
        LOGGER.warn("ClientZk::getRoutes routes changes:" + serviceInfo.routes());
        return;
      } catch (KeeperException.NoNodeException e) {
        ZkUtils.createPersistNodeOnly(servicePath, zk);
      } catch (KeeperException | InterruptedException e) {
        LOGGER.error(getClass() + "::syncZkRouteInfo serviceName: " + serviceInfo.serviceName() + " 出现异常, zkStatus:" + zk.getState(), e);
        sleep(300);
      }
    }
  } while (--retry > 0);
}

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com