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. JOIN与EXISTS(子查询)的效率研究

    使用MySQL提供的Sample数据库Sakila 现将profiling打开,用来一会查看sql执行时间 set profiling=1; exists 子查询与 join联接效率的对比,功能:查看 ...

  2. 图片变换【Matrix】矩阵 简介

    Matrix矩阵介绍 官方文档地址:https://developer.android.com/reference/android/graphics/Matrix.html 在Android中,对图片 ...

  3. iframe高度动态自适应

    by zhangxinxu from http://www.zhangxinxu.com本文地址:http://www.zhangxinxu.com/wordpress/?p=1294 一.前言碎碎念 ...

  4. ECharts学习总结(四):echarts的实例方法

    echarts的实例方法非常重要,因为在实际运用中我们额图表的数据不可能是死的,而是动态变化的,实例方法为动态改变数据提供了方法.故特意从官网上面把下面实例方法进行记录: 注:下面内容摘自echart ...

  5. MyEclipse 如何最佳设置

    摘自: http://blog.csdn.net/lifuxiangcaohui/article/details/8513561 MyEclipse 如何最佳设置 作为企业级开发最流行的工具,用Mye ...

  6. VS中的代码拖放

    平时数据操作中,我们经常在选择文件,由于数据太多.数据目录太深,选择数据文件到TextBox中非常不方便,于是就想让控件支持拖放数据,很多软件都支持这个功能,非常实用. 在ArcGIS10.x开发平台 ...

  7. 【树莓派】-bash: /usr/local/java/jdk1.8.0_161/bin/java: cannot execute binary file: Exec format error

    遇到这样的问题:-bash: /usr/local/java/jdk1.8.0_161/bin/java: cannot execute binary file: Exec format error ...

  8. Eclipse Kepler 设置中文编码 和 汉化

    以下是 mac 下 Eclipse Kepper的设置 一:设置中文编码 1:打开Eclipse--Preference-->general--->editor---->Spelli ...

  9. 移动端项目中 @2x 图 和 @3x 图 的使用

    移动端开发过程中,因为手机的dpr(设备像素比不同),我们需要根据dpr来修改图标的大小: 1.通过mixin,动态修改图标的背景图片.通过@media (媒体查询),判断设备的dpr. @mixin ...

  10. NSArray利用Cocoa框架进行汉字排序

    NSArray利用Cocoa框架进行汉字排序 在NSString有一个函数localizedCompare:,它的功能是通过自身与给定字符串的比較,返回一个本地化的比較结果.也就是说这个函数是支持汉字 ...