【问题标题】:Hystrix Fallback DisableHystrix 后备禁用
【发布时间】:2018-06-21 00:30:13
【问题描述】:

我有一个带有 hystrix 注释的方法,如下所示:

例如:

@HystrixCommand(fallbackMethod="testMessage")

public boolean receiveMessage(String message, String destination) 

{


Code goes here



}

.

所以我有一个标志,当它为真时,回退应该启用,否则如果为假,我需要禁用回退。有没有办法做到这一点。 注意我们使用的是注解,那么有没有办法启用和禁用注解意味着根据标志启用或禁用回退。

【问题讨论】:

    标签: annotations command hystrix fallback


    【解决方案1】:

    我能想到的几个选项。

    1. 保留一个静态布尔变量。并根据您的要求进行更改。在您的后备方法中,您可以检查此变量并仅在未设置的情况下继续进行。 (不太干净)
    2. (更好的解决方案)有一​​个 Hystrix 属性 hystrix.command.default.fallback.enabled 可以让您禁用回退,如提到的 here

    您可以在运行时设置此设置,获取 ConfigurationManager (com.netflix.config.ConfigurationManager)。像这样的

    com.netflix.config.ConfigurationManager.getConfigInstance().setProperty("hystrix.command.default.fallback.enabled", false)// If you want to turn it off
    

    【讨论】:

    • 有没有其他方法可以设置这个属性 hystrix.command.default.fallback.enabled.
    • 如果您不喜欢上面提供的选项,您可以随时使用注释 @HystrixProperty(name = HystrixPropertyManager.FALLBACK_ENABLED, value = "false")(我知道回复太晚了,但我认为这是值得的对于任何有兴趣的人)
    猜你喜欢
    • 2017-10-18
    • 2018-03-07
    • 2018-02-06
    • 2017-12-27
    • 2017-10-10
    • 2018-03-08
    • 2015-06-13
    • 2020-08-07
    • 2018-02-27
    相关资源
    最近更新 更多