Connecting microservices to a Netflix Eureka server
In this section, we will learn how to connect microservice instances to a Netflix Eureka server. We will learn both how microservices instances register themselves to the Eureka server during their startup and how clients can use the Eureka server to find the microservice instances they want to call.To be able to register a microservice instance in the Eureka server, we need to do the following:
- Add a dependency to
spring-cloud-starter-netflix-eureka-clientin the build file,build.gradle:
Implementation 'org.springframework.cloud:spring-cloud-starter-netflix-eureka-client'
- When running tests on a single microservice, we don't want to depend on having the Eureka server up and running. Therefore, we will disable the use of Netflix Eureka in all Spring Boot tests, that is, JUnit tests annotated with
@SpringBootTest. This can be done by adding theeureka.client.enabledproperty and setting it tofalsein the annotation...