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?
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);
});
});