Hystrix的用法demo
1.引入依赖
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-hystrix</artifactId>
</dependency> 2.使用
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的用法demo的更多相关文章
- QMsgPack的用法DEMO
QMsgPack的用法DEMO 引用单元文件: uses qstring, qmsgpack, qjson; 演示一: procedure TForm2.Button10Click(Sender: T ...
- Hystrix的用法
package com.example.demo; import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand; imp ...
- easyui 之ComboTree 用法Demo
实现效果如下: HTML部分: <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="ser ...
- Java SPI机制用法demo
①构建一个maven工程 包含如下目录结构: src/main/java src/main/resources src/test/java src/test/resources ②在src/main/ ...
- Hibernate Validation与Spring整合各注解的用法Demo
转自:https://www.aliyun.com/jiaocheng/1315650.html <dependency> <groupId>org.hibernate< ...
- TryParse用法示例
int.Parse()是一种类型转换:表示将数字内容的字符串转为int类型.如果字符串为空,则抛出ArgumentNullException异常:如果字符串内容不是数字,则抛出FormatExce ...
- TryParse用法
int.Parse()是一种类型转换:表示将数字内容的字符串转为int类型. 如果字符串为空,则抛出ArgumentNullException异常: 如果字符串内容不是数字,则抛出FormatExce ...
- hystrix应用介绍(二)
上篇博客中讲了hystrix在公司中的一些应用场景,由于保密的原因没办法贴出优化的代码,这里专门写一篇hystrix代码的demo,供大家在使用的过程中快速上手 Hystrix有两个请求命令 Hyst ...
- SpringCloud学习笔记(五、SpringCloud Netflix Hystrix)
目录: Hystrix简介 线程隔离:线程池.信号量 服务降级.服务熔断.请求缓存.请求合并 Hystrix完整流程.Hystrix属性值 注解方式实现Hystrix Hystrix Dashboar ...
随机推荐
- Hive QL——深入浅出学Hive
第一部分:DDL DDL •建表 •删除表 •修改表结构 •创建/删除视图 •创建数据库 •显示命令 建表 CREATE [EXTERNAL] TABLE [IF NOT EXISTS] table_ ...
- ASP.NET 5 Beta5来了(翻译)
在6月30日微软发布了ASP.NET 5 Beta5,我们可以从http://nuget.org上获取Beta5 的packages. 随着VS2015RC发布的ASP.NET 5的版本号是Beta4 ...
- poj 3258 River Hopscotch 题解
[题意] 牛要到河对岸,在与河岸垂直的一条线上,河中有N块石头,给定河岸宽度L,以及每一块石头离牛所在河岸的距离, 现在去掉M块石头,要求去掉M块石头后,剩下的石头之间以及石头与河岸的最小距离的最大值 ...
- Spark开源学习模块
Spark开源的各模块组成结构: 1. Narrow dependency--窄依赖,子RDD依赖于父RDD中固定的data partition. 2. Stage--分为多个阶段进行作业. 3. W ...
- OpenCV学习(4) Mat的基本操作(1)
图像在OpenCV中都是通过Mat类来存储的,Mat可以用来表示N维矩阵,当然用的最多的还是二维矩阵. Mat类有两部分组成:第一部分是头信息,这些信息主要用来描述矩阵,比如矩 ...
- hadoop中实现定制Writable类
Hadoop中有一套Writable实现可以满足大部分需求,但是在有些情况下,我们需要根据自己的需要构造一个新的实现,有了定制的Writable,我们就可以完全控制二进制表示和排序顺序. 为了演示如何 ...
- Netbeans配合xdebug调试
http://xdebug.org/download.php 下载对应的xdebug的dll不知道php文件中的ext文件夹中 并且加入以下配置在php.info 然后重启apche zend_ext ...
- (LeetCode 49)Anagrams
Given an array of strings, return all groups of strings that are anagrams. Note: All inputs will be ...
- ES PS TS 流的区别
http://fengqing888.blog.163.com/blog/static/330114162012111805717584/ ES是原始码流,包含视频.音频或数据的连续码流.TS是传输流 ...
- 关于UbuntuMate的两个问题点:SSH问题处理与自启动项配置
一.SSH连接报错问题 ssh到某台机器时候,存在如下报错: /usr/bin/xauth: timeout in locking authority file /home/sam/.Xauthori ...