当前位置:网站首页>[cloud native] the ribbon is no longer used at the bottom of openfeign, which started in 2020.0.x
[cloud native] the ribbon is no longer used at the bottom of openfeign, which started in 2020.0.x
2022-07-25 07:08:00 【Bald loves fitness】
List of articles
One 、 Preface
In front of Feign Series articles :
- SpringCloud And Feign A detailed case of implementing declarative client load balancing
- SpringCloud And OpenFeign Realize the transfer of request header data between services (OpenFeign Interceptor RequestInterceptor Use )
- SpringCloud And OpenFeign Common configuration of ( Overtime 、 data compression 、 journal )
- SpringCloud And OpenFeign Core components (Encoder、Decoder、Contract)
- SpringBoot Start in the startup process OpenFeign Entrance (ImportBeanDefinitionRegistrar Detailed explanation )
- Source analysis OpenFeign How to scan all FeignClient
- Source analysis OpenFeign How to FeignClient Generate dynamic proxy class
- Analysis of graphic source code OpenFeign Process request
We talked about the following :
- OpenFeign Overview 、 Why are they used Feign Instead of Ribbon?
- Feign and OpenFeign The difference between ?
- The details of the OpenFeign Implement declarative client load balancing cases
- OpenFeign Middle interceptor RequestInterceptor Use
- OpenFeign Some common configurations of ( Overtime 、 data compression 、 Log output )
- SpringCloud And OpenFeign Core components (Encoder、Decoder、Contract)
- stay SpringBoot Start in the startup process OpenFeign Entrance
- OpenFeign How to scan / Register all FeignClient
- OpenFeign How to FeignClient Generate dynamic proxy class
- OpenFeign Process request
This article is based on OpenFeign Higher version (SpringCloud 2020.0.x The version after the beginning of the version ) Discuss :OpenFeign The difference between the new version and the old version ( Higher version OpenFeign The bottom layer does not use Ribbon Load balancing )
PS: This article uses SpringCloud Higher version :
<properties>
<spring-boot.version>2.4.2</spring-boot.version>
<spring-cloud.version>2020.0.1</spring-cloud.version>
<spring-cloud-alibaba.version>2021.1</spring-cloud-alibaba.version>
</properties>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-dependencies</artifactId>
<version>${spring-boot.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
<!-- Integrate spring cloud-->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>${spring-cloud.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
<!-- Integrate spring cloud alibaba-->
<dependency>
<groupId>com.alibaba.cloud</groupId>
<artifactId>spring-cloud-alibaba-dependencies</artifactId>
<version>${spring-cloud-alibaba.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
PS: This article uses SpringCloud Low version :
<properties>
<spring-boot.version>2.3.7.RELEASE</spring-boot.version>
<spring-cloud.version>Hoxton.SR9</spring-cloud.version>
<spring-cloud-alibaba.version>2.2.6.RELEASE</spring-cloud-alibaba.version>
</properties>
Two 、 Differences between source code and main process versions
1、@FeignClientsRegistrar Open to FeignClient Scan
There is no difference in the main process here ;
stay SpringBoot Starting the process @FeignClientsRegistrar Annotations to open OpenFeign Entrance 、OpenFeign Scan all FeignClient The process of The high version is basically the same as the low version , See the article for the lower version :FeignClientsRegistrar Annotations to open OpenFeign Entrance 、OpenFeign Scan all FeignClient.
The main process is as follows :
1> Open the scanning FeignClient Entrance :
- Start the
@EnableFeignClientsThe annotation will pass @Import Annotations in SpringBoot The startup process willImportBeanDefinitionRegistrarImplementation class of interfaceFeignClientsRegistrarInjected into the startup class ConfigurationClass Properties of , Register the startup class BeanDefinition when , Will traverse and call its @Import All of the ImportBeanDefinitionRegistrar Interface registerBeanDefinitions() Method .2> scanning FeignClient:
- Get @EnableFeignClients Attributes related to the scanning package path configured in the annotation , Get the package path to scan ;
- Get the scanner
ClassPathScanningCandidateComponentProvider, Then add an annotation filter to it (AnnotationTypeFilter), Only filter out the contents @FeignClient Annotated BeanDefinition;- Scanner findCandidateComponents(basePackage) Method scan out all annotations from the package path @FeignClient Annotate and conform to the interface of conditional assembly ; Then put it in BeanDefinitionRegistry Sign up for ;
2、 by FeignClient Generate dynamic proxy class
The difference is mainly reflected here ;
Register at FeignClient To Spring When the container , Built BeanDefinition Of beanClas yes FeignClientFactoryBean;FeignClientFactoryBean It's a factory , Save the @FeignClient All attribute values for annotation , stay Spring During container initialization , It will be based on the previously scanned FeignClient Information Architecture FeignClient Dynamic proxy class .
For the specific dynamic proxy class generation process, please refer to the blog :OpenFeign How to FeignClient Generate dynamic proxy class ;
Bottom layer communication Client The difference between ?
In the use of Feign.Builder structure FeignClient When , Acquired Client yes FeignBlockingLoadBalancerClient( The logic will be discussed later , stay OpenFeign The lower version is LoadBalancerFeignClient); Used to generate FeignClient Of Targeter yes DefaultTargeter( stay OpenFeign The lower version is HystrixTargeter, The higher version removed Hystrix, use Spring Cloud Circuit Breaker Make current limiting fuse );
It is embodied in FeignClientFactoryBean#loadBalance() Method , It is a load balancing FeignClient Dynamic proxy generation method ;
OpenFeign Low version :
1> FeignBlockingLoadBalancerClient When to inject into Spring Containers ?
FeignBlockingLoadBalancerClient Injection into Spring The way of containers and OpenFeign Low version of the LoadBalancerFeignClient It's the same ;
Enter into FeignBlockingLoadBalancerClient Class , Look where it calls its only constructor ;

find FeignBlockingLoadBalancerClient It is found that its constructor is called in three places ,new An example is given ;
- DefaultFeignLoadBalancedConfiguration
- HttpClientFeignLoadBalancedConfiguration
- OkHttpFeignLoadBalancedConfiguration
Combined with the default configuration , Only DefaultFeignLoadBalancedConfiguration Medium Client Qualified assembly ;

By introducing Apache HttpClient Of maven Rely on the use of HttpClientFeignLoadBalancedConfiguration,
Or introduce OkHttpClient Of maven Depend on and be in application.yml The document specifies feign.okhttp.enabled The attribute is true Use OkHttpFeignLoadBalancedConfiguration.
2> DefaultTargeter Where to inject Spring Containers ?
DefaultTargeter Injection into Spring The way of containers and OpenFeign Low version of the HystrixTargeter It's the same ;
stay FeignAutoConfiguration Class Targeter Injection into Spring Container logic ;

3> The logic of subsequent generation of dynamic proxy classes is the same as that of the old version
Are reflected in ReflectiveFeign#newInstance() In the method :

3、**Client Load balancing ( The core difference between )
above-mentioned OpenFeign Obtained from the higher version Client yes FeignBlockingLoadBalancerClient, The lower version is LoadBalancerFeignClient,LoadBalancerFeignClient be based on Ribbon Load balancing ,FeignBlockingLoadBalancerClient It depends OpenFeign Realize load balancing by yourself ;
OpenFeign How to deal with a HTTP Request to see the blog : Analysis of graphic source code OpenFeign Process request .
Next, take a look FeignBlockingLoadBalancerClient How to do load balancing !!
1)FeignBlockingLoadBalancerClient Select a service instance

边栏推荐
- Upload and download multiple files using web APIs
- Leetcode 206. reverse linked list I
- GIS实战应用案例100篇(十七)-基于DEM制作三维地图
- Health clock in daily reminder tired? Then let automation help you -- hiflow, application connection automation assistant
- Wechat applet switchtab transmit parameters and receive parameters
- [daily question] sword finger offer II 115. reconstruction sequence
- Rongyun launched a real-time community solution and launched "advanced players" for vertical interest social networking
- Example demonstration of math.random() random function
- 数据提交类型 Request Payload 与 Form Data 的区别总结
- How can dbcontext support the migration of different databases in efcore advanced SaaS system
猜你喜欢

【terminal】x86 Native Tools Command Prompt for VS 2017

knapsack problem

LeetCode46全排列(回溯入门)

RecycleView实现item重叠水平滑动

常吃发酵馒头是否会伤害身体

leetcode刷题:动态规划06(整数拆分)

Luo min's backwater battle in qudian

Boiling short drama Jianghu: nine of the ten production teams are shooting, with a head sharing fund of more than 30million, and users are addicted to paying routines

C # --metroframework framework calls the metromodernui library and uses it in the toolbar

阿里云镜像地址&网易云镜像
随机推荐
Kubernates-1.24.2 (latest version) + containerd + nexus
Devops has been practiced for many years. What is the most painful thing?
Statistical learning -- naive Bayesian method
How can dbcontext support the migration of different databases in efcore advanced SaaS system
[yolov5 practice 3] traffic sign recognition system based on yolov5 - model training
【SemiDrive源码分析】【驱动BringUp】39 - Touch Panel 触摸屏调试
[OBS] DTS sent by video packet_ USEC calculation
EFCore高级Saas系统下单DbContext如何支持不同数据库的迁移
Software engineering in Code: regular expression ten step clearance
章鱼网络 Community Call #1|开启 Octopus DAO 构建
In container multicast
Vscode saves setting configuration parameters to the difference between users and workspaces
[Yugong series] July 2022 go teaching course 016 logical operators and other operators of operators
YOLOv7模型推理和训练自己的数据集
Leetcode 115. different subsequences
Talk about practice, do solid work, and become practical: tour the digitalized land of China
100 GIS practical application cases (seventeen) - making 3D map based on DEM
Mathematics Olympiad vs Informatics Olympiad (July 19, 2022)
Rambus announces ddr5 memory interface chip portfolio for data centers and PCs
Builder pattern