package com.example.demo;

import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import com.netflix.hystrix.contrib.javanica.annotation.HystrixProperty;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController; @RestController
@RequestMapping("/app")
public class AppController { @RequestMapping("/get/{id}")
@HystrixCommand(fallbackMethod = "getFallBack", commandProperties = {
@HystrixProperty(name = "execution.isolation.thread.timeoutInMilliseconds", value = "500")
})
public String get(@PathVariable("id") long id) throws Exception { // throw new Exception("error");
Thread.sleep(id);
return "get";
} public String getFallBack(@PathVariable("id") long id) {
return "getFallBack"; }
}
package com.example.demo;

import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import com.netflix.hystrix.contrib.javanica.annotation.HystrixProperty;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController; @RestController
@RequestMapping("/app")
public class AppController { @RequestMapping("/get/{id}")
@HystrixCommand(fallbackMethod = "getFallBack", commandProperties = {
@HystrixProperty(name = "execution.isolation.thread.timeoutInMilliseconds", value = "500")
})
public String get(@PathVariable("id") long id) throws Exception { // throw new Exception("error");
Thread.sleep(id);
return "get";
} public String getFallBack(@PathVariable("id") long id) {
return "getFallBack"; }
}

Hystrix的用法的更多相关文章

  1. Hystrix的用法demo

    1.引入依赖 <dependency> <groupId>org.springframework.cloud</groupId> <artifactId> ...

  2. Hystrix 用法及注解用法

    一.hystrix参数使用方法 通过注解@HystrixCommand的commandProperties去配置,如下就是hystrix命令超时时间命令执行超时时间,为1000ms和执行是不启用超时 ...

  3. Netflix Hystrix - 快速入门

    Hystrix最初是由Netflix的API team研发的,用于提高API的弹性和性能,2012年在公司内部广受好评. 如果你的应用是一个单独的应用,那几乎不用在意断路的问题. 但在分布式环境中,各 ...

  4. hystrix基本介绍和使用(1)

    一.hystrix基本介绍 Hystrix(https://github.com/Netflix/Hystrix)是Netflix(https://www.netflix.com/global)的一个 ...

  5. Spring Cloud微服务系列文,Hystrix与Eureka的整合

    和Ribbon等组件一样,在项目中,Hystrix一般不会单独出现,而是会和Eureka等组件配套出现.在Hystrix和Eureka整合后的框架里,一般会用到Hystrix的断路器以及合并请求等特性 ...

  6. 架构师系列文:通过Spring Cloud组件Hystrix合并请求

    在前文里,我们讲述了通过Hystrix进行容错处理的方式,这里我们将讲述通过Hystrix合并请求的方式 哪怕一个URL请求调用的功能再简单,Web应用服务都至少会开启一个线程来提供服务,换句话说,有 ...

  7. 架构师入门:Spring Cloud系列,Hystrix与Eureka的整合

    和Ribbon等组件一样,在项目中,Hystrix一般不会单独出现,而是会和Eureka等组件配套出现.在Hystrix和Eureka整合后的框架里,一般会用到Hystrix的断路器以及合并请求等特性 ...

  8. SpringCloud笔记六:Hystrix

    目录 Hystrix是什么? Hystrix服务熔断 新建Hystrix项目 修改yml Maven的pom.xml添加hystrix引用 修改Controller Hystrix服务降级 修改api ...

  9. Hystrix是个什么玩意儿

    1. 什么是Hystrix Hystrix是Netflix的一个开源框架,地址如下:https://github.com/Netflix/Hystrix 中文名为“豪猪”,即平时很温顺,在感受到危险的 ...

随机推荐

  1. Python性能优化:PyPy、Numba 与 Cython。PyPy的安装及对应pip的安装

    性能优化讨论见参考1:大概意思是,PyPy内置JIT,对纯Python项目兼容性极好,几乎可以直接运行并直接获得性能提升:缺点是对很多C语言库支持性不好.Numba是一个库,可以在运行时将Python ...

  2. Spring持久化

    1. Spring的DAO理念 Spring提供了一套抽象的DAO类,供开发者扩展,这有利于以统一的方式操作各种DAO技术,如JDO.JDBC等,这些抽象DAO类提供了设置数据源及相关辅助信息的方法, ...

  3. json 数组操作

    用js有很久了,但都没有深究过js的数组形式.这段时间做的一个项目,用到数组的地方很多,自以为js还可以的自己居然无从下手,一下狠心,我学!呵呵. 1.数组的创建 var arrayObj = new ...

  4. 13个 ASP.NET MVC 的扩展

    ASP.NET MVC设计的主要原则之一是可扩展性.处理管线(processing pipeline)上的所有(或大多数)东西都是可替换的.因此,如果您不喜欢ASP.NET MVC所使用的约定(或缺乏 ...

  5. HDU 2897 邂逅明下 (博弈)

    题意: 给你n.p.q,每次操作是令n减小 [p, q]区间中的数,当n < p时必须全部取完了,取完最后一次的人算输,问先手必胜还是必败. 解题思路: 这种非常类似巴什博弈,可以找出必胜区间和 ...

  6. 真人测试网站用户体验的超棒在线服务 - Peek by UserTesting

    闲逛的过程中找到的这个工具网站,它可以帮助你测试你的网站用户体验,而且会发送给你一个5分钟的视频来展示一个实际的用户(不是机器,是人哦)如何操作你的网站的,这个服务目前免费,大家如果有兴趣了解你的网站 ...

  7. Centos 安装Apache软件

    检查rpm    -qa    httpd [root@luozhonghua icons]# rpm    -qa   |grep  httpd httpd-2.2.15-30.el6.centos ...

  8. Tomcat 之 启动tomcat时 错误: 代理抛出异常 : java.rmi.server.ExportException: Port already in use: 1099;

    错误: 代理抛出异常 : java.rmi.server.ExportException: Port already in use: 1099; nested exception is:  java. ...

  9. AA MME设备内部错误

    adobe audition 找不到所支持的音频设备 这是3.0的错误!     上面是cs6的错误的图   主要原因是以前安装过,没有注册表没有清理干净     解决方案: https://jing ...

  10. Python 创建包含列表的元组

    “可变”的tuple前面我们看到了tuple一旦创建就不能修改.现在,我们来看一个“可变”的tuple:>>> t = ('a', 'b', ['A', 'B'])注意到 t 有 3 ...