本文介绍了Eureka Server-列出所有注册的实例的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个Spring Boot应用程序,它也是一个Eureka服务器.我想列出已注册到此Eureka服务器的所有实例.我该怎么办?
I have a Spring Boot application that is also a Eureka Server. I want to list all instances that have been registered to this Eureka Server. How do I do it?
推荐答案
使用EurekaServerContextHolder.getInstance().getServerContext().getRegistry()
获取registry
,然后使用registry
列出所有Applications
Fetch the registry
using EurekaServerContextHolder.getInstance().getServerContext().getRegistry()
then use the registry
to list all 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);
});
});
这篇关于Eureka Server-列出所有注册的实例的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!