当前位置:网站首页>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拉取到。
边栏推荐
- [unity][ecs] learning notes (II)
- 【云驻共创】DWS告警服务DMS详细介绍和集群连接方式简介
- 物联网5种无线传输协议特点大汇总
- PHP curl forged IP address and header information code instance - Alibaba cloud
- 读取pdf文字和excel写入操作
- Read PDF Text and write excel operation
- 手把手教你处理 JS 逆向之 SVG 映射
- 关于FTP的协议了解
- Fastposter v2.8.4 release e-commerce poster generator
- Redis sentinel cluster main database failure data recovery ideas # yyds dry goods inventory #
猜你喜欢

Dbeaver installation and use tutorial (super detailed installation and use tutorial)

老板叫我写个APP自动化--Yaml文件读取--内附整个框架源码

bye! IE browser, this route edge continues to go on for IE

解决表单action属性传参时值为null的问题

【OpenCV 例程200篇】213. 绘制圆形

Interface automation framework scaffolding - Implementation of parametric tools
![[unity][ecs] learning notes (I)](/img/eb/1f0ad817bbc441fd8c14d046b82dd0.png)
[unity][ecs] learning notes (I)

如图 用sql行转列 图一原表,图二希望转换后

港伦敦金行情走势图所隐藏的信息

我大抵是卷上瘾了,横竖睡不着!竟让一个Bug,搞我两次!
随机推荐
Looking at jBPM from jbm3 to jbm5 and activiti
As shown in the figure, the SQL row is used to convert the original table of Figure 1. Figure 2 wants to convert it
JSON数据与List集合之间的正确转换
理想中的接口自动化项目
增量快照 必须要求mysql表有主键的吗?
Fastposter v2.8.4 release e-commerce poster generator
Django database operation and problem solving
MySQL的开发环境和测试环境有什么区别??
Realize an air conditioner with compose to bring you cool in summer
Correct conversion between JSON data and list collection
Idea failed to connect to SQL Sever
【OpenCV 例程200篇】213. 绘制圆形
[happy Lantern Festival] guessing lantern riddles eating lantern festival full of vitality ~ (with lantern riddle guessing games)
I'm almost addicted to it. I can't sleep! Let a bug fuck me twice!
Chapter 3 stack and queue
sqlcmd 连接数据库报错
Restful style
What is the difference between MySQL development environment and test environment??
Fabric. How to use js brush?
R语言使用car包中的avPlots函数创建变量添加图(Added-variable plots)、在图像交互中,在变量添加图中手动标识(添加)对于每一个预测变量影响较大的强影响点