Get the App
SLTechnology News&Howtos  ›  Development  › 

Example Analysis of Service Registration and Discovery Eureka and Registration Source Code in SpringCloud

Shulou Source: shulou.com Published: 2022-06-02 10:31:42 10月04日 Update

SpringCloud service registration and discovery Eureka and registration source code example analysis, I believe that many inexperienced people do not know what to do, so this article summarizes the causes of the problem and solutions, through this article I hope you can solve this problem.

Service registration and discovery

Relationship:

1. Upon startup, the service provider registers the services it provides with the registry.

two。 Service consumers subscribe to the services they need from the registry when they start up.

3. The registry returns the service provider address to the consumer.

4. The service consumer invokes the consumer from the provider address.

Eureka introduction:

Spring Cloud Eureka is a part of the Spring Cloud Netflix micro-service suite, which is re-encapsulated based on Netflix Eureka and is mainly responsible for completing the service governance function in the micro-service architecture. By adding Spring Boot-style automated configuration to Eureka, Spring Cloud can easily integrate micro-service applications built by Spring Boot with Eureka service governance architecture by simply introducing dependency and annotation configuration.

Netflix Eureka

Spring Cloud Eureka, which uses Netflix Eureka to realize service registration and discovery, contains both server-side components and client-side components, and both server-side and client-side components are written in Java, so Eureka is mainly suitable for distributed systems implemented through Java or systems built with NM compatible languages. However, because the service governance mechanism of Eureka server provides a complete RESTfulAPL, it also supports the integration of micro-service applications built in non-Java language into the service governance system of Eureka. Just when using other language platforms, you need to implement the client program of Eureka on your own. Fortunately, on several popular development platforms, there are already some client implementation frameworks for Eureka registries, such as Steeltoe for .NET platform, eureka-js-client for Node.js, and so on.

The Eureka server, also known as the service registry. Like other service registries, it supports highly available configurations. It relies on strong consistency to provide good service instance availability and can deal with a variety of different failure scenarios. If the Eureka is deployed in cluster mode, when a shard in the cluster fails, then the Eureka goes into self-protection mode. It allows the discovery and registration of services to continue during a shard failure, and when the fault shard resumes operation, other shards in the cluster will synchronize their status back. Taking the practice on AWS as an example, Netflix recommends running an Eureka server for each available region to form a cluster. Service registries in different availability regions replicate their states to each other through an asynchronous pattern, which means that each instance has a slight difference in the state of all services at any given point in time.

Eureka client, which mainly deals with the registration and discovery of services. The client service is embedded in the code of the client application through annotations and parameter configuration. When the application is running, the Eureka client registers its own services with the registry and periodically sends a heartbeat to update its service lease. At the same time, it can also query the currently registered service information from the server and cache them locally and refresh the service status periodically.

Eureka environment building

First, build the server

1. New project

Tags: Services methods customers clients instances information protection configuration code faults consumers status programs consumption addresses data time mechanisms processes problems Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno NVidia Huawei OPPO Reno Shulou Information MariaDB