当前位置:网站首页>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.
边栏推荐
- 聊聊消息队列高性能的秘密——零拷贝技术
- 队列管理器running状态下无法查看通道
- commands out of sync. did you run multiple statements at once
- Jd.com interviewer asked: what is the difference between using on or where in the left join association table and conditions
- Win10 uses docker to pull the redis image and reports an error read only file system: unknown
- 长篇总结(代码有注释)数构(C语言)——第四章、串(上)
- Oracle related statistics
- Qt——如何在QWidget中设置阴影效果
- 以字节跳动内部 Data Catalog 架构升级为例聊业务系统的性能优化
- 远程连接IBM MQ报错AMQ4036解决方法
猜你喜欢

WSL installation, beautification, network agent and remote development

机器学习实战:《美人鱼》属于爱情片还是动作片?KNN揭晓答案

队列管理器running状态下无法查看通道

Introduction to the basic concept of queue and typical application examples

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

Complete solution of servlet: inheritance relationship, life cycle, container, request forwarding and redirection, etc

C#钉钉开发:取得所有员工通讯录和发送工作通知

微服务实战|负载均衡组件及源码分析

History of Web Technology

将一串数字顺序后移
随机推荐
Cloudrev self built cloud disk practice, I said that no one can limit my capacity and speed
Programmers with ten years of development experience tell you, what core competitiveness do you lack?
盘点典型错误之TypeError: X() got multiple values for argument ‘Y‘
gocv opencv exit status 3221225785
Introduction to the basic concept of queue and typical application examples
Jd.com interviewer asked: what is the difference between using on or where in the left join association table and conditions
Openshift container platform community okd 4.10.0 deployment
The channel cannot be viewed when the queue manager is running
【Go实战基础】gin 如何获取 GET 和 POST 的请求参数
Gocv boundary fill
Cartoon rendering - average normal stroke
长篇总结(代码有注释)数构(C语言)——第四章、串(上)
随笔:RGB图像颜色分离(附代码)
【Go实战基础】gin 如何验证请求参数
Redis zadd导致的一次线上问题排查和处理
Flink-使用流批一体API统计单词数量
Taking the upgrade of ByteDance internal data catalog architecture as an example, talk about the performance optimization of business system
C Baidu map, Gaode map, Google map (GPS) longitude and latitude conversion
Qt的右键菜单
Multi version concurrency control mvcc of MySQL