Setting up a Netflix Eureka server
In this section, we will learn how to set up a Netflix Eureka server for service discovery. Setting up a Netflix Eureka server using Spring Cloud is really easy – just follow these steps:
- Create a Spring Boot project using Spring Initializr, as described in Chapter 3, Creating a Set of Cooperating Microservices, in the Using Spring Initializr to generate skeleton code section.
- Add a dependency to
spring-cloud-starter-netflix-eureka-server
. - Add the
@EnableEurekaServer
annotation to the application class. - Add a Dockerfile, similar to the Dockerfiles that are used for our microservices, with the exception that we export the default Eureka port,
8761
, instead of the default port for our microservices,8080
. - Add the Eureka server to our three Docker Compose files, that is,
docker-compose.yml
,docker-compose-partitions.yml
, anddocker-compose-kafka.yml
, like this:
eureka:
build: spring-cloud/eureka-server
mem_limit: 512m
ports:
- "...