zoukankan      html  css  js  c++  java
  • 微服务监控平台获取网关(zuul)配置列表

    步骤:

    (1)读取zuul的配置文件,获取路由配置项信息;

        private static Properties props;
    
        static {
            String fileName = "application.properties";
            props = new Properties();
            try {
                props.load(new InputStreamReader(PropertiesUtil.class.getClassLoader().getResourceAsStream(fileName), "UTF-8"));
            } catch (IOException e) {
                log.error("配置文件读取异常", e);
            }
        }

    (2)在获取到的配置项信息中截取出服务的路由配置信息;

        /**
         * 根据zuul.routes.KSKZT.serviceId
         * 获取KSKZT
         * @param key
         * @return
         */
        public static String getRoutesKey(String key){
            return key.replace("zuul.routes.", "").replace(".serviceId", "");
        }
        
        /**
         * 根据KSKZT
         * 获取zuul.routes.KSKZT.path
         * @param key
         * @return
         */
        public static String getRoutesPathKey(String key){
            return "zuul.routes."+key+".path";
        }
        
        /**
         * 根据zuul.routes.KSKZT.path
         * 获取/KSKZT/**
         * @param pathKay
         * @return
         */
        public static String getRoutesPathPalue(String pathKay){
            return props.getProperty(pathKay.trim());
        }
        
        /**
         * 获取系统配置的注册名称
         * @return
         */
        public static String getApplicationName(){
            return props.getProperty("spring.application.name");
        }
        
        /**
         * 获取路由表
         * @return
         */
        public static List<Map<String,String>> getRouteList(){
            List<Map<String,String>> routeList = new ArrayList<>();
            for(Object key : props.keySet()){
                if(key.toString().startsWith("zuul.routes") && key.toString().endsWith(".serviceId") ){
                    Map< String, String> route = new HashMap<String, String>();
                    route.put("serviceName",props.get(key)+"");
                    route.put("servicePath",getApplicationName()+getRoutesPathPalue(getRoutesPathKey(getRoutesKey(key.toString()))));
                    routeList.add(route);
                }
            }
            return routeList;
        }
        

    测试获取到的路由表

        public static void main(String[] args) {
            List<Map<String,String>> list = getRouteList();
            for (Map<String,String> object : list) {
                System.out.println("********************");
                System.out.println(object.get("serviceName"));
                System.out.println(object.get("servicePath"));
                
            }
        }

    (3)保证监控平台获取正确的路由表;

      1)在监控平台启动时:通过HttpClient请求zuul提供的接口,获取路由表信息

      2)在zuul启动时:通过的HttpClient请求监控平台的更新接口,将路由表作为参数传递给监控平台,监控平台接受并更新。

  • 相关阅读:
    hdu 4946 Area of Mushroom(凸包)
    uva 10065 (凸包+求面积)
    hdu 3934&&poj 2079 (凸包+旋转卡壳+求最大三角形面积)
    Codeforces Round #237 (Div. 2) B题模拟题
    Codeforces Round #237 (Div. 2) A
    zoj 1377 || poj 1228 Grandpa's Estate (看了题解,待解决)
    poj 1584 看懂题意----待解决
    Codeforces Round #249 (Div. 2) C题,模拟画图 ----未解决!
    Codeforces Round #249 (Div. 2)B(贪心法)
    MMORPG大型游戏设计与开发(客户端架构 part3 of vegine)
  • 原文地址:https://www.cnblogs.com/excellencesy/p/12373659.html
Copyright © 2011-2022 走看看