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 ...
随机推荐
- Tomcat与Servlet工作流程
什么是Tomcat? Tomcatserver是一个免费的开放源码的Web 应用server,属于轻量级应用server. 什么是Servlet? Servlet是在server上执行的小程序.,说白 ...
- go语言基础之range的用法
一.range的用法 示例1: 传统用法 package main //必须有一个main包 import "fmt" func main() { str := "abc ...
- C#装饰者模式实例代码
using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace 装饰者 ...
- 2014Esri全球用户大会——亮点系列之产品技术
2014年Esri全球用户大会已于7月14日~18日隆重召开,让我们一起来回味下面精彩内容: 序:大会主题"Creating Our Future" [解读]: 传达两个核 ...
- (1)风色从零单排《C++ Primer》 一个简单的c++程序
从零单排<C++ Primer> --(1)一个简单的c++程序 本次学习收获 0.写在前面 风色以前上过C++的课程,然而当时并没有认真去学,基本不能使用c++来作项目开发. 这次又一次 ...
- MESI-CPU缓存一致性协议
转http://blog.csdn.net/realxie/article/details/7317630 http://en.wikipedia.org/wiki/MESI_protocol MES ...
- uitabbar 标题设置 button text attributes only respected for UIControlStateNormal
uitabbar 标题设置 button text attributes only respected for UIControlStateNormal [[UITabBarItem appearan ...
- MySQL数据库和实例简介
MySQL 单进程多线程,也就是说MySQL实例在系统上表现就是一个进程 该架构类似于SQL Server和Windows版本的Oracle MySQL数据库是由一些列物理文件组成.类似于frm.MY ...
- scribe 搭建遇到的问题
1.如果安装了多个boost版本或boost路径不是scribe脚本指定的话,会出现问题: checking whether the Boost::System library is availabl ...
- 基于 bootstrap 的数据展示--bootgrid 样式改动。
bootgrid 的官网案例 http://www.jquery-bootgrid.com/Examples 官方demo 样式 基于项目须要,取消了一些不须要 的功能,改动了源代码 最后样式成了这样 ...