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

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. 在函数内部定义的函数 this 指向 undefined

    在函数内部定义的函数 this 指向 undefined 以下这个 this 就是指向 undefined. 但在非 strict 模式下是指向 window <script> 'use ...

  2. PHP 中的对象传递

    <?php class A { public $age = 0; public $username = ""; public $obj = null; } $a = new ...

  3. 浏览器的自动翻译会影响 JS 逻辑

    有人在 QQ 群里反馈,官方注册后跳转时出现 Bug. 收到群友非常有用的资讯,这是因为浏览器的自动翻译功能引起的. 11:04:21[潜水]Better Command 2017/12/30 11: ...

  4. 【转】【iOS】动态更换App图标

    原文网址:http://www.cocoachina.com/ios/20170619/19557.html 前言 动态更换App图标这件事,在用户里总是存在需求的:有些用户喜欢“美化”自己的手机.至 ...

  5. python之 数据类型判定与类型转换

    一. 判断数据类型 0.type(x)type()可以接收任何东西作为参数――并返回它的数据类型.整型.字符串.列表.字典.元组.函数.类.模块,甚至类型对象都可以作为参数被 type 函数接受. & ...

  6. ML(4.2): R CART

    CART模型 :即Classification And Regression Trees.它和一般回归分析类似,是用来对变量进行解释和预测的工具,也是数据挖掘中的一种常用算法.如果因变量是连续数据,相 ...

  7. Python中的偏函数

    偏函数是从Python2.5引入的一个概念,通过functools模块被用户调用. 偏函数是将所要承载的函数作为partial()函数的第一个参数,原函数的各个参数依次作为partial()函数后续的 ...

  8. FPGA将加速今日新型态数据中心的主流应用

    在这个强调智能与联网的时代,可编程逻辑栅阵列 (FPGA)已经成为一个重要且不可或缺的元件.以全球500亿个联网设备,一年所产生的数据量将不计其数.从数据中心.5G通讯.虚拟网络功能,到嵌入式系统,F ...

  9. appiu 笔记

    1.要在手机上输入字符, 要屏蔽手机键盘 于是可以想办法屏蔽软键盘,只需在desired_caps{}设置里面加两个参数 unicodeKeyboard是使用unicode编码方式发送字符串reset ...

  10. 操他妈的,jquery1.4以上不能用toggle()轮流切换函数

    query 1.9里面已经删除了toggle(fn1, fn2)函数 (2013-05-07 13:44:27) 转载▼ 标签: it 分类: js jquery 1.9里面已经删除了toggle(f ...