我有一个也是Eureka Server的Spring Boot应用程序。我想列出已注册到此Eureka服务器的所有实例。我该怎么做?
最佳答案
使用registry
提取EurekaServerContextHolder.getInstance().getServerContext().getRegistry()
,然后使用registry
列出所有Applications
PeerAwareInstanceRegistry registry = EurekaServerContextHolder.getInstance().getServerContext().getRegistry();
Applications applications = registry.getApplications();
applications.getRegisteredApplications().forEach((registeredApplication) -> {
registeredApplication.getInstances().forEach((instance) -> {
System.out.println(instance.getAppName() + " (" + instance.getInstanceId() + ") : " + response);
});
});