zoukankan      html  css  js  c++  java
  • springcloud-服务发现Discovery

      服务发现是指:服务或其他程序可以去获取注册中心上的注册信息

      eureka提供了实现服务发现的API,具体操作如下:

        @Autowired
        private DiscoveryClient discoveryClient;
    @GetMapping(
    "/payment/getServices") public void getServicesInfo(){ //获取多个服务名 List<String> services = discoveryClient.getServices(); for (String service: services) { log.info("服务名:"+service); } //指定一个服务,得到多个该服务的实例 List<ServiceInstance> instances = discoveryClient.getInstances("cloud-payment-service"); for (ServiceInstance instance: instances) { log.info("主机名:"+instance.getHost()+ " "+"实例ID"+instance.getInstanceId()+" "+"服务ID"+instance.getServiceId()+" "+ "实例端口:"+instance.getPort()+" "+"实例URI"+instance.getUri()); } }

      想要获取注册中心的注册信息,可以这个DidscoveryClient这个API去操作

      等下,还没完,这个API是需要加入到容器中的,所以我们得加一个注解,目的之一就是让他加入到IOC中

    @SpringBootApplication
    @EnableEurekaClient
    @EnableDiscoveryClient //启动发现客户端
    public class PaymentApplication {}
  • 相关阅读:
    The model backing the 'XXX' context has changed 错误
    MVC5+EF6 入门完整教程四
    MVC5 + EF6 完整入门教程三
    MVC5 + EF6 入门完整教程二
    每日总结9.11
    setTextColor的几个注意事项
    selector使用注意事项
    每日总结9.9
    android popWindow使用注意事项
    有关TextView的drawaleTop属性
  • 原文地址:https://www.cnblogs.com/ibcdwx/p/14225899.html
Copyright © 2011-2022 走看看