当前位置:网站首页>Microservice system design - service fusing and degradation design
Microservice system design - service fusing and degradation design
2022-06-27 04:21:00 【Zhuangxiaoyan】
Abstract
OpenFeign The call between microservices is completed , And in the case of multi instance clusters , Adjust the load policy to deal with concurrent calls . Network product development , The network may sometimes be unavailable , The service may also be unavailable , When the calling service is slow or unavailable , A large backlog of requests , Will be the last straw to overwhelm the camel of the system .
One 、Hystrix Principle
It is the basic component of a low delay fault tolerance mechanism provided by distributed systems , Provide current limiting 、 service degradation 、 System fuse protection 、 Fast failure and other dimensions to ensure the stability of micro services .Hystrix It's also Netflix Part of the kit .
Unfortunately 1.5.18 After the release, it entered maintenance mode , Officials offer alternatives :resilience4j , This test uses Hystrix ultimate , If you need a higher version , It is suggested that resilience4j , I won't give you too much introduction here , It will be replaced by another important component ——Sentinel To replace Hystrix.
1.1 introduce Hystrix
use starter Way to introduce
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-hystrix</artifactId>
</dependency>feignClient The function of circuit breaker has been integrated by default in , But it needs to be opened in the configuration file , Ability to open . stay application.properties Open in hystrix switch :
#hystrix enable
feign.hystrix.enabled=trueGo back to the previous FeignClient Code , Add... In comments fallback Property value , Add corresponding fallback Calling class .
@FeignClient(value = "card-service", fallback = MemberCardServiceFallback.class)
public interface MemberCardClient {
@RequestMapping(value = "/card/addCard", method = RequestMethod.POST)
public CommonResult<Integer> addCard(@RequestParam(value = "json") String json) throws BusinessException;
@RequestMapping(value = "/card/updateCard", method = RequestMethod.POST)
public CommonResult<Integer> updateCard(@RequestParam(value = "json") String json) throws BusinessException;
}To write MemberCardServiceFallback Method , Is a common service implementation class , increase @Component annotation .
@Component
@Slf4j
public class MemberCardServiceFallback implements MemberCardClient {
@Override
public CommonResult<Integer> addCard(String json) throws BusinessException {
CommonResult<Integer> result = new CommonResult<>("parking-card service not available! ");
log.warn("parking-card service not available! ");
return result;
}
@Override
public CommonResult<Integer> updateCard(String json) throws BusinessException {
CommonResult<Integer> result = new CommonResult<>("parking-card service not available! ");
log.warn("parking-card service not available! ");
return result;
}
}1.2 test Hystrix
The function has been completed according to the normal process in the previous chapter : After the member opens , Integral generation , There will be no startup " Points sub service ", See what the effect will be .( The default service registry has been started , It will not be specifically mentioned here and in the subsequent demonstrations )
- Start only parking-member A sub service
- open parking-member Sub service swagger-ui Interface , Call the member binding mobile number interface ( Or adopt PostMan Tools )
Under normal circumstances, it will directly call fallback Interface , Fast failure , Response caller . At this point, the integration module service will be started , Call again , In the correct case, it is no longer called fallback Method , Instead, the integration service interface is called normally , Shown below :

1.3 Graphical monitoring Hystrix
Through the above application , We can already Hystrix Normal integration into the function development process , But after all Hystrix What is the real-time running status ? Is there any way to see Hystrix The indicators of ? Here we introduce Hystrix Dashboard ( The dashboard ), adopt UI The way , Check the health status quickly .
Add instrument panel table item : We are parking-base-serv Under the project , Create a new one called parking-hystrix-dashboard Spring Boot Sub project , It's for you Hystrix Instrument cluster monitoring . modify pom.xml file , Add dependencies :
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-hystrix-dashboard</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>Add... In the project startup class @EnableHystrixDashboard annotation , Turn on the instrument cluster function
@SpringBootApplication
@EnableDiscoveryClient
@EnableHystrixDashboard
public class ParkingHystrixDashboardApplication {
public static void main(String[] args) {
SpringApplication.run(ParkingHystrixDashboardApplication.class, args);
}
}Start project , Open the address :http://localhost:10093/hystrix, The following interface appears to indicate normal operation .

Adjust the monitored items : In the member service, in the process of calling the points service interface , use Feign To initiate a remote call , At the same time fallback service degradation 、 Fast fail function , The main objective of this monitoring is this function . stay parking-member project config Code package , increase Hystrix Configuration of data flow :
@Configuration
public class HystrixConfig {
@Bean
public ServletRegistrationBean<HystrixMetricsStreamServlet> getServlet() {
HystrixMetricsStreamServlet servlet = new HystrixMetricsStreamServlet();
ServletRegistrationBean<HystrixMetricsStreamServlet> bean = new ServletRegistrationBean<>(servlet);
bean.addUrlMappings("/hystrix.stream");
bean.setName("HystrixMetricsStreamServlet");
return bean;
}
}After starting , Open the Hystrix Data acquisition address :http://localhost:10060/hystrix.stream, The initial state , The page will keep outputting ping The case of null value , Only use Hystrix When relevant functions are requested , To output data normally JSON Format data , As shown in the screenshot :

The output of the above figure is not friendly , There is no way to intuitively analyze Hystrix Application of components , At this point, our dashboard project comes in handy .
Dashboard interpretation : Address http://localhost:10060/hystrix.stream Input to dashboard The data in the page is captured in the address bar ,Delay Items can have default values ,Titile Items can be given a new name , So that we can identify . alike , Related functions have only been performed , The instrument cluster can display normally , The following figure shows that the points service is not started , The direct invocation of member services leads to all failures .

Two 、sentinel Principle
Blog reference
边栏推荐
- Fastdds server records - Translation-
- 笔记本电脑没有WiFi选项 解决办法
- 017 C语言基础:位域和typedef
- ERP demand and sales management Kingdee
- 【B站UP DR_CAN学习笔记】Kalman滤波3
- Knowledge of iPhone certificate structure
- 轨道姿态常用编程缩写
- In a sense, the Internet has become an incubator and a parent
- Further exploration of handler (I) (the most complete analysis of the core principle of handler)
- 实践 DevOps 时,可能面临的六大挑战
猜你喜欢
![[array]bm94 rainwater connection problem - difficult](/img/2b/1934803060d65ea9139ec489a2c5f5.png)
[array]bm94 rainwater connection problem - difficult

日志收集系統

Kotlin Compose compositionLocalOf 与 staticCompositionLocalOf
![Promise [II. Promise source code] [detailed code comments / complete test cases]](/img/ac/abf3181fa7b3345efcc9abc046cea5.png)
Promise [II. Promise source code] [detailed code comments / complete test cases]
![[BJDCTF2020]The mystery of ip](/img/f8/c3a7334252724635d42c8db3d1bbb0.png)
[BJDCTF2020]The mystery of ip

MobileNet系列(4):MobileNetv3网络详解

Nignx configuring single IP current limiting

Cultural tourism light show breaks the time and space constraints and shows the charm of night tour in the scenic spot
![[BJDCTF2020]The mystery of ip](/img/f8/c3a7334252724635d42c8db3d1bbb0.png)
[BJDCTF2020]The mystery of ip

Fplan powerplan instance
随机推荐
Matlab | drawing of three ordinate diagram based on block diagram layout
跟着BUU学习Crypto(周更)
Resnet152 pepper pest image recognition 1.0
006 C语言基础:C存储类
math_ Number set (number set symbol) and set theory
低代码开发平台NocoBase的安装
008 C语言基础:C判断
USB DRIVER
Système de collecte des journaux
016 C语言基础:C语言枚举类型
DAST 黑盒漏洞扫描器 第六篇:运营篇(终)
Network structure and model principle of convolutional neural network (CNN)
015 C语言基础:C结构体、共用体
【B站UP DR_CAN学习笔记】Kalman滤波3
Fplan layout
fplan-电源规划
Common sense of Apple's unique map architecture
JMeter takes the result of the previous request as the parameter of the next request
渗透测试-目录遍历漏洞
手撸promise【二、Promise源码】【代码详细注释/测试案例完整】