当前位置:网站首页>Eureka service registration and discovery

Eureka service registration and discovery

2022-06-22 22:15:00 Miaoshiansen likes fish

One 、 The registry of microservices

The registry can be said to be in the microservice architecture “ Mail list ”, It records the mapping relationship between service and service address . In a distributed architecture , The service will register here , When a service needs to call other services , You will find the service address here , To call .
 Insert picture description here

1.1 The main role of the registry

Service registry ( Hereinafter referred to as the registry ) Is a very important component of microservice architecture , It mainly plays the role of coordinator in the microservice architecture . The registry generally includes the following functions :
1、 Service discovery :

  • Service registration / Anti registration : Save information about service providers and service callers
  • Service subscription / Unsubscribe : The service caller subscribes to the service provider's information , It's better to have the function of real-time push
  • Service routing ( Optional ): Have the ability to screen integrated service providers

2、 Service configuration :

  • Configure subscription : Service providers and service callers subscribe to microservice related configurations
  • Configure distribution : Actively push configuration to service providers and service callers

3、 Service health testing

  • Check the health status of the service provider

1.2 Common registries

Zookeeper
Zookeeper Is a distributed services framework , yes Apache Hadoop A subproject of , It is mainly used to solve some data management problems often encountered in distributed applications , Such as : Unified naming service 、 State synchronization service 、 Cluster management 、 Management of distributed application configuration items . Simply speaking Zookeeper = file system + Monitoring notification mechanism .

Eureka
Eureka Is in Java Language , be based on RESTful API Developed service registration and discovery components ,SpringCloud Netflix Important components in .

Consul
Consul By HashiCorp be based on Go Service publishing and registration software supporting distributed and highly available services in multiple data centers developed by language , use Raft Algorithm guarantees service consistency , And support health examination

Nacos
Nacos It is a dynamic service discovery that is easier to build cloud native applications 、 Configuration management and service management platform . Simply speaking Nacos It's the registry + A combination of configuration centers , Provide an easy to use feature set , Help us to solve the problems of service registration and discovery that microservice development must involve , Service configuration , Service management, etc .Nacos still SpringCloud Alibaba One of the components , Responsible for service registration and discovery .

Component name Language CAP Consistency algorithm Service health check Exposed interface
EurekaJavaAP nothing With support HTTP
ConsulGoCPRaft Support HTTP/DNS
ZookeeperJavaCPPaxos Support client
NacosJavaAPRaft Support HTTP

Two 、Eureka Overview

2.1 Eureka Basic knowledge of

Eureka yes Netflix Developed service discovery framework ,SpringCloud Integrate it into your own subproject spring-cloud-netflix in , Realization SpringCloud Service discovery capabilities for .
 Insert picture description here
The picture above briefly describes Eureka Basic architecture , from 3 The characters make up :
1、Eureka Server

  • Provide service registration and discovery

2、Service Provider

  • service provider
  • Register your services with Eureka, So that service consumers can find

3、Service Consumer

  • Service consumer
  • from Eureka Get the list of registered services , To be able to consume Services

2.2 Eureka Interaction process and principle of

 Insert picture description here
Figure is from Eureka Official architecture , It gives a general description Eureka Working process of cluster . There are many components in the diagram , Explain it. :

  • Application Service Equivalent to a service provider ,Application Client Equivalent to serving consumers
  • Make Remote Call, It can be simply understood as calling RESTful API
  • us-east-1c、us-east-1d Are all zone, They all belong to us-east-1 This region

About zone and region You can see this article for an introduction to :eureka In depth explanation of zoning

It can be seen from the picture that ,Eureka There are two components :Eureka Server and Eureka Client, Their functions are as follows :

  • Eureka Client It's a Java client , Used to simplify and Eureka Server Interaction ;
  • Eureka Server The ability to provide service discovery , When each microservice starts , Will pass Eureka Client towards Eureka Server Register your own information ( For example, network information ),Eureka Server Will store information about the service
  • After the micro service is started , Periodically Eureka Server Send a heartbeat ( Default period 30 second ) To renew your information . If Eureka Server The heartbeat of a microservice node is not received within a certain period of time ,Eureka Server The microservice node will be unregistered ( Default 90 second )
  • Every Eureka Server It's also Eureka Client, Multiple Eureka Server Complete the synchronization of service registry through replication
  • Eureka Client Will cache Eureka Server Information in . Even if all Eureka Server All nodes are down , Service consumers can still find service providers using cached information .

Sum up ,Eureka By heartbeat detection 、 Mechanisms such as health checks and client caching , Improved system flexibility 、 Scalability and availability .

原网站

版权声明
本文为[Miaoshiansen likes fish]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/173/202206222029500437.html