How Does A Eurka Client Register With Eurkea Server
Table of Contents
Micro-services are all good until they come with their distributed challenges which normally nosotros don't face up in monolithic based applications. Only like this one!
Understanding the problem
In order to fully go the principal purpose of the solution let us first sympathize the underlying trouble.
As the diagram above shows, nosotros accept to micro-services communicating via a sure network:
- Micro-service I with the IP address ten.10.ten.ten , and port 8080
- Micro-service II with the IP address 20.twenty.20.20 , and port 8090
All working peacefully until the 2d micro-service changed its accost and port for some reason.
As result the micro-service I cannot communicate with micro-service II since it doesn't have the new address and port (xxx.thirty.30.xxx:5000). To resolve this we demand to provide manually the micro-service I with the micro-service II'southward new address and port. What if we can do that automatically?
The answer is Aye, and that'south exactly what Netflix Eureka does.
Eureka under the hood
The first thing MS2 will practise is to register to the naming registry server (Eureka server) providing mainly its IP, port and status (UP or DOWN). [A]
Earlier MS1 makes the call to MS2 [D], it will fetch the MS2 coordinates from the naming registry [B] which volition allow the advice to happen even if MS2 changes its location a million times equally long as its registers to the Eureka server. The server will respond with the required information. [C]
You should as well empathize that by fetching the naming registry or registering to it, the micro-service becomes its customer (Eureka customer).
Let's talk lawmaking
For this tutorial I'll exist using:
Spring Boot two.six.2
| |
Java 8 && Spring cloud 2021.0.0
| |
and of course the dependency management for the spring cloud modules
| |
Eureka server configuration
The Eureka server require the Bound Cloud starter netflix eureka server dependency
| |
Then, we demand a set of properties as the post-obit
| |
Finally, we need to declare our app as a registry service using the @EnableEurekaServer
note:
| |
You can find a user interface generated past Eureka, for our example is on localhost:8099
Eureka client configuration
The Eureka customer require the Spring Cloud starter netflix eureka client dependency
| |
Too for this one, nosotros need a prepare of properties:
| |
Finally, we demand to declare our app equally a discovery client (Eureka customer) using the @EnableDiscoveryClient
annotation:
| |
Once, we first our client app, we will observe that information technology successfully registered to the running eureka server.
This may seem incomplete , actually information technology is, since we're non fetching the eureka server for registered service instances and exploit them. That's the main purpose of the next commodity when nosotros will be doing then using a reverse proxy called Netflix Zuul .
Reference https://elattar.me/posts/spring-cloud-introduction-to-service-discovery-netflix-eureka/
How Does A Eurka Client Register With Eurkea Server,
Source: https://www.springcloud.io/post/2022-03/spring-cloud-introduction-to-service-discovery-netflix-eureka/
Posted by: tobiaswenscipt.blogspot.com
0 Response to "How Does A Eurka Client Register With Eurkea Server"
Post a Comment