Do not “intermittently complacent, continue to eat and die” live into a habit

1. What do you mean by this passage? 2 Framework (familiar but unfamiliar Contoller)3.Google’s Guava framework (melon child)4.HTTP communication 5

First, why write this article

Because the company uses SpringCloud, I tried to read the source code in my spare time to understand the underlying working principle of SpringCloud. I recall reading various blogs at that time, a lot of breakpoints and code, often made my head big.

Now in retrospect, no direction of random source, although there will be a harvest, but the efficiency is not high.

With this in mind, I thought of writing an article on the basics of reading the source code for Springcloud that I hope will inspire you.

Two, basic knowledge

1. Find the root of the code

The Eureka project we usually use is a sub-project of the Spring Cloud Netflix project, which is the encapsulation of Netflix OSS components. Netflix has an open source package of distributed service framework components, and their project address is github.com/Netflix

In other words, the core functionality is at the root.

2.Jersey Frame (Familiar yet unfamiliar Contoller)

Springcloud is a typical Servlet application. The server interacts with the client through Restful interfaces.

The interaction between EurekaSever and EurekaClient is similar to that between my usual systems. We have written so many controllers that it should be clear how business systems interact with each other through interfaces.

Different from the code we are familiar with:

  • We’re going to useSpringMVCFrame, it saysController.
  • EurekaUsing aJerseyThe framework,JerseyThe controller-like component in the framework is calledApplicationResourceConcept.

Interface package:

  • We usually define an xxx.controller package that holds our interface
  • Eureka has a resources package that houses the external interface of EurekaServercom.netflix.eureka.resourcesThe package.
Similar to business system entry

Interfaces: What are interfaces?

As mentioned above, Eureka’s roots are in github.com/Netflix/eur…

So from its wiki documentation, you’ll see a directory like eureka-rest-operations,

That’s basically all of EurekaServer’s APIS right there. A few more are listed here in the project Wiki documentation

operation interface instructions
Registered instance POST /eureka/v2/apps/appID Data format JSON/XML Registration success Code: 204 on success
Delete the instance DELETE /eureka/v2/apps/appID/instanceID HTTP Code: 200 on success

The XML data format is also aptly presented in the document

Insert a picture description here

Take registering an interface: you simply start the EurekaSever service and register an instance by invoking the interface through the PostMan tool.

Just like the Controller interface in our business-oriented system, what you see along the interface under this package is the entrance to the whole business. I think that’s the way we’re most familiar with it

3.Google’s Guava Framework

Many of the tools used in Eureka come from Google’s Guava project.

Such as:

  • Caches: Many of the caches used in Eureka are built using Google’s Guava cache.

4. HTTP communication

Communication protocol between EurekaSever and EurekaClient is HTTP.

Our usual Resttemplate initiates a Post/GET request.

EurekaClient uses an HTTP tool called EurekaTransport to communicate with EurekaSever.

Strange and familiar correspondence

5. Design ideas of EurekaServer

  • Read/write separation (cache hierarchy) : This is what comes to mind when frequent reads and writes occur. EurekaSever does the same
  • Time to refresh
  • Timed out
  • STW

6. InstanceInfo domain values (DTO)

The basic unit of communication between EurekaSever and EurekaClient is InstanceInfo.

The client assembles an InstanceInfo that represents its own information, registers it with EurekaSever, and EurekaSever caches the InstanceInfo.

Just like the concept of Dtos in our multi-system. In fact, the technical term is better called the domain value.

Third, summary

I wonder if you’ve seen the familiar business system from the Eureka client and server

With this in mind, you can pick up your PostMan tool, use the official data structure, and start debugging the EurekaSever,EurekaClient source code tour.

What is common between frameworks is often understood at the beginning and then read, which will result in twice the result with half the effort.


If there are any mistakes in this article, please comment, appreciate! If you think the article is good, give it a thumbs up

Welcome to add my wechat, pull you into the partnership, talk about the source code

Insert a picture description here