我需要获取正在运行的微服务的当前实例 ID,问题是我要求如果未注册进程,则必须提供“随机生成的”实例 ID。
我正在尝试从 DiscoveryClient 获取服务实例 ID,但正如代码指出的那样,getLocalServiceInstance它已被弃用,我无法使用它。
我尝试使用Registrationjavadoc 中所述的方法,但找不到初始化它的方法。
是否有常规/特定方式来获得服务自己的注册?
顺便说一句,我不能使用直接实现,因为它是一个启动器,不知道在运行时可以使用什么 DiscoveryService 实现。
/**
* @deprecated use the {@link org.springframework.cloud.client.serviceregistry.Registration} bean instead
*
* @return ServiceInstance with information used to register the local service
*/
@Deprecated
ServiceInstance getLocalServiceInstance();