This sample shows off how to use Spring Cloud Eureka for service discovery between microservices. In this sample it will be shown how message-service
registers itself inside eureka, while billboard-client
is able to resolve the endpoint for message-service
from the eureka registry by looking it up by it's service name.
- Import the root of the repo into your favorite Java IDE
- Run eureka-server application
- Run
message-service
application - Browse to http://localhost:8761 and confirm that
message-service
is showing up in the eureka registry - Run
billboard-client
application and browse it to it in your browser
- Examine
BillboardController
inbillboard-client
to view how the invocation URL is based on application name instead of actual endpoint. The hostname will be automatically substituted by Eureka - Browse to eureka dashboard at http://localhost:8761. Observe that only the
message-service
is showing up, asbillboard-client
only fetches registry, but doesn't advertise itself - Run multiple instances of
message-service
. Observe how a single service have multiple instance URLs in eureka dashboard. The calling application will do client-side load balancing by selecting a random instance when calling it.