When I start to build microservice platform, the first thing that I thought is how every service do discover each other with minimum effort, I mean, when we create two services and they do communication, I don’t need to define url for every services that we need to access, also if we need, we don’t need to define raw json request and response when we need to to microservice operation.

First, I think I can build library that will do service discovery, but it will take very long time to do research and do debugging, and finally I find a library that used (and maybe develop) by Netflix, it called netflix eureka, this library is supported by Spring Boot framework, the framework that using for long time since my career as Java Software Engineer, this library exist on spring cloud, I will write about spring cloud in my blog, but now, let me explain how I config Eureka for my microservice project

Dependency for eureka server

Create spring boot project and include these dependency into pom.xml(we use maven)

  • spring-boot-starter
  • spring-boot-starter-test
  • spring-cloud-starter-netflix-eureka-server

Also include for dependency management for spring cloud so we don’t need to define version for each dependency

This is the full pom.xml

Setting up eureka configuration

We will deploy our eureka server into port 10000, we define this port on application.yml

And we define our eureka as server so this server will not fetch registry from another server

Setting up the main class

Goto your main class that run spring boot for first time and add annotation that indies project mark as eureka server using annotation @EnableEurekaServer

Run your first eureka server

$ mvn spring-boot:run

our terminal will looks like this, it means server already running on localhost port 10000

Eureka server is running

Eureka server is running

You can find this project and feel free to checkout on my github page

Now you have eureka service discovery, see you at next post