如何做

@Resource
    private EurekaServerConfigBean eurekaServerConfigBean;

    @GetMapping("/disable/self-preservation")
    public void disableSelfPreservation() {
        eurekaServerConfigBean.setEnableSelfPreservation(false);
    }

    @GetMapping("/enable/self-preservation")
    public void enableSelfPreservation() {
        eurekaServerConfigBean.setEnableSelfPreservation(true);
    }

为什么我知道这么做?

  • 通过 wiki 介绍。得知有方法可以动态关闭自我保护机制(不过没说方案,差评!!!)

eureka wiki 的介绍中,有说到可以通过临时的强制关闭自我保护机制,但是却没有给出方案。原文如下:
https://github.com/Netflix/eureka/wiki/Server-Self-Preservation-Mode

The self preservation config is definedhere. To disable self preservation in the example, set the property:eureka.enableSelfPreservation=false.

In a production environment, if for some reason your servers have entered self preservation due to a legitimate reason, you can force the servers to be out of self preservation mode by temporarily disabling self preservation via config. We would expect that in these cases, a human operation is evaluating the situation and taking the appropriate actions.

上面大致的意思是:除了可以通过配置属性,还可以动态的关闭自我保护机制。

  • google 搜索关键字 eureka force the servers to be out of self preservation mode

https://github.com/Netflix/eureka/issues/1073

然后看到了这篇文章。

最后发现这兄弟点出了一个关键词,临时关闭自我保护

  • 查看源码

通过大兄弟给的链接,跳转到了 EurekaServerConfig 接口源码中。 EurekaServerConfigBean 实现了该接口。 并且被 spring 管理。
然后就有了上面最开始的解决方案

为什么会有这么奇葩的需求

本人在确实在生产环境中碰到了这样的要求。。。google(关键字没把握好),stackoverflow 一波,找到的方案,更多的是直接取消自我保护机制。还有就是降低 续期阈值的配置。(因为一开始的思路,就是想通过降低续期的阈值来解决的,后面发现,这个不靠谱呀!!!哪能在生产环境干这种事情!!!)


心无私天地宽
513 声望22 粉丝