当前位置:网站首页>Implementation of service fusing
Implementation of service fusing
2022-04-23 22:00:00 【Leon_ Jinhai_ Sun】
# 0. How to realize service fusing
- introduce hystrix rely on , And turn on the fuse ( Circuit breaker )
- Simulation degradation method
- Call test # 1. Introduced in the project hystrix rely on <!-- introduce hystrix-->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-hystrix</artifactId>
</dependency># 2. Open the circuit breaker @SpringBootApplication
@EnableCircuitBreaker // Used to open the circuit breaker
public class Products9998Application {
public static void main(String[] args) {
SpringApplication.run(Products9998Application.class, args);
}
}# 3. Use HystrixCommand Annotation implementation break // Service failure
@GetMapping("/product/break")
@HystrixCommand(fallbackMethod = "testBreakFall" )
public String testBreak(int id){
log.info(" Goods received id by : "+ id);
if(id<=0){
throw new RuntimeException(" Illegal data !!!");
}
return " Currently receiving goods id: "+id;
}
public String testBreakFall(int id){
return " The current data is illegal : "+id;
}# 4. Access test
- Normal parameter access
- Error parameter access # 5. summary
- From the above demonstration process, we can find that if a certain condition is triggered, the circuit breaker will automatically open , After a while, it'll shut down again after it's normal . So what is the opening condition of the circuit breaker ?
# 6. Circuit breaker opening conditions
- Official website : https://cloud.spring.io/spring-cloud-netflix/2.2.x/reference/html/#circuit-breaker-spring-cloud-circuit-breaker-with-hystrix
A service failure in the lower level of services can cause cascading failure all the way up to the user. When calls to a particular service exceed circuitBreaker.requestVolumeThreshold (default: 20 requests) and the failure percentage is greater than circuitBreaker.errorThresholdPercentage (default: >50%) in a rolling window defined by metrics.rollingStats.timeInMilliseconds (default: 10 seconds), the circuit opens and the call is not made. In cases of error and an open circuit, a fallback can be provided by the developer. -- From the official
# After the translation of the original text , Summarize the conditions for opening and closing :
- 1、 When a certain threshold is met ( Default 10 More than in seconds 20 Number of requests )
- 2、 When the failure rate reaches a certain level ( Default 10 More than in seconds 50% Request failed for )
- 3、 Reaching the above threshold , The circuit breaker will open
- 4、 When it's turned on , All requests are not forwarded
- 5、 After a while ( The default is 5 second ), At this time, the circuit breaker is half open , One of the requests will be forwarded . If it works , The circuit breaker will close , If it fails , Keep opening . repeat 4 and 5.
# Interview key questions : Circuit breaker process

# 7. The default service FallBack processing method
- If you develop a downgrade for each service method , For us , There may be a lot of code redundancy , Not conducive to maintenance , At this time, you need to add the default service degradation processing method
@GetMapping("/product/hystrix")
@HystrixCommand(fallbackMethod = "testHystrixFallBack") // adopt HystrixCommand Degraded processing Specify the method of error
public String testHystrix(String name) {
log.info(" The receiving name is : " + name);
int n = 1/0;
return " service [" + port + "] Response successful , The current receiving name is :" + name;
}
// Service degradation processing
public String testHystrixFallBack(String name) {
return port + " The current service has been degraded !!!, The receiving name is : "+name;
}版权声明
本文为[Leon_ Jinhai_ Sun]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/113/202204232157392813.html
边栏推荐
- Hystrix简介和服务端熔断的实现
- 【SDU Chart Team - Core】SVG属性类设计之枚举
- Question brushing plan -- backtracking method (I)
- Plato Farm元宇宙IEO上线四大,链上交易颇高
- [※ leetcode refers to offer 48. The longest substring without repeated characters (medium)]
- When pycharm debugs, view the tensor image of pytorch in the console
- Alibaba cloud responded to the disclosure of user registration information
- Oracle ora-01033: Oracle initialization or shutdown in progressprocess solution
- Database Experiment four View experiment
- Express ③ (use express to write interface and cross domain related issues)
猜你喜欢

Yolov5 NMS source code understanding

Chrome 94 introduces the controversial idle detection API, which apple and Mozilla oppose

Is rust more suitable for less experienced programmers?

手撕《Google SRE Book》

JS merge duplicate data in array object

微服务系统中服务降级

Oracle updates the data of different table structures and fields to another table, and then inserts it into the new table

Error message: b04access.00f eve'. Read of address 000001B4

Correction of date conversion format error after Oracle adds a row total

Preliminary analysis of Airbase
随机推荐
Thread safe sigleton (singleton mode)
清华大学 | WebFace260M:百万级深度人脸识别的基准(TPAMI2022)
presto on spark 支持3.1.3记录
Detailed explanation of basic assembly instructions of x86 architecture
服务雪崩、服务熔断、服务降级
Pytorch: runtimeerror: an attempt has been made to start a new process Error reporting (resolved)
A series of problems of C DataGridView binding list
Detectron2 using custom datasets
[leetcode refers to offer 32 - III. print binary tree III from top to bottom (medium)]
Normalized transforms in pytorch The real calculation process of normalize
Yolov5 NMS source code understanding
FAILURE: Build failed with an exception. * What went wrong: Execution failed for task ‘:app:stripDe
Sklearn function: Train_ Test_ Split (split training set and test set)
Introduction to tensorrt
1.整理华子面经--1
Database experiment I database definition and data import
Pycharm download and installation
Automatic heap dump using MBean
2022-04-24日报:在生物科学领域应用深度学习的当前进展和开放挑战
DW basic course (II)