zoukankan      html  css  js  c++  java
  • eureka之服务发现 DiscoveryClient

    1:注入 DiscoveryClient

    // import org.springframework.cloud.client.discovery.DiscoveryClient;    
    @Autowired
        private DiscoveryClient discoveryClient;

    2:对外提供方法

        @RequestMapping("/eureka/discovery")
        public BaseResult discovery() {
            String description = discoveryClient.description();
            List<String> services = discoveryClient.getServices();
            for (String service : services) {
                List<ServiceInstance> instances = discoveryClient.getInstances(service);
                String instancesStr = JSONUtil.toJsonPrettyStr(instances);
                System.out.println("instancesStr== " + instancesStr);
            }
            String servicesStr = JSONUtil.toJsonPrettyStr(services);
            return sendSuccess("description:" + description + "    servicesStr:" + servicesStr + " :: serverPort=" + serverPort);
        }

    调用该方法,会得到eureka里面的一些信息

  • 相关阅读:
    单片机4*4按键数码管显示0-9
    netbeans设置语言
    单片机中断的应用
    Linux 命令总结
    vc6.0快捷键大全
    怎么使PUTTY一直连接
    mysql alter 效率
    treeview
    Gitbook
    linux 进程监控软件 supervisor
  • 原文地址:https://www.cnblogs.com/draymond/p/12713809.html
Copyright © 2011-2022 走看看