“This is the first day of my participation in the First Challenge 2022. For details: First Challenge 2022”

Hello everyone, I am Wukong.

Last time we looked at the Ribbon in depth, this time we’ll take a look at Feign remote calls.

Understand remote calls

What about remote calls?

Remote calls are relative to local calls, so let’s talk about local calls first. Local calls are methods A in the same Service that call method B.

A remote call is a method call between different services. For service-level method invocations, we construct the request URL and request parameters ourselves to initiate remote invocations.

Call between services, we are based on HTTP protocol, commonly used remote service framework has OKHttp3, Netty, HttpURLConnection and so on. The call flow is as follows:

But the process of constructing requests in dotted boxes is tedious. Is there an easier way?

Feign is here to simplify the code we use to make remote calls, but to what extent? Simplifying achievements is as simple as calling local methods.

Code similar to remote calls in my open source project PassJava:

/ / remote calls to the user's learning time R memberStudyTimeList = studyTimeFeignService. GetMemberStudyTimeListTest (id);Copy the code

Feign is a very important component in the Spring Cloud microservice stack. If you were to design this microservice component, how would you design it?

Here are a few factors to consider:

  • How can I make a remote call as simple as a local method call? (Packet scanning + dynamic proxy)
  • How did Feign find the address of the remote service?
  • How does Feign do load balancing? (How Feign works with Ribbon)

Let’s take a look at Feign’s design philosophy around these core issues.

Will be divided into several detailed explanation, pay attention to me, continue to update.