我使用Netflix的Eureka注册了许多微服务,我也在使用Spring Cloud Config。但是,当我更新application.properties时,我需要重新启动应用程序才能应用新的属性。
重启应用程序有点烦人,所以我在谷歌上搜索了一下,发现可以使用Netflix Eureka获取注册的微服务,并使用spring boot actuator刷新它,但我未能获得注册的微服务。
简而言之:如何使用Netflix Eureka获得注册的微服务?
发布于 2020-10-30 00:55:29
您可以使用com.netflix.discovery.EurekaClient接口以编程方式访问Eureka的注册表。
例如,要向某个服务的所有实例发送刷新:
@RestController
public class EurekaOperationsController {
@Autowired
private EurekaClient eurekaClient;
@Autowired
private RestTemplate restTemplate;
@PostMapping("/{serviceName}")
public void refreshAllInstancesOf(@RequestParam String serviceName) {
Application application = eurekaClient.getApplications().getRegisteredApplications(serviceName);
application.getInstances().forEach(instanceInfo -> {
restTemplate.postForEntity(instanceInfo.getHomePageUrl() + "actuator/refresh", null, Void.class);
});
}
}这可以在任何Eureka客户端中,包括Eureka服务本身,因为它应该自我注册为客户端。
发布于 2020-10-30 00:15:41
如果您正在尝试使用eureka来识别服务位置,那么我强烈建议您在客户端使用ribbon。因此,您不需要对应用程序进行任何其他更改。请看这一张。https://cloud.spring.io/spring-cloud-netflix/multi/multi_spring-cloud-ribbon.html
https://stackoverflow.com/questions/64567389
复制相似问题