• Hystrix超时设置无效及解决原因


    我有一个http接口如下,Hystrix策略设置为线程隔离,超时时间为10秒

    @PostMapping("addBatch")
    @HystrixCommand(fallbackMethod = "addBatchFallBack", commandProperties = {
      @HystrixProperty(name = "execution.isolation.strategy", value = "THREAD"),
      @HystrixProperty(name = "execution.isolation.thread.timeoutInMilliseconds", value = "10000"),
      @HystrixProperty(name = "execution.timeout.enabled", value = "true")
    })
    public CommonResult addBatch(@RequestBody List<TblEmployee> employees, @RequestParam(name = "t", required = false) String t) {
      return employeeService.addBatch(employees, t);
    }
    
    private CommonResult addBatchFallBack(List<TblEmployee> employees, String t, Throwable throwable) {
      throwable.printStackTrace();
      return new CommonResult(false, "fallback,原因:" + throwable.getMessage(), null);
    }
    

    yml文件中hystrix部分的配置如下:

    hystrix:
      dashboard:
        proxy-stream-allow-list: localhost
      command:
        default:
          execution:
            isolation:
              thread:
                timeoutInMilliseconds: 10000   #默认
            timeout:
              enabled: true                    # 必须设置true,否则会交给ribbon
        serverMethod:
          execution:
            isolation:
              thread:
                timeoutInMilliseconds: 10000   #配置具体方法的超时时间
    

    但是实际请求发现,1秒左右就自动触发了fallback方法,远远未达到我设置10秒超时的阈值,再次检测配置无误后不仅陷入沉思。

    查看异常发现一个关键信息:

    超时的异常是由ribbon抛出,而不是hystrix。突然想起来ribbon有自己的超时设置,于是果断调整ribbon的配置

    EMPLOYEE:
      ribbon:
        ReadTimeout: 300000 #5分钟
        ConnectTimeout: 300000
    

    再次请求接口,打印的异常如下:

    可以发现现在超时的异常是由hystrix抛出,大功告成

  • 相关阅读:
    eclipse中不能识别enum
    The source attachment does not contain the source for the file Activity.class
    ASP.NET应用程序脱机问题
    鱼仔系统部署教程
    鱼仔系统开发教程
    mysql innodb cluster 无感知集群
    Mysql 8.0 新特性测试
    随笔1
    音频输出格式
    2012.02.03(S3C6410中文手册笔记)(一)
  • 原文地址:https://www.cnblogs.com/wugang/p/14497236.html
Copyright © 2020-2023  润新知