当前位置:网站首页>8 figures | analyze Eureka's first synchronization registry
8 figures | analyze Eureka's first synchronization registry
2022-07-01 06:42:00 【Microservice mall technology sharing】
The registry is particularly important for the registry , All functions are expanded around this registry . Services such as A To access the service B, You have to know the service B Of IP Address and port number . As shown in the figure below , The traditional way is to serve A I see. Service B After the address of , send out HTTP Request to the corresponding API Address .

That service A and service B The information is actually placed in the registry of the Registration Center , The registration center manages the registration of all services 、 Offline . service A and service B Want to get registration information , Unified access to the registry , Get the registry , I know the of other services IP Address And port number .

Last time , Let's talk about a Eureka Client Successfully registered to Eureka Server after ,Eureka Server Will save the registry information in a ConcurrentHashMap in .
that Client How to get other customer registration information ?

Two 、 Get registration information for the first time
First of all, let's think about , service B Sent the registration request to the Registration Center , That service A You have to get the registry , service A There must have been no registry information at the beginning , Then you must get the registration center to pull all the registration forms .( Service here A Also known as Eureka client )
service A For the registry , Namely
to see somebody for the first time, service A Want to putallSave a copy of the registration information in your own place , Convenient for follow-up API call .
Next, let's analyze how the client obtains the full registry from the perspective of source code .
The client sends a request to get
Client When initializing , It will start from Eureka Get the full registry from the registry :

The first time to obtain registration information is to use it in DiscoveryClient Obtained during initialization . We can find the following judgment from the source code :
if (clientConfig.shouldFetchRegistry() && !fetchRegistry(false)) {
fetchRegistryFromBackup();
}
The meaning of this code is shown in the figure :

First, it depends on whether it is configured shouldFetchRegistry, If the , It will call fetchRegistry Method to get the registry .
Because it's new client, So there must be no registration information , So local variables applications = null. Then judge whether it is necessary to obtain the full registry according to several conditions , If one of the conditions is met, the full amount of :

- Conditions for a : Whether to force full access . Transmitted false, You don't need a full amount .
- Condition 2 : Whether the registry information is empty .application == null, It's empty , Need full access to .
- Condition 3 : Get registered client Whether the number of is equal to 0. Yes , Need full access to .
Because of satisfaction applications=null, So you need to get the full amount .
Method for obtaining full registration information :
getAndStoreFullRegistry()
In this, you will send the following HTTP Request calling jersey Of restful Interface :
getApplications()
then Eureka Server Deal with this http The requested class is here :ApplicationsResource Class getContainers Method . This method will be used to get Server Over there .
3、 ... and 、Server Side of the registry cache
Server The client will put the registry into the cache , Reading the registry is actually read from the cache .
There are two levels of cache , A read-only cache readOnlyCacheMap And read-write cache readOnlyCacheMap.
As shown in the figure below :

The read logic of the cache is as follows :
Jersey Servlet Handle HTTP request .
First, the default will start from read-only Find it in the cache .
If not , Again from Reading and writing Find it in the cache .
If you find it, update it read-only cache , And return the found cache .
If you can't find it yet , Return empty .

Leave a few questions , Put it in the cache architecture article :
(1) How did the two-level cache data come from ?
(2) How cache data is updated ?
(3) How the cache expires ?
then ,Eureka Client After getting the registry information , It will be saved locally localRegionApps variable . such Client There will be a copy of Server The registry information of .
localRegionApps.set(this.filterAndShuffle(apps));
Four 、 summary
Registry, whether for Client still Server Come on , It's all very important :
- about Server End to speak , In order to better provide the service of querying the registry , Multi level cache is used to cache registry information .
- about Client End to speak , When the registry is obtained for the first time, it will grab the registry in full , Have their own local .
边栏推荐
- 概率论学习笔记
- Insufficient free space after clearing expired cache entries - consider increasing the maximum cache space
- 记一次线上接口慢查询问题排查
- SQL学习笔记九种连接2
- MySQL learning
- The code generator has eliminated the styling of xxxx js as it exceeds the max of 500kb
- 问题解决:OfficeException: failed to start and connect(一)
- 考研目录链接
- 常用快捷键
- Postgraduate entrance examination directory link
猜你喜欢

产品学习(三)——需求列表
![[unity shader custom material panel part II]](/img/d1/8632ae680299a27b7431b2d6e03fd3.png)
[unity shader custom material panel part II]

Esp32 esp-idf GPIO key interrupt response

Esp32 esp-idf ADC monitors battery voltage (with correction)

Jena default inference query based on OWL

树莓派4的WiFi设置

ESP32 - ULP 协处理器在低功耗模式下读片内霍尔传感器HALL SENSOR

8 张图 | 剖析 Eureka 的首次同步注册表

ESP32 ESP-IDF GPIO按键中断响应
![[wechat applet low code development] second, resolve the code composition of the applet in practice](/img/ab/28ab01db84b1437220e659118b2871.png)
[wechat applet low code development] second, resolve the code composition of the applet in practice
随机推荐
Storage function learning notes
MySQL learning
【Unity Shader 描边效果_案例分享第一篇】
NOC 设计的一些坑
The code generator has eliminated the styling of xxxx js as it exceeds the max of 500kb
Rotate the animation component around the circle, take it and use it directly
Promise
[unity shader custom material panel part II]
根据输入画有向图
Esp32 esp-idf GPIO key interrupt response
Which securities company does qiniu school cooperate with? Is it safe to open an account?
C language course set up library information management system (big homework)
SQL statement
Database notes
Detailed steps for installing redis on Windows system
MySQL data type learning notes
【微信小程序低代码开发】二,在实操中化解小程序的代码组成
Postgraduate entrance examination directory link
Is fixed investment fund a high-risk product?
Notes on probability theory