由于客户端请求服务端方法时,服务端方法响应超过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>

6.Hystrix-超时设置的更多相关文章

  1. Hystrix超时测试

    package com.cookie.test; import com.netflix.hystrix.HystrixCommand; import com.netflix.hystrix.Hystr ...

  2. delphi tidhttp 超时设置无效的解决方法

    现在delphi都发布到xe8了,tidhttp还有缺陷,那就是超时设置在没有网络或者连不上服务器的时候是无效的,不管你设置为多少都要10-20秒.connectTimeout和readTimeout ...

  3. Linux串口中的超时设置

    在Linux下使用串口通信时,默认的阻塞模式是不实用的.而采用select或epoll机制的非阻塞模式,写代码有比较麻烦.幸好Linux的串口自己就带有超时机制. Linux下使用termios.h中 ...

  4. org.apache.http.client.HttpClient; HttpClient 4.3超时设置

    可用的code import org.apache.commons.lang.StringUtils;import org.apache.http.HttpEntity;import org.apac ...

  5. HttpClient 3.X 4.3 4.x超时设置

    HttpClient 4.3.HttpClient这货和Lucene一样,每个版本的API都变化很大,这有点让人头疼.就好比创建一个HttpClient对象吧,每一个版本的都不一样, 3.X是这样的 ...

  6. Apache性能优化、超时设置,linux 重启apache

    在httpd.conf中去掉Include conf/extra/httpd-default.conf前的#以使httpd-default.php生效.其中调节以下参数Timeout 15 (连接超时 ...

  7. libcurl多线程超时设置不安全(转)

    from http://www.cnblogs.com/kex1n/p/4135263.html (1), 超时(timeout) libcurl 是 一个很不错的库,支持http,ftp等很多的协议 ...

  8. CXF超时设置

    转自: http://peak.iteye.com/blog/1285211 http://win.sy.blog.163.com/blog/static/9419718620131014385644 ...

  9. 使用select io复用实现超时设置

    在linux的socket编程中,经常会遇到超时设置的问题,例如请求方如果在Ks内不发送数据则服务器要断开连接停止服务.这里我使用select的io复用实现超时5s设置,具体代码片段如下: fd_se ...

  10. jquery ajax超时设置

    var ajaxTimeoutTest = $.ajax({ url:'',  //请求的URL timeout : 1000, //超时时间设置,单位毫秒 type : 'get',  //请求方式 ...

随机推荐

  1. HDU5384-Hotaru's problem-Manacher

    找出紧挨的三个回文串,例如abccbaabc ,形如ABA格式,其中AB为回文串.计算最长的长度. 首先用Manacher处理回文半径.然后就是找到两个点,都是偶数的回文串,并且共享了中间一段. 之后 ...

  2. Elasticsearch 中数据类型 text 与 keyword 的区别

    随着ElasticSearch 5.X 系列的到来, 同时也迎来了该版本的重大特性之一: 移除了string类型. 这个变动的根本原因是string类型会给我们带来很多困惑: 因为ElasticSea ...

  3. Semi-prime H-numbers POJ - 3292 打表(算复杂度)

    题意:参考https://blog.csdn.net/lyy289065406/article/details/6648537 一个H-number是所有的模四余一的数. 如果一个H-number是H ...

  4. springMVC整理03--处理数据模型 & 试图解析器 & @ResponseBody & HttpEntity

    1.处理模型数据 SpringMVC 中的模型数据是非常重要的,因为 MVC 中的控制(C)请求处理业务逻辑来生成数据模型(M),而视图(V)就是为了渲染数据模型的数据.当有一个查询的请求,控制器(C ...

  5. 局域网共享hfs 软件使用

    前言 由于想从局域网同学电脑上偷点小片,又不想用u盘拷贝.所有在同学电脑上打开hfs软件,通过自己电脑ie浏览器(chrome不行报错)下载即可. 流程 1.两台电脑在同一局域网下,在同学电脑上打开h ...

  6. 【XSY1528】azelso 概率&期望DP

    题目大意 有一条很长很长的路(出题人的套路),你在\(0\)位置,你要去\(h\)位置. ​ 路上有一些不同的位置上有敌人,你要和他战斗,你有\(p\)的概率赢.若你赢,则你可以走过去,否则你会死.还 ...

  7. HDOJ5547 SudoKu

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5547 题目大意:填数独... 思路:爆搜 #include <stdio.h> #incl ...

  8. Android stadio 生成项目 Plugin with id 'com.android.application' not found

    buildscript { repositories { jcenter() } dependencies { classpath 'com.android.tools.build:gradle:2. ...

  9. web 压力测试工具

    最近有收到任务,测试新服务器的性能. 花了很长时间做搜索,也整理了一些资料.以下是收集到一些简单易用的分析工具.推荐给大家使用. WebBenchhttp://www.ha97.com/4623.ht ...

  10. agc031

    T1 题意:给你一个串,求所有子序列个数,满足没有相同字符.1e5,2s. 解:考虑一个合法的子序列.其中每个字母的出现位置都有(出现次数)种选择.还可以不选,要 + 1. 然后乘起来就做完了.如果变 ...