Eureka实现灰度发布(功能优雅下线)

@RestController
public class HelloController {
    @Autowired
    private DiscoveryClient client;
 
    @RequestMapping(value = "/hello", method = RequestMethod.GET)
    public String index() {
        java.util.List<ServiceInstance> instances = client.getInstances("hello-service");       
        return "Hello World";
    }
    
    @RequestMapping(value = "/offline", method = RequestMethod.GET)
    public void offLine(){
    	DiscoveryManager.getInstance().shutdownComponent();
    }   
}

eureka客户端是是一个spring boot应用通过调用以下代码通知注册中心下线。 

DiscoveryManager.getInstance().shutdownComponent(); 

发布了159 篇原创文章 · 获赞 177 · 访问量 147万+

猜你喜欢

转载自blog.csdn.net/hanghangaidoudou/article/details/103785916