To register any microservice with the Eureka name server, we need to add the dependency on a Eureka starter project. The following dependency needs to be added to the pom.xml file of Microservice A:
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
</dependency>
The next step is to add EnableDiscoveryClient to the SpringBootApplication classes. An example of MicroserviceAApplication is shown here:
@SpringBootApplication
@EnableDiscoveryClient
public class MicroserviceAApplication {
We will configure the URL of the naming server in the application configuration. For Microservice A, the application configuration is in the local Git repository file, git-localconfig-repo/microservice-a.properties:
eureka.client.serviceUrl.defaultZone=
http://localhost:8761/eureka
When both instances of Microservice A are restarted, you will see these messages in the log of Eureka Server:
Registered instance MICROSERVICE-A/192.168.1.5:microservice-a
with status UP (replication=false)
Registered instance MICROSERVICE-A/192.168.1.5:microservice-a:
8081 with status UP (replication=false)
A screenshot of the Eureka dashboard at http://localhost:8761 is as follows:
Two instances of Microservice A are now registered with Eureka Server. Similar updates can be done on Config Server in order to connect it to Eureka Server.
In the next step, we want to connect the Service Consumer microservice to pick up URLs of instances of Microservice A from Eureka Server.