当前位置:网站首页>Automatic assembly and fuse degradation of feign
Automatic assembly and fuse degradation of feign
2022-07-25 21:38:00 【Xiaobai wants to become a big cow】
Use steps
The first step is to import feign rely on
<!-- Spring Cloud Microservice load balancing -->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-ribbon</artifactId>
</dependency>
<!-- Spring Cloud Microservice remote call -->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-openfeign</artifactId>
</dependency>
<!--sentinel-->
<dependency>
<groupId>com.alibaba.cloud</groupId>
<artifactId>spring-cloud-starter-alibaba-sentinel</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-validation</artifactId>
</dependency>The second step is to configure feign
# Turn on feign The remote call of uses fusing
feign.sentinel.enabled = true
# Configuration request GZIP Compress
feign.compression.request.enabled = true
# Configure the minimum compressed data size
feign.compression.request.min-request-size = 2048
# Configure response GZIP Compress
feign.compression.response.enabled = true
# Configure compression support MIME TYPE
feign.compression.request.mime-types[0] = text/xml
feign.compression.request.mime-types[1] = application/xml
feign.compression.request.mime-types[2] = application/json
# Below is the setting feign Call yes, timeout, etc , Prevent avalanche
# Number of retries to the current instance default 0
ribbon.MaxAutoRetries = 1
# Set connection timeout default 2000
ribbon.ConnectTimeout = 3000
# Retry all operation requests default false
ribbon.OkToRetryOnAllOperations = false
# Set read timeout default 5000
ribbon.ReadTimeout = 20000
# Number of retries to switch instances default 1
ribbon.MaxAutoRetriesNextServer = 1The third step ( utilize spring Of SPI): stay resource Created in META-INF, also META-INF Created in spring.factories
org.springframework.boot.autoconfigure.EnableAutoConfiguration=com.xuecheng.api.feign.config.FeignConfigMy waiting right points to mine feign Configuration class , such Spring When it starts , I will scan first resource.META-INF.spring.factories file , Scan the files pointed to inside ,
@Configuration
@ComponentScan(basePackages = {"com.xuecheng.api.feign"}) // This is to scan the path and add IOC Class in
@EnableFeignClients(basePackages = {"com.xuecheng.api.feign"}) // This is used to scan the path feign Give the annotated package to ioc management
public class FeignConfig {
}such spring Will be based on spring.factories Found the path specified in FeignConfig, By scanning FeignConfig See there are
@EnableFeignClients(basePackages = {"com.xuecheng.api.feign"}) // This is used to scan the path feign Give the annotated package to ioc management annotation , Will scan com.xuecheng.api.feign Under the use of Feign Related annotation class .
But if fuse is configured , But fusing is not used feign Relevant comments, so the above @EnableFeignClients It will not scan the package that is not used feign Related notes , Then you need to be in FeignConfig Add annotation to
@ComponentScan(basePackages = {"com.xuecheng.api.feign"}) // This is to scan the path and add IOC Class in Put all under this path @Componen Derived needs to be connected to IOC The class of the container is handed over to Spring management , And the fuse class is just under this path , That's it Feign Automatic assembly of
technological process :Spring start-up --------> Scan all in the project resource.META-INF.spring.factories Content ------> Find the specified FeignConfig class ---------------> adopt FeignConfig Annotations configured in @EnableFeignClients scanning feignj All uses under the package where the interface is located Feign Related annotation class , Add to IOC in ------------> If there is a fuse , adopt @ComponentScan Scan under the package where the fuse class is located All use @Componen And classes derived from annotations are added to IOC in .
So that's the end of it feign Integrated into the Spring in
边栏推荐
- Zero basic learning canoe panel (17) -- panel CAPL function
- Web3 entrepreneurship has all the elements of explosive growth of innovation
- Advanced technology management - how can the team be broken?
- Programmer's Guide to health quenching 5: introduction to sports Basics
- [MAIXPY]kpu: load error:2005, ERR_READ_FILE: read file failed问题解决
- Handwriting distributed configuration center (1)
- Fastjson deserialization vulnerability utilization analysis collection
- 零基础学习CANoe Panel(17)—— Panel CAPL Function
- ONEFLOW V0.8.0 officially released
- 人脸与关键点检测:YOLO5Face实战
猜你喜欢

IJCAI2022开会了! 微软等《领域泛化Domain Generalization》教程

ag 搜索工具参数详解

【Redis底层解析】链表类型
![[ManageEngine] value brought by Siem to enterprises](/img/1e/56d64d193e0428523418bef5e98866.png)
[ManageEngine] value brought by Siem to enterprises

CNN structural design skills: taking into account speed accuracy and engineering implementation

浅谈web性能优化(一)

Web3 entrepreneurship has all the elements of explosive growth of innovation

字节一面:TCP 和 UDP 可以使用同一个端口吗?

ORIGYN基金会正式启动$OGY Staking,引领新一轮生态利好

ONEFLOW V0.8.0 officially released
随机推荐
All non isomorphic subgraphs of a directed complete graph of order 3 (number of different hook graphs)
Optimization analysis of storage structure and IO performance of openharmony littlefs file system
Experience sharing of system architecture designers preparing for the exam: from point to surface
Apple estimates that iPhone will give up the Chinese market, and the Chinese industrial chain needs to consider living a hard life
Redis configuration
立创EDA——我为什么要学EDA
Research: more than 70% of doctors are still prescribing unsafe antibiotic drugs
ONEFLOW V0.8.0 officially released
Byte side: can TCP and UDP use the same port?
NVIDIA has opened source a comprehensive library of 3D deep learning based on pytorch
接口测试工具 restlet client
Database SQL statement exercise "suggestions collection"
Please give an example of how to optimize MySQL index (sqlserver index optimization)
yuv422转rgb(422sp转420p)
如何用 Redis 实现分布式锁的?
Stm3 (cubeide) lighting experiment
C#常见的集合
An interview question about recover in golang
I live far away. Is there a good way to open an account? Is it safe to open a stock account by mobile phone?
On Web Performance Optimization (1)