spring cloud hystrix timeouts

本文详细解析了Spring Cloud中Hystrix超时时间的配置逻辑,包括默认超时时间、具体服务超时时间及与Ribbon超时时间的关系。强调了具体服务超时时间的优先级高于默认超时时间,且两者都高于Ribbon超时时间。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

spring cloud hystrix timeouts

protected static int getHystrixTimeout(IClientConfig config, String commandKey) {
    int ribbonTimeout = getRibbonTimeout(config, commandKey);
    DynamicPropertyFactory dynamicPropertyFactory = DynamicPropertyFactory.getInstance();
    
    // 获取默认的hytrix超时时间
    int defaultHystrixTimeout = dynamicPropertyFactory.getIntProperty("hystrix.command.default.execution.isolation.thread.timeoutInMilliseconds",
        0).get();
    // 获取具体服务的hytrix超时时间,这里应该是hystrix.command.foo.execution.isolation.thread.timeoutInMilliseconds
    int commandHystrixTimeout = dynamicPropertyFactory.getIntProperty("hystrix.command." + commandKey + ".execution.isolation.thread.timeoutInMilliseconds",
        0).get();
    int hystrixTimeout;
    // hystrixTimeout的优先级是 具体服务的hytrix超时时间 > 默认的hytrix超时时间 > ribbon超时时间
    if(commandHystrixTimeout > 0) {
        hystrixTimeout = commandHystrixTimeout;
    }
    else if(defaultHystrixTimeout > 0) {
        hystrixTimeout = defaultHystrixTimeout;
    } else {
        hystrixTimeout = ribbonTimeout;
    }
    // 如果默认的或者具体服务的hytrix超时时间小于ribbon超时时间就会警告
    if(hystrixTimeout < ribbonTimeout) {
        LOGGER.warn("The Hystrix timeout of " + hystrixTimeout + "ms for the command " + commandKey +
            " is set lower than the combination of the Ribbon read and connect timeout, " + ribbonTimeout + "ms.");
    }
    return hystrixTimeout;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值