This Java and microservices tutorial shows how one microservice communicates with another dependent microservice service via the service registry and Eureka Server.
Let's see the sequence of how one microservice calls another microservice using Eureka server.
Each microservice should be registered into the service registry with a unique name {service-id}, so it can be identified.
Please note that it is an important step, as one of the main benefits of microservices is autoscaling; we can’t rely on the hostname/IP address, so a unique name is important in a distributed environment.
Fetching the Registry:
Before calling the downstream/dependent service, the caller service fetches the registry from Eureka server. The registry contains all the active services registered into the service registry.
Please note the Iniques service id act as a Key in service registry but network does not know about it network expects Hostname to call the desired Rest Endpoint on the dependent service like (localhost:8080/employee/{id} or employee.cognizant,com/2 etc).
So it is required to resolve the actual hostname of the dependent service Eureka API provides a method for that we just invoke that method to get the Ip address, For a distributed system it is the public IP of Load balancer.
Call the Rest Endpoint:
After resolving the IP address using Spring Resttemplate, we call the actual Rest endpoint and get the data.
For more updates keep an eye on this website!