当前位置:网站首页>Microservice practice | fuse hytrix initial experience
Microservice practice | fuse hytrix initial experience
2022-07-02 09:11:00 【_ Time boiled the rain】
What is? Hystrix
In daily electricity consumption , If the fuse is correctly placed in our circuit , Then when the voltage rises abnormally , The fuse will blow to cut off the current , So as to protect the safe operation of the circuit .
In the cargo ship , In order to prevent the spread of water leakage and fire , Generally, the warehouse will be divided , To avoid the tragedy of a warehouse accident leading to the sinking of the whole ship , This is the bulkhead protection mechanism .
Hystrix The fuse provided is similar , When calling a service provider , When the total number of requests exceeds the configured threshold in a certain period of time , And the error rate is too high in the window period , that Hystrix The call request will be fused , Subsequent requests are short circuited directly , Enter degradation logic , And implement the local degradation strategy .
meanwhile Hystrix It also isolates the service providers in the system , A service provider delays too much or fails , It doesn't lead to the failure of the whole system , At the same time, it can also control the concurrency of calling these services .
All in all ,Hystrix Can disable your system in the event of a dependency service failure , By isolating the services on which the system depends , Prevent service cascading failure , It also provides a failback mechanism , Deal with failures more gracefully , And enable your system to recover from exceptions more quickly .
Hystrix actual combat
Then, in our last article dms service , Make the following changes :
Feign Support by itself Hystrix, There is no need to introduce additional dependencies .
1、 First modify the caller app The configuration file for the service application.xml, Turn on hystrix
feign:
hystrix:
enabled: true
2、 Add service fuse processing , Realization DmsApi Interface
/** * @Author: official account : The programmer 965 * @create 2022-06-26 **/
@Component
public class DmsHystrixImpl implements DmsApi {
@Override
public String findNameByCode(String code) {
return " Server failure ";
}
}
3、 Modify the interface class annotation , Add fusing treatment :fallback = DmsHystrixImpl.class;
(Spring Cloud Feign HTTP Request exception Fallback Fault tolerance mechanism , It is based on Hystrix Realized , So you need to configure parameters feign.hystrix.enabled=true Enable this function )
/** * @Author: official account : The programmer 965 * @create 2022-06-20 **/
@FeignClient(value = "dms",fallback = DmsHystrixImpl.class)
public interface DmsApi {
@RequestMapping(value="/dict/{code}", method = RequestMethod.GET)
public String findNameByCode(@PathVariable("code") String code);
}
4、 Add exception code , In order to verify
/** * @Author: official account : The programmer 965 * @create 2022-06-20 **/
@RestController
public class DmsController implements DmsApi {
@Override
public String findNameByCode(String code) {
Integer.parseInt("a");
switch (code){
case "0" :
return " male ";
case "1" :
return " Woman ";
default:
return " Unknown ";
}
}
}
5、 Start project , To verify , Return the correct result .
summary
In the microservices architecture , There are usually multiple services calling each other , A failure of the underlying service can lead to cascading failures , And then the whole system is not available , This phenomenon is called service avalanche effect . The service avalanche effect is a result of “ Service providers ” The unavailability of “ Serving consumers ” Not available , And will not be available for gradual amplification of the process .
Such as :A As a service provider ,B by A Service consumers ,C and D yes B Service consumers .A Unavailability caused B Not available , And enlarge the unavailable as snowball to C and D when , The avalanche effect is formed . In order to avoid the formation of avalanche effect , You need to use Hystrix.
边栏推荐
- 选择排序和插入排序
- C Gaode map obtains the address according to longitude and latitude
- 我服了,MySQL表500W行,居然有人不做分区?
- Programmers with ten years of development experience tell you, what core competitiveness do you lack?
- oracle修改数据库字符集
- Shengshihaotong and Guoao (Shenzhen) new energy Co., Ltd. build the charging pile industry chain
- Find the node with the smallest value range in the linked list and move it to the front of the linked list
- Qt——如何在QWidget中设置阴影效果
- Mysql安装时mysqld.exe报`应用程序无法正常启动(0xc000007b)`
- C Baidu map, Gaode map, Google map (GPS) longitude and latitude conversion
猜你喜欢

Minecraft module service opening

微服务实战|手把手教你开发负载均衡组件

Move a string of numbers backward in sequence

WSL installation, beautification, network agent and remote development
![[go practical basis] how to verify request parameters in gin](/img/de/50db131d6993e5d955e3416c667c4c.png)
[go practical basis] how to verify request parameters in gin

数构(C语言)——第四章、矩阵的压缩存储(下)

Avoid breaking changes caused by modifying constructor input parameters
![[go practical basis] how can gin get the request parameters of get and post](/img/fd/66074d157d93bcf20a5d3b37da9b3e.png)
[go practical basis] how can gin get the request parameters of get and post

一篇详解带你再次重现《统计学习方法》——第二章、感知机模型

MYSQL安装出现问题(The service already exists)
随机推荐
gocv opencv exit status 3221225785
C language - Blue Bridge Cup - 7 segment code
Finishing the interview essentials of secsha system!!!
Mirror protocol of synthetic asset track
Image transformation, transpose
Loadbalancer dynamically refreshes Nacos server
【Go实战基础】gin 如何设置路由
聊聊消息队列高性能的秘密——零拷贝技术
Qt QTimer类
[staff] the lines and spaces of the staff (the nth line and the nth space in the staff | the plus N line and the plus N space on the staff | the plus N line and the plus N space below the staff | the
Taking the upgrade of ByteDance internal data catalog architecture as an example, talk about the performance optimization of business system
Multi version concurrency control mvcc of MySQL
Servlet全解:继承关系、生命周期、容器和请求转发与重定向等
十年开发经验的程序员告诉你,你还缺少哪些核心竞争力?
Cloudrev self built cloud disk practice, I said that no one can limit my capacity and speed
Dix ans d'expérience dans le développement de programmeurs vous disent quelles compétences de base vous manquez encore?
Solution and analysis of Hanoi Tower problem
概率还不会的快看过来《统计学习方法》——第四章、朴素贝叶斯法
Gocv image reading and display
Programmers with ten years of development experience tell you, what core competitiveness do you lack?