Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What is the implementation principle of Feign?

2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/02 Report--

This article introduces you what is the principle of Feign implementation, the content is very detailed, interested friends can refer to, hope to be helpful to you.

What is Feign?

Feign is an open source project for java that binds to http clients. The main goal of Feign is to make the Java Http client simple. Source address of Feign: https://github.com/OpenFeign/feign

How Feign works

Feign is a pseudo client, that is, it does not do any request processing. Feign simplifies HTTP API development by processing annotations to generate request, that is, developers can customize request api templates by annotations. Before sending http request requests, feign replaces parameters in request templates by processing annotations, which seems more direct and understandable.

Summary

To sum up, the source code implementation of Feign is as follows:

First open FeignCleint through the @ EnableFeignCleints annotation

Implement the interface according to the rules of Feign and annotate @ FeignCleint

After the program starts, a package scan is performed, scanning all @ FeignCleint annotated classes, and injecting this information into the ioc container.

When the method of the interface is called, the concrete RequesTemplate is generated through the proxy of jdk.

RequesTemplate is generating Request

Request is left to Client to handle, where Client can be HttpUrlConnection, HttpClient or Okhttp

Finally, Client is encapsulated into the LoadBalanceClient class, which combines with the class Ribbon to achieve load balancing.

What is the implementation principle of Feign is shared here, I hope that the above content can be of some help to you, can learn more knowledge. If you think the article is good, you can share it for more people to see.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report