hystrix熔断指定方法设置超时时间

一、结论

hystrix:
  command:
    default:  #default全局有效
      execution:
        timeout:
          #是否开启超时熔断
          enabled: true
        isolation:
          thread:
            timeoutInMilliseconds: 6000 #断路器超时时间,默认1000ms
    HystrixCommonKey:  #HystrixCommandKey:要单独设置超时时间的方法
      execution:
        timeout:
          #是否开启超时熔断,默认true
          enabled: true
        isolation:
          thread:
            timeoutInMilliseconds: 10000 #断路器超时时间

二、查看HystrixCommandKey

HystrixCommonKey:类名#方法名(参数类型)
 public static String configKey(Class targetType, Method method) {
    StringBuilder builder = new StringBuilder();
    builder.append(targetType.getSimpleName());
    builder.append('#').append(method.getName()).append('(');
    for (Type param : method.getGenericParameterTypes()) {
      param = Types.resolve(targetType, targetType, param);
      builder.append(Types.getRawType(param).getSimpleName()).append(',');
    }
    if (method.getParameterTypes().length > 0) {
      builder.deleteCharAt(builder.length() - 1);
    }
    return builder.append(')').toString();//打断点,查看自己方法的 HystrixCommonKey
  }

你可能感兴趣的:(框架,java,spring,boot,后端,spring)