Real time cloud application consist of a large number of micro services communicating with each other. Service instances are added/removed dynamically based on requirement and availability. Service discovery is the process of one service dynamically discovering the network location (IP address and port) of another service without hard coding their location.
1. Service registers location - when service boots up it registers itself with discovery server
2. Client looks for service location - When client needs to hit a particular service first it goes to discovery server for its location
3. Discovery server sends back location - Discovery server sends the active location of the particular service
4. Client request service at location - This is a normal request to the service
5. Service sends response - Service responds to client accordingly
Example -
Started eureka server on default port 8761 and Started 2 instances of Application service on 8081 and 8082
Discovery Server
pom.xml
application.properties
DiscoveryServerApplication.java
Application Service
pom.xml
application.properties
ServiceApplication.java
Controller.java
Client
pom.xml
application.properties
DiscoveryClientApplication.java
Controller.java
Here is complete source code in Github
https://github.com/madan712/discovery-server
https://github.com/madan712/discovery-application-service
https://github.com/madan712/discovery-client