当前位置:网站首页>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 .
边栏推荐
- Sqlcmd database connection error
- Transactions proof in appliedzkp zkevm (10)
- 【OpenCV 例程200篇】213. 绘制圆形
- ICMP协议的作用,Ping of Death攻击的原理是什么?
- Bytecode proof in appliedzkp zkevm (9)
- 如何利用k线图做技术分析
- Fastposter v2.8.4 release e-commerce poster generator
- Google开源依赖注入框架-Guice指南
- Training and recognition of handwritten digits through the lenet-5 network built by pytorch
- R语言使用car包中的avPlots函数创建变量添加图(Added-variable plots)、在图像交互中,在变量添加图中手动标识(添加)对于每一个预测变量影响较大的强影响点
猜你喜欢
Ribbon core source code analysis
Internet of things application case of wireless module transparent transmission technology
Realization of a springboard machine
无线通信模块定点传输-点对多点的具体传输应用
[Unity]内置渲染管线转URP
接口自动化框架脚手架-利用反射机制实现接口统一发起端
学习机器学习的最佳路径是什么
解决表单action属性传参时值为null的问题
Several methods of using ABAP to operate Excel
一种跳板机的实现思路
随机推荐
The boss asked me to write an app automation -- yaml file reading -- with the whole framework source code attached
Chapter 3 stack and queue
Must the MySQL table have a primary key for incremental snapshots?
使用 ABAP 操作 Excel 的几种方法
I'm almost addicted to it. I can't sleep! Let a bug fuck me twice!
MarkDown——基本使用语法
An idea plug-in that automatically generates unit tests, which improves the development efficiency by more than 70%!
appliedzkp zkevm(10)中的Transactions Proof
一款自动生成单元测试的 IDEA 插件,开发效率提升 70% 以上!
树莓派无需显示屏的VNC Viewer方式的远程连接
Read PDF Text and write excel operation
关于FTP的协议了解
[unity] built in rendering pipeline to URP
Solve the problem that the value of the action attribute of the form is null when transferring parameters
Django数据库操作以及问题解决
增量快照 必须要求mysql表有主键的吗?
Interface automation framework scaffold - use reflection mechanism to realize the unified initiator of the interface
Hystrix 部署
Instant messaging and BS architecture simulation of TCP practical cases
Guangzhou Customs supports the stable supply of food, agricultural products, traditional Chinese medicine and other civilian and biological resources to Hong Kong