发现服务

@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;
}

 

上一篇:Stacking


下一篇:RedLock底层实现