当前位置:网站首页>Hystrix deployment
Hystrix deployment
2022-06-28 10:32:00 【All right, all right】
Reference resources
Java Version implementation : github Address
PHP Version implementation : github Address
Realization
Hystrix Support two ways to realize fuse degradation function :
programmatic
declarative
programmatic
In a programmatic implementation , be based on Hystrix rich API, The setting of circuit breaker is realized by coding .API Users are required to encapsulate different external interactions into command mode objects . During the call , Form a layer of agent ,Hystrix The framework performs periodic takeover on the command object , And determine the circuit breaker status according to the status report obtained in the window .
Add core dependencies hystrix-core To pom.xml file
<dependency>
<groupId>com.netflix.hystrix</groupId>
<artifactId>hystrix-core</artifactId>
<version>1.5.18</version>
</dependency>The package needs to fuse the code logic to Command Class
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";
}
}initialization Command object , And implement execute() Method .
declarative
seeing the name of a thing one thinks of its function , The same effect can be achieved by configuring the declaration , This method has little business intrusion , Automatic code implantation without coding , High business acceptance . This scheme needs to introduce dependencies , And in main class Use notes in EnableHystrix Activate this function .
Add core dependencies hystrix-javanica To pom.xml file
<dependency>
<groupId>com.netflix.hystrix</groupId>
<artifactId>hystrix-javanica</artifactId>
<version>x.y.z</version>
</dependency>Use @HystrixCommand Modify the monitored method , And provide the bottom logic :
Introduce... Into the environment HystrixCommandAspect Injection section , Intercept all with HystrixCommand Method of annotation , And generate its proxy object . Business calls do not need to be adjusted , I
spring-cloud-netflix-hystrix Depend on hystrix-javanica , Can make Hystrix Open the box . For the automatic configuration code, see
@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 The bridge
stay Hystrix Design support with plugin The way to bridge metrics To external systems , The plug-in requires inheritance com.netflix.hystrix.strategy.metrics.HystrixMetricsPublisher .
Bridged metrics Can be uniformly exported to actuator Endpoint , And then Prometheus Pull to .
边栏推荐
- Django数据库操作以及问题解决
- 卸载oracle报错
- Must the MySQL table have a primary key for incremental snapshots?
- R语言plotly可视化:plotly可视化互相重叠的直方图(histogram)、在直方图的底部边缘使用geom_rug函数添加边缘轴须图Marginal rug plots
- Metersphere实现UI自动化元素不可点击(部分遮挡)
- Ribbon核心源码解析
- idea连接sql sever失败
- 使用 ABAP 操作 Excel 的几种方法
- [200 opencv routines] 213 Draw circle
- 我大抵是卷上瘾了,横竖睡不着!竟让一个Bug,搞我两次!
猜你喜欢

一文读懂 12种卷积方法(含1x1卷积、转置卷积和深度可分离卷积等)
Ribbon核心源码解析

BLE蓝牙模块NRF518/NRF281/NRF528/NRF284芯片方案对比

一种跳板机的实现思路

无线模块透明传输技术的物联网应用案例

To enhance the function of jupyter notebook, here are four tips

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

dotnet 使用 Crossgen2 对 DLL 进行 ReadyToRun 提升启动性能

fastposter v2.8.4 发布 电商海报生成器
![[unity] built in rendering pipeline to URP](/img/a5/3ae37b847042ffb34e436720f61d17.png)
[unity] built in rendering pipeline to URP
随机推荐
Katalon当中的output使用方法
Minimum stack < difficulty coefficient >
appliedzkp zkevm(10)中的Transactions Proof
Bytecode proof in appliedzkp zkevm (9)
爬虫小操作
fastposter v2.8.4 发布 电商海报生成器
R语言plotly可视化:plotly可视化互相重叠的直方图(histogram)、在直方图的底部边缘使用geom_rug函数添加边缘轴须图Marginal rug plots
老板叫我写个APP自动化--Yaml文件读取--内附整个框架源码
Resolution: overview of decentralized hosting solution
Django数据库操作以及问题解决
如何使用 DataAnt 监控 Apache APISIX
MySQL common commands for viewing database performance
各位大佬,问下Mysql不支持EARLIEST_OFFSET模式吗?Unsupported star
增强 Jupyter Notebook 的功能,这里有四个妙招
[unity][ecs] learning notes (II)
An error is reported when uninstalling Oracle
[leetcode daily question] [December 19, 2021] 997 Find the town judge
MySQL general binary installation method
【NLP】今年高考英语AI得分134,复旦武大校友这项研究有点意思
理想中的接口自动化项目