zoukankan      html  css  js  c++  java
  • Hystrix-超时设置

    由于客户端请求服务端方法时,服务端方法响应超过1秒将会触发降级,所以我们可以配置Hystrix默认的超时配置

    如果我们没有配置默认的超时时间,Hystrix将取default_executionTimeoutInMilliseconds作为默认超时时间

    this.executionTimeoutInMilliseconds = getProperty(propertyPrefix, key, "execution.isolation.thread.timeoutInMilliseconds", builder.getExecutionIsolationThreadTimeoutInMilliseconds(), default_executionTimeoutInMilliseconds)

    1.代码中修改默认超时配置(改为3秒):

    @HystrixCommand(commandProperties = {
         @HystrixProperty(name = "execution.isolation.thread.timeoutInMilliseconds",value = "3000")
    })
    public String serverMethod() {
      return null;
    }
    2.application.properties中设置默认超时时间:
    1.默认:(方法上记得要加上@HystrixCommand,否则无效):
    hystrix.command.default.execution.isolation.thread.timeoutInMilliseconds=3000
    
    2.配置具体方法的超时时间
    hystrix.command.serverMethod.execution.isolation.thread.timeoutInMilliseconds=3000

    3.启动类:

    复制代码
    package com.wangfajun;
    
    import org.springframework.boot.SpringApplication;
    import org.springframework.boot.autoconfigure.SpringBootApplication;
    import org.springframework.cloud.client.SpringCloudApplication;
    import org.springframework.cloud.client.circuitbreaker.EnableCircuitBreaker;
    import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
    
    //@SpringBootApplication
    //@EnableDiscoveryClient
    //@EnableCircuitBreaker //开启断路器
    @SpringCloudApplication
    public class FajunClientTestApplication {
    
        public static void main(String[] args) {
            SpringApplication.run(FajunClientTestApplication.class, args);
        }
    }
    复制代码

    4.pom:

    <!--hystrix-->
    <dependency>
      <groupId>org.springframework.cloud</groupId>
      <artifactId>spring-cloud-starter-hystrix</artifactId>
    </dependency>
  • 相关阅读:
    AX 2012 Security Framework
    The new concept 'Model' in AX 2012
    How to debug the SSRS report in AX 2012
    Using The 'Report Data Provider' As The Data Source For AX 2012 SSRS Report
    Deploy SSRS Report In AX 2012
    AX 2012 SSRS Report Data Source Type
    《Taurus Database: How to be Fast, Available, and Frugal in the Cloud》阅读笔记
    图分析理论 大纲小结
    一文快速了解Posix IO 缓冲
    #转载备忘# Linux程序调试工具
  • 原文地址:https://www.cnblogs.com/maohuidong/p/9858089.html
Copyright © 2011-2022 走看看