发现服务

@Resource
private DiscoveryClient discoveryClient; #spring的包

@GetMapping(value="/payment/discovery")
public Object discovery(){
    List<String> services = discoveryClient.getServices();
    services.forEach(item -> {
        log.info("***********"+item);
    });
    List<ServiceInstance> instances = discoveryClient.getInstances("CLOUD-PAYMENT-SERVICE");
    instances.forEach(item ->{
        log.info("====="+item.getServiceId() + "\t"+item.getHost() + "\t" + item.getPort() + "\t" + item.getUri());
    });
    return discoveryClient;
}

 

posted @ 2020-05-07 23:43  洁瑞小弟  阅读(191)  评论(0编辑  收藏  举报