当前位置:网站首页>Microservice registration and discovery
Microservice registration and discovery
2022-07-06 02:41:00 【Rainy night】
Multi service communication under micro service architecture , One problem that needs to be solved is how to realize service discovery . This article will start with why service discovery is needed 、 What is service discovery 、 How to realize service discovery is briefly introduced in four aspects .
Why service discovery is needed
When calling between services , One service needs to know the network location of another service (IP Address and port ). Applications running on physical hardware , The network location of the service instance is usually static . But in the cloud age , It's usually not that simple . In cloud based service instances , Its network location is more dynamic . An example is shown below : 
Pictured above is an example , When creating service instances based on cloud , Service instances have dynamically allocated IP Address . Because service instances can be created or destroyed at any time , Therefore, a service instance cannot occupy a fixed IP, Instead, a random one is used every time a service is created IP, Recycle this when the service is destroyed IP.
What is service discovery
The service caller cannot configure IP Address to access the service provider interface . contrary , Applications or infrastructures need to provide dynamic service discovery mechanisms . Service discovery is conceptually very simple : The key component of service discovery is the service registry , It is a database containing the network location information of service instances .
When the service instance starts or stops , The service discovery mechanism updates the service registry . When the client calls the server , The service discovery mechanism will query the service registry , To get a list of available service instances , And route the request to one of the service instances . Careful students can find out , This principle is similar to DNS similar . Actually , The principle of service discovery is to learn DNS Principle realization .
How to implement service discovery
There are two main ways to implement service discovery :
(1) Service callers and service providers interact directly with the service registry , That is, the application layer service discovery pattern .
(2) Handle service discovery by deploying infrastructure , That is, the platform layer service discovery pattern .
Application layer service discovery pattern
One way to realize service discovery is that service callers and service providers interact directly with the service registry . The service provider registers its network location using the service registry . The service caller first calls the service by querying the service registry to obtain the list of service instances , Then send a request to one of the instances . Examples are as follows :
It can be seen from the figure above , When initializing the service instance , Will call registration API Register its network location with the service registry . in addition , The service registry may also require service instances to call periodically heartbeat API To prevent its registration from expiring . When the service caller needs to call the service interface , It queries the service registry for a list of service instances . Then the service caller uses Load balancing algorithm To select a service instance . Then it sends a request to the selected service instance .
In the early stage of the development of microservice architecture , The application layer service discovery model has been greatly promoted . The main application layer service discovery components are Netflix Of Eureka. This is also Spring Cloud The default service discovery component before the framework (Eureka Maintenance is now stopped ).
One advantage of application layer service discovery is that it can handle the problem of multi platform deployment ( The service discovery mechanism is independent of the underlying deployment platform ).
One disadvantage of application layer service discovery is that each service discovery library is language or framework related . Such as Eureka Can only help based on Java Developer . If needed GoLang Or other languages , You must use other service discovery components .
Platform layer service discovery pattern
Another way to implement service discovery is to deploy infrastructure to handle service discovery . Many modern deployment platforms ( Such as Docker and Kubernetes) Both have built-in service registry and service discovery mechanism . The deployment platform provides services for each service DNS name 、 fictitious IP(VIP) And resolve to VIP Address of the DNS name . Service call direction DNS Name and VIP Request , The deployment platform automatically routes requests to one of the available service instances . therefore , Service registration 、 Service discovery and request routing are handled entirely by the deployment platform . Examples are as follows :
The deployment platform includes a service registry , Used to track deployed services IP Address . When the service starts , The Registrar of the deployment platform writes the address of the service instance into the registry . Each service has a network location 、 One DNS Name and virtual IP Address . The service call requests the network location of the service provider from the router of the deployment platform . Then deploy the router of the platform to query the registry and load balance requests between available service instances .
The main advantage of the service discovery mechanism provided by the platform is that all aspects of service discovery are completely handled by the deployment platform . Neither the service provider nor the service caller contains any service discovery code . therefore , No matter which language or framework you use , The service discovery mechanism can be used by all service providers and service callers .
One disadvantage of the service discovery mechanism provided by the platform is that it is limited to services that support deployment using the platform . Based on Kubernets The findings of apply only to Kubernets Services running on .
From the perspective of the development of microservice architecture , The platform layer service discovery model has been successfully mainstream in the industry , Cloud service development I participated in , It is based on the platform layer service discovery pattern .
Reference resources
Microservice design Sam Newman Writing , Cui Liqiang etc. translate
Microservice architecture design pattern Chris Richardson Writing , Chen Bin etc. translate
https://itdks.su.bcebos.com/307ea09e7ef34bbfa58b845bf0f3d74b.pdf Microservice architecture development and platform evolution
边栏推荐
- Force buckle 146 LRU cache
- PAT甲级 1033 To Fill or Not to Fill
- 有沒有sqlcdc監控多張錶 再關聯後 sink到另外一張錶的案例啊?全部在 mysql中操作
- 2.11 simulation summary
- GifCam v7.0 极简GIF动画录制工具中文单文件版
- RobotFramework入门(三)WebUI自动化之百度搜索
- [Wu Enda machine learning] week5 programming assignment EX4 - neural network learning
- [Yunju entrepreneurial foundation notes] Chapter II entrepreneur test 12
- [Yunju entrepreneurial foundation notes] Chapter II entrepreneur test 13
- 事故指标统计
猜你喜欢

微服务注册与发现

C language - Blue Bridge Cup - promised score

Structural theme model (I) STM package workflow
![[Yunju entrepreneurial foundation notes] Chapter II entrepreneur test 15](/img/72/0fe9cb032339d5f1ccf6f6c24edc57.jpg)
[Yunju entrepreneurial foundation notes] Chapter II entrepreneur test 15
![[Yunju entrepreneurial foundation notes] Chapter II entrepreneur test 14](/img/c5/dde92f887e8e73d7db869fcddc107f.jpg)
[Yunju entrepreneurial foundation notes] Chapter II entrepreneur test 14

Ue4- how to make a simple TPS role (II) - realize the basic movement of the role

ReferenceError: primordials is not defined错误解决

HttpRunnerManager安装(三)-Linux下配置myql数据库&初始化数据

Shell script updates stored procedure to database
![[Yunju entrepreneurial foundation notes] Chapter II entrepreneur test 13](/img/29/49da279efed22706545929157788f0.jpg)
[Yunju entrepreneurial foundation notes] Chapter II entrepreneur test 13
随机推荐
[Yunju entrepreneurial foundation notes] Chapter II entrepreneur test 9
剑指 Offer 30. 包含min函数的栈
MySQL (IV) - transactions
Maturity of master data management (MDM)
QT release exe software and modify exe application icon
解决:AttributeError: ‘str‘ object has no attribute ‘decode‘
PMP practice once a day | don't get lost in the exam -7.5
Solve 9 with C language × 9 Sudoku (personal test available) (thinking analysis)
有没有sqlcdc监控多张表 再关联后 sink到另外一张表的案例啊?全部在 mysql中操作
A copy can also produce flowers
2345文件粉碎,文件强力删除工具无捆绑纯净提取版
主数据管理理论与实践
[Yunju entrepreneurial foundation notes] Chapter II entrepreneur test 8
Shell script updates stored procedure to database
C language - Blue Bridge Cup - promised score
Pat 1046 shortest distance (20 points) simulation
有沒有sqlcdc監控多張錶 再關聯後 sink到另外一張錶的案例啊?全部在 mysql中操作
What should we pay attention to when using the built-in tool to check the health status in gbase 8C database?
米家、涂鸦、Hilink、智汀等生态哪家强?5大主流智能品牌分析
Which ecology is better, such as Mi family, graffiti, hilink, zhiting, etc? Analysis of five mainstream smart brands