Implementing Eureka Server

Malinda Peiris
3 min readApr 20, 2019

Is there such thing as Eureka server..?

Some of you might not know about “Eureka server” yet we all have heard the story of Archimedes where he proclaimed “Eureka! Eureka!” (I have found it) when he finds out upthrust experienced by a body immersed in a fluid for the first time. You might wonder what this article all about. I can assure you this is not about upthrust theory.

What is Eureka?

Simply Eureka is a server. It holds the details of its clients. Eureka act as a discovery client where it keeps details of its client applications (port, Ipaddress etc). The Eureka Server is a Netflix OSS product, and Spring Cloud offers a declarative way to register and invoke services by Java annotation.

Basic architectural representation of Eureka server and Eureka client.

Eureka Server Implementation

A Eureka server works with spring framework Eureka server can be created using https://start.spring.io/ by adding the dependency Eureka Server.

Creating Eureka server

There is another dependency which comes up when you search for eureka in the dependency tab called Eureka Discovery that’s for Eureka client, I’ll come up with that in next article. Spring main class looks like this

Spring main class

The one amazing things working with spring is that its ability of this dependency injection. By a simple annotation you can do whole lot of things in Spring. In here also you can simply create this Eureka Server by injecting @EnableEurekaServer. I’m pretty sure this annotation is not part of the downloaded project from spring.io. The annotating should be added explicitly.

Are we done? No not yet. There are some more configurations to be done.

Spring JAVA Maven Dependencies for Eureka server

Since I have created this as a maven project in the pom.xml you could see following dependencies which are related to Eureka server. One is spring cloud version inside the properties

pom.xml in maven

Dependencies for Eureka server

build.gradle file gradle

One last configuration to be done before run the Eureka server.In application.properties you have to put these configurations.

application.properties

What are these configurations? Port in not a must to add to the properties. Other two are must if you are starting eureka for the first time. Here is the thing every eureka server act as a Eureka client. When it runs it tries to register with other Eureka server since in microservices you can have multiple instances of Eureka servers so that they can register with each other. It’s the greatness of microservices if one instance is to fail other instance provide the service. These properties would stop eureka server acting as a client. I’ve said the server you are the in charge here by adding these two properties.

You’re good to go! Run the main method in the application. Eureka!! 😉

It runs default on port 8761 if you want to change you can change applications application properties.

If you’re getting bellow interface when you directed to http://localhost:8761/ means done you have successfully configured Eureka server.

Eureka Server Interface

Configuring Eureka client and usage of Eureka server and client will be described in next article. Please comment on your view of this article since this is my first medium article.

--

--