当前位置:网站首页>Hystrix 部署
Hystrix 部署
2022-06-28 10:13:00 【可以吧可以吧】
参考
Java版本实现: github地址
PHP版本实现: github地址
实现
Hystrix支持两种方式实现熔断降级功能:
编程式
声明式
编程式
在编程式实现中,基于Hystrix丰富的API,通过编码的方式实现断路器的设置。API要求用户将不同的外部交互封装成命令模式对象。在调用过程中,形成一层代理,Hystrix框架对命令对象执行周期接管,并根据窗口内获取到的状态报告决定断路器状态。
添加核心依赖 hystrix-core 到pom.xml文件
<dependency>
<groupId>com.netflix.hystrix</groupId>
<artifactId>hystrix-core</artifactId>
<version>1.5.18</version>
</dependency>包裹需要熔断处理的代码逻辑到Command类中
static class CommandHello extends HystrixCommand<String> {
private final String name;
public CommandHello(String name) {
super(Setter.withGroupKey(HystrixCommandGroupKey.Factory.asKey("ExampleGroup"))
.andCommandPropertiesDefaults(HystrixCommandProperties.Setter().withExecutionTimeoutInMilliseconds(3000)));
this.name = name;
}
@Override
protected String runTest() {
return "Hello " + name + "!";
}
// Default fallback method
public String getFallback() {
return "Fallback of Hello was triggered";
}
}初始化Command对象,并执行 execute() 方法。
声明式
顾名思义,通过配置声明的方式以达到以上方式同样的效果,这种方式对业务侵入小,无需编码自动植入代码功能,业务接受程度高。此方案需要引入依赖,并在main class中使用注释 EnableHystrix 激活该功能。
添加核心依赖 hystrix-javanica 到pom.xml文件
<dependency>
<groupId>com.netflix.hystrix</groupId>
<artifactId>hystrix-javanica</artifactId>
<version>x.y.z</version>
</dependency>使用@HystrixCommand修饰被监控方法,并提供兜底逻辑:
在环境中引入 HystrixCommandAspect 注入切面,拦截所有带有HystrixCommand注释的方法,并生成其代理对象。业务调用无需调整,我
spring-cloud-netflix-hystrix 依赖于 hystrix-javanica ,使能Hystrix开箱即用。自动配置代码见
@HystrixCommand(fallbackMethod = "fallback_hello", commandProperties = {
@HystrixProperty(name = "execution.isolation.thread.timeoutInMilliseconds", value = "1000")})
public String hello() throws InterruptedException {
System.out.println("Hello");
Thread.sleep(3000);
return "Welcome Hystrix";
}
private String fallback_hello() {
return "Request fails. It takes long time to response";
}Metrics桥接
在Hystrix设计支持以plugin的方式桥接metrics到外部系统,该插件要求继承 com.netflix.hystrix.strategy.metrics.HystrixMetricsPublisher 。
桥接后的metrics可统一导出到actuator端点,随后被Prometheus拉取到。
边栏推荐
- [200 opencv routines] 213 Draw circle
- 解析:去中心化托管解决方案概述
- PHP curl forged IP address and header information code instance - Alibaba cloud
- ECS MySQL query is slow
- 一文读懂 12种卷积方法(含1x1卷积、转置卷积和深度可分离卷积等)
- 如何利用k线图做技术分析
- Correct conversion between JSON data and list collection
- 云服务器MYSQL查询速度慢
- TCP实战案例之即时通信、BS架构模拟
- fastposter v2.8.4 发布 电商海报生成器
猜你喜欢

BLE蓝牙模块NRF518/NRF281/NRF528/NRF284芯片方案对比
![[200 opencv routines] 213 Draw circle](/img/8d/a771ea7008f84ae3a3cf41507448ec.png)
[200 opencv routines] 213 Draw circle

接口自动化框架脚手架-参数化工具的实现

一种跳板机的实现思路

mysql打不开,闪退
![QT signal and slot communication mechanism (when multiple windows communicate back and forth [parent and child windows])](/img/17/57ffb7393b71eddc5ac92ae3944338.jpg)
QT signal and slot communication mechanism (when multiple windows communicate back and forth [parent and child windows])

Starting from full power to accelerate brand renewal, Chang'an electric and electrification products sound the "assembly number"

Teach you how to handle the reverse SVG mapping of JS

如何查看谷歌浏览器保存的网页密码

MySQL cannot be opened. Flash back
随机推荐
Settings of gift giving module and other custom controls in one-to-one video chat system code
[unity][ecs] learning notes (III)
Sword finger offer | Fibonacci sequence
2022吴恩达机器学习specialization Week 2 practice lab: Linear regression
再見!IE瀏覽器,這條路由Edge替IE繼續走下去
我大抵是卷上瘾了,横竖睡不着!竟让一个Bug,搞我两次!
Proxy mode (proxy)
sqlcmd 连接数据库报错
【云驻共创】DWS告警服务DMS详细介绍和集群连接方式简介
Read PDF image and identify content
Discard Tkinter! Simple configuration to quickly generate cool GUI!
爬虫小操作
Training and recognition of handwritten digits through the lenet-5 network built by pytorch
用 Compose 实现个空调,为你的夏日带去清凉
OpenHarmony应用开发之二维码生成器
无线模块透明传输技术的物联网应用案例
[Unity]EBUSY: resource busy or locked
港伦敦金行情走势图所隐藏的信息
第五章 树和二叉树
Installing redis under Linux and windows (ultra detailed graphic tutorial)