以编程方式从 Eureka Server 中删除已注册的实例
Programmatically remove registered instance from Eureka Server
有没有办法在不使用 REST 操作的情况下从 Eureka Server 中删除已注册的实例?包含所有应用程序的数据结构是什么?
(很明显,我想删除他们在Eureka Server中编写代码)。
您需要的功能可通过 InstanceRegistry
, which is itself just an extension of the Netflix Eureka classes (PeerAwareInstanceRegistryImpl
, and AbstractInstanceRegistry
).
具体来说,AbstractInstanceRegistry#cancel(String,String,boolean)
方法应该从注册表中删除应用程序。
此方法的 Javadoc 指出:
/**
* 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.
*/
这就是您从 Eureka 服务器本身实现这一目标的方式。
有没有办法在不使用 REST 操作的情况下从 Eureka Server 中删除已注册的实例?包含所有应用程序的数据结构是什么?
(很明显,我想删除他们在Eureka Server中编写代码)。
您需要的功能可通过 InstanceRegistry
, which is itself just an extension of the Netflix Eureka classes (PeerAwareInstanceRegistryImpl
, and AbstractInstanceRegistry
).
具体来说,AbstractInstanceRegistry#cancel(String,String,boolean)
方法应该从注册表中删除应用程序。
此方法的 Javadoc 指出:
/**
* 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.
*/
这就是您从 Eureka 服务器本身实现这一目标的方式。