Microservice Service Discovery Best Practices

I covered how to get started with Eureka Server Setup in my previous post, and this is the second part of the microservices communication series.

Spring Initializer is utilised to create our project here. Before generating a Maven project, select the Spring Boot version and then add the "Spring Web" and "Eureka Discovery Client" dependencies.




To make this a client, simply add the @EnableEurekaClient annotation to the class.



As an alternative, we may utilise the spring-cloud-commons @EnableDiscoveryClient annotation. It chooses the implementation (Zookeeper, Eureka) based on the classpath. It would automatically select Eureka in our instance.


We may define our Employee model as follows: setters, getters, and a constructor



Finally, we may specify a controller.



In the preceding section, we constructed a basic endpoint that returns a list of Employee objects, emulating a database query.

In this project, we have the Eureka Discovery client jar. When Spring encounters this on the classpath, it will attempt to locate a running Spring Eureka server. This must be specified in the application.file with properties.


In addition to the server URL, we must additionally supply the application name. Other services will use this name when making REST calls.

We've now registered our service on the server, and any other registered service can use spring.application.name to call it

After running the EnableDiscoveryApplication class, let's refresh/call the Eureka server endpoint



In addition to registering with Eureka server, the Eureka client jar sends frequent heartbeats to Eureka server to notify it that it is still available. 
  • How to Begin Using the Eureka server 
  • Simple REST service that has been registered with the Eureka cloud registry

Part3

Client Service Configuration- All you need to do is follow the instructions below to set up an end service called client service.
  • application.properties file 
  • Main application with @EnableEurekaClient annotation 
  • Client controller class 

Conclusion:

That's all there is to it, if you enjoyed this tutorial, please share it with others...!

Chandra Sekhar

A Blogger and Author! This post was written and edited by me, a technologist. I started this site to share my inspirations, work, and free materials, which I hope others may find useful as well. Man with a creative streak who enjoys experimenting with various web design strategies.

Previous Post Next Post

Microservice Communication in a Distributed System