Is there a way to remove a registered instance from the Eureka Server without using REST operations? Which is the data structure that contains all the applications?
(It's clear that I want to remove them writing code in the Eureka Server).
The functionality you are after is available via the InstanceRegistry
, which is itself just an extension of the Netflix Eureka classes (PeerAwareInstanceRegistryImpl
, and AbstractInstanceRegistry
).
Specifically, the AbstractInstanceRegistry#cancel(String,String,boolean)
method should remove applications from the registry.
The Javadoc for this method states:
/**
* Cancels the registration of an instance.
*
* <p>
* This is normally invoked by a client when it shuts down informing the
* server to remove the instance from traffic.
* </p>
*
* @param appName the application name of the application.
* @param id the unique identifier of the instance.
* @param isReplication true if this is a replication event from other nodes, false
* otherwise.
* @return true if the instance was removed from the {@link AbstractInstanceRegistry} successfully, false otherwise.
*/
This is how you would achieve this from the Eureka server itself.