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学习(二)Python 简介

    Python 简介 官方指南及文档 Python2.7官方指南(中文版):http://pan.baidu.com/s/1dDm18xr Python3.4官方指南(中文版):http://pan.b ...

  2. C#使用DirectShow播放视频文件 [转]

    原文网址:http://blog.csdn.net/openzpc/article/details/48442751 最近在开发一个视频播放软件,主要要求就是循环播放多个视频文件,并且要求两个视频文件 ...

  3. 【补间动画示例】Tweened Animation

    代码中定义动画示例 public class MainActivity extends ListActivity </integer> 常用的Activity转场动画中的补间动画 publ ...

  4. ECharts学习总结(五):echarts的Option概览

    注:下面内容摘自echarts官网,原文地址:http://echarts.baidu.com/doc/doc.html#%E9%80%89%E9%A1%B9 option 图表选项,包含图表实例任何 ...

  5. 【云计算】jenkins,docker,mesos,marathon,k8s相关资料

    参考资料: 基于Apache Mesos 构建高可靠,高可用的Jenkins CI:http://blog.csdn.net/ebay/article/details/43529401 Docker ...

  6. HUD Text 学习

    使用版本 NGUI_HUD_Text_v1.11 .英语水平差,难免有很多不足之处,忘批评指正.本文为鬼脸苹果原创 HUD Text 的其中一个用途是,涉及到非战斗场景时,你能通过在角色头顶显示文本行 ...

  7. [Angular-Scaled Web] 6. Navigating between states with ui-router

    There are two ways to naviagting between state: 1. Using $state service, $state.go() 2. Using ui-ser ...

  8. WEB打印控件Lodop(V6.x)使用说明及样例

    WEB打印控件Lodop(V6.x)使用说明及样例 Lodop是专业WEB控件,用它既可裁剪输出页面内容,又可用程序代码生成复杂打印页. 控件功能强大,却简单易用,所有调用如同JavaScript扩展 ...

  9. 最短路+状态压缩dp(旅行商问题)hdu-4568-Hunter

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=4568 题目大意: 给一个矩阵 n*m (n m<=200),方格里如果是0~9表示通过它时要花 ...

  10. MySQL中的锁、隔离等级和读场景

    一.导言 关于MySQL中的锁还有隔离等级这类话题,其概念性的解释早已泛滥.记住其概念,算不上什么.更重要的是思考:他们的区别和联系在哪儿,为什么会有这样的概念. 1)MySQL的锁(Lock)分为行 ...