public class NacosServiceListener { private static String serviceName = "wms"; private static List<Instance> listenService() throws NacosException { String serverAddr = "127.0.0.1:8848"; NamingService namingService = NacosFactory.createNamingService(serverAddr); String serverStatus = namingService.getServerStatus(); List<ServiceInfo> subscribeServices = namingService.getSubscribeServices(); List<Instance> wms = namingService.getAllInstances("wms"); ListView<String> servicesOfServer = namingService.getServicesOfServer(1, 20); return namingService.getAllInstances(serviceName); } public static void main(String[] args) throws NacosException { boolean healthy = false; List<Instance> instances = listenService(); if (!CollectionUtils.isEmpty(instances)) { Instance instance = instances.get(0); healthy = instance.isHealthy(); System.out.println(serviceName + "健康状态: " + healthy); } else { System.out.println(serviceName + "健康状态: " + healthy); } } }
标签:String,instances,healthy,List,Nacos,指定,namingService,获取,serviceName From: https://www.cnblogs.com/axibug/p/16965338.html