当前位置:网站首页>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
边栏推荐
- Swift import third-party library reports an error no such module““
- [leetcode refers to offer 22. The penultimate node in the linked list (simple)]
- Xiaomi mobile phone has abandoned the "Mi" brand all over the world and switched to the full name brand of "Xiaomi"
- Error message: b04access.00f eve'. Read of address 000001B4
- 阿里又一个“逆天”容器框架!这本Kubernetes进阶手册简直太全了
- Database Experiment 7 stored procedure experiment
- 手撕《Google SRE Book》
- South Korea may ban apple and Google from offering commission to developers, the first in the world
- Question brushing plan - depth first search (II)
- YOLOv5 Unable to find a valid cuDNN algorithm to run convolution
猜你喜欢
随机推荐
Detailed explanation of basic assembly instructions of x86 architecture
Database Experiment 7 stored procedure experiment
Idea import a project
Express ③ (use express to write interface and cross domain related issues)
2022-04-24日報:在生物科學領域應用深度學習的當前進展和開放挑戰
[leetcode sword finger offer 28. Symmetric binary tree (simple)]
Introduce structured concurrency and release swift 5.5!
[leetcode refers to offer 27. Image of binary tree (simple)]
一文解决浏览器跨域问题
降级和熔断总结
2022-04-24日报:在生物科学领域应用深度学习的当前进展和开放挑战
MySQL back to table
C list data paging
微服务系统中服务降级
Database experiment VI integrity language experiment
Resolve the "chromedriver executable needs to be in path" error
airbase 初步分析
Thinkphp5 + data large screen display effect
Hystrix断路器开启条件和流程以及默认备选处理
Pyuninstaller package exe cannot find the source code when running, function error oserror: could not get source code