当前位置:网站首页>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 .
边栏推荐
- 如图 用sql行转列 图一原表,图二希望转换后
- 使用 ABAP 操作 Excel 的几种方法
- Read PDF Text and write excel operation
- 学习机器学习的最佳路径是什么
- Ideal interface automation project
- 生成token
- Realize an air conditioner with compose to bring you cool in summer
- The introduction of flink-sql-mysql-cdc-2.2.1 has solved many dependency conflicts?
- 丢弃 Tkinter!简单配置快速生成超酷炫 GUI!
- Wireless communication module fixed-point transmission - point to multipoint specific transmission application
猜你喜欢
Ribbon core source code analysis

Ble Bluetooth module nrf518/nrf281/nrf528/nrf284 chip scheme comparison

Interface automation framework scaffolding - Implementation of parametric tools

What is the best way to learn machine learning

linux中源码安装mysql数据库(centos)

How to use dataant to monitor Apache apisex

Mysql通用二进制安装方式

ruoyi集成积木报表(nice)

一文读懂 12种卷积方法(含1x1卷积、转置卷积和深度可分离卷积等)

MySQL cannot be opened. Flash back
随机推荐
老板叫我写个APP自动化--Yaml文件读取--内附整个框架源码
[unity][ecs] learning notes (III)
【LeetCode每日一题】【2021/12/19】997. 找到小镇的法官
Read PDF image and identify content
R语言使用car包中的avPlots函数创建变量添加图(Added-variable plots)、在图像交互中,在变量添加图中手动标识(添加)对于每一个预测变量影响较大的强影响点
生成token
接口自动化框架脚手架-参数化工具的实现
[Li Kou - dynamic planning] sort out topic 1: basic topics: 509, 70, 746, 62, 63, 343, 96 (with links, topic descriptions, problem solving methods and codes)
June training (day 28) - Dynamic Planning
【monkey】monkey测试入门
如何利用k线图做技术分析
idea连接sql sever失败
物联网无线通信应用中6种融合定位技术
Sqlcmd database connection error
[leetcode daily question] [December 19, 2021] 997 Find the town judge
Discard Tkinter! Simple configuration to quickly generate cool GUI!
Missed the golden three silver four, found a job for 4 months, interviewed 15 companies, and finally got 3 offers, ranking P7+
Markdown -- basic usage syntax
无线模块透明传输技术的物联网应用案例
Django数据库操作以及问题解决