为何需要平滑发布
在使用eureka作为服务注册中心,应用之间通过FeignClient调用时,正常情况下,被调用方在发布时,调用方是有短暂时间调用不到服务的,提示报错: No route to Host。针对这种情况,需要实现eureka的平滑发布功能。其实,也就是实现点火,熄火接口。
springboot1.5+的实现
配置文件配置
eureka.instance.initialStatus=OUT_OF_SERVICE
management.health.eureka.enabled=false
management.health.discoveryClient.enabled=false
spring.cloud.discovery.client.composite-indicator.enabled=false
自定义类实现MvcEndpoint
@ManagedResource
@Configuration
public class EurekaStatusEndpoint implements MvcEndpoint {
@Resource
private ServiceRegistry serviceRegistry;
@Resource
private Registration registration;
@RequestMapping(path = "instance-status", method = RequestMethod.POST)
@ResponseBody
@ManagedOperation
public Object setStatus(@RequestBody String status) {
if (this.registration == null) {
throw new</
SpringCloud Eureka平滑发布实践指南

本文详细介绍了在SpringCloud中实现Eureka服务的平滑发布过程,旨在解决服务发布时调用方短暂无法连接的问题。内容涵盖1.5+及2.0+版本的配置方法,包括自定义MvcEndpoint和management端点接口的实现,以及点火、熄火接口的调用时机和操作流程,确保服务实例的无缝切换。
最低0.47元/天 解锁文章

被折叠的 条评论
为什么被折叠?



