In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-15 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)05/31 Report--
This article will explain the example analysis of Spring Cloud Eureka for you in detail. The editor thinks it is very practical, so I share it with you as a reference. I hope you can get something after reading this article.
Eureka is a part of the Spring Cloud Netflix micro-service suite, which is secondary developed based on Netflix Eureka and is mainly responsible for completing the service governance function in the micro-service architecture.
Three core elements of Eureka infrastructure
1: service registry
2: service provider
3: serve consumers
Service governance is mainly divided into:
1: service registration:
In the service governance framework, a service registry is usually built, and each service provider needs to register its own registration information with the registry. Such as IP, port number, version number, service name, communication protocol and other additional information to inform the registry, the registry will classify the list of services according to the service name. For example, the following figure:
Eureka maintains the list of classified services through a two-tier Map. The key of the first layer Map is the service name, such as the HELLO-SERVICE above, and the Key of the second layer is the specific instance information, such as the DLBOOH.:hello-service:8081 above.
2: service discovery
Because the program operates under the service governance framework, the invocation between services is no longer achieved by specifying a specific instance address, but by the service name, such as http://hello-service:8081/hello. So when the service caller wants to invoke the service provider's interface, the service caller does not know the specific instance address of the service provider, so the caller needs to consult the registry Eureka for services and get the instance list of all services. For example, if existing service B wants to invoke service A, service B needs to initiate a request to the registry to obtain the instance list of service A, and the registry returns the instance list of service A. then service B will poll the instances in the access list with a certain policy from the list, and the load balancing effect can be accessed through Ribbon.
In the actual production project, the service list list is not obtained in every request, which is inefficient. Mechanisms such as caching and service culling will also be implemented in different ways in the actual scenario.
3: service synchronization
When Eureka implements high availability, service providers can register with different service registries in the cluster, that is, their information is maintained by different registries. At this time, since service centers register as services each other (high availability), when the service provider sends a registration request to a service registry, it will forward the request to other registries in the cluster and synchronize it. So as to realize the service synchronization of the service registry. Through service synchronization, the service information of the two service providers can be obtained through either of the two service registries.
4: service renewal
After registering for the service, the service provider maintains a heartbeat to keep telling Eureka "I'm alive" to prevent Eureka's stripping service from excluding the service from the list, which we call service renewal.
There are two important attributes about service renewal
# # used to define the interval between calls for service renewal tasks. Default is 30 seconds.
Eureka.instance.lease-renewal-interval-in-seconds=30
# # Parameter is used to define the service expiration time. Default is 90 seconds.
Eureka.instance.lease-expiration-duration-in-seconds=90
5: get services
When the service consumer program starts, it sends a Rest request to the registry to get the list of services registered above. For performance reasons, Eureka maintains a read-only list of services to return to the client, and the cache list is updated every 30 seconds.
Obtaining service is the foundation of service consumers, so you must make sure that eureka.client.fetch-registry=true defaults to true. If you want to modify the update time of cache list, you can modify it through eureka.client.registry-fetch-interval-seconds=30. Default is 30 seconds, and parameters are in seconds.
6: service invocation
After obtaining the service list, the name of the instance and the metadata of the instance (ip,port, etc.) can be obtained through the service name. Ribbon is used to implement polling to invoke the service provider.
7: service offline
When the service is offline, under normal circumstances, we do not want the service consumer to continue to call the service that has been offline, so when the service provider shuts down normally, it will trigger a REST request for service offline, telling Eureka "I am going offline". When Eureka receives the request, it sets the service to (DOWN) and broadcasts the message to update the cache list.
8: failure elimination of service center
When the service shuts down abnormally, such as machine Down, power outage, memory overflow, network failure, and so on. At this time, the request from the REST that will not be offline will be triggered. In order to remove these services that are no longer available, Eureka Server will create a scheduled task at startup. By default, the expired contract will be removed from the list every 60 seconds.
This is the end of this article on "sample Analysis of Spring Cloud Eureka". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, please share it for more people to see.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.