当前位置:网站首页>8 figures | analyze Eureka's first synchronization registry
8 figures | analyze Eureka's first synchronization registry
2022-06-28 07:24:00 【A female programmer who can't write code】
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 .
边栏推荐
- Introduction and several months' experience of extending the solution thanos of Prometheus
- Is it safe to open an account on Dongfang fortune
- 7-1 懂的都懂
- Encyclopedia of scala operators
- A small code editor can also run programs -- a summary of sublime Text3 running programs in various languages
- ABAP 技能树
- ice, protobuf ,thrift -- 笔记
- DBeaver 22.1.1 发布,可视化数据库管理平台
- Jetpack - defects of livedata component and Countermeasures
- vite2.9 中指定路径别名
猜你喜欢

GoLand IDE and delve debug Go programs in kubernetes cluster

MySQL master-slave replication, detailed configuration, create unable to connect processing prompt

LeetCode+ 66 - 70 高精度、二分专题

hack the box:RouterSpace题解

安全培训是员工最大的福利!2022新员工入职安全培训全员篇

ABAP skill tree

【C语言】详解 C 语言获取数组长度

Voice network VQA: make the user's subjective experience of unknown video quality in real-time interaction known

我的MVVM开源项目《出行防疫App》已发布

A gadget can write crawlers faster
随机推荐
Modifying MySQL user name root under Linux
Alibaba cloud server creates snapshots and rolls back disks
[thanos source code analysis series]thanos query component source code analysis
R 语言 Kolmogorov-Smirnov 检验 2 个样本是否遵循相同的分布。
腾讯下半年继续裁员,所有事业群至少缩减 10%,对此你怎么看?关注者
Encyclopedia of scala operators
7-1 懂的都懂
R 语言 ggmap
数字藏品市场“三大套路”
自律挑战30天
My MVVM open source project "travel epidemic prevention app" has been released
东方财富上开户是安全的吗
LeetCode+ 66 - 70 高精度、二分专题
Sword finger offer II 091 Paint the house
MySQL master-slave replication, detailed configuration, create unable to connect processing prompt
R 语言绘制 动画气泡图
全方位透析真实企业软件测试流程
Solving the longest palindrome substring by dynamic programming
Application and Optimization Practice of redis in vivo push platform
实时数据库 - 笔记