DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Newsletter
Log In / Join
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Related

  • Distributed Tracing System (Spring Cloud Sleuth + OpenZipkin)
  • Migration of Microservice Applications From WebLogic to Openshift
  • Google Cloud Pub/Sub: Messaging With Spring Boot 2.5
  • Microservices With JHipster

Trending

  • Build Production-Ready AI Phone Agents: Infrastructure, Models, and Telephony
  • Member Spotlight: Shai Almong
  • Prompt Caching for LLMs, Part 1: Exact-Match Caching in Production
  • Engineering Data Observability: Detecting Schema Drift, Data Drift, and Silent Pipeline Failures

Draft This article hasn't been published, so readers can't see it.

In moderation This article is waiting for review, so readers can't see it yet.

Deleted This article has been deleted, so readers can't see it.

  1. DZone
  2. Coding
  3. Frameworks
  4. Netflix Eureka Discovery – Microservices

Netflix Eureka Discovery – Microservices

Learn about using Netflix Eureka with microservices to monitor and maintain a registry of all the microservices in the ecosystem.

By 
Sovan Misra
·
Aug. 29, 18 · Tutorial
Post on X (opens in a new tab) Share on LinkedIn (opens in a new tab)
49.3K Views

Join the DZone community Save articles, join the discussion, and download Refcards and Trend Reports with a free account.

Join for free Already a member? Log in

In the headline, we saw three buzzwords:

  1. Microservices
  2. Netflix Eureka
  3. Discovery (Registry)

What Is a Microservice?

In simple words, microservice(s) are clusters of small applications that work together in coordination to provide a complete solution.

When we say a lot of small applications running independently together, then they will all have their own URLs and ports. In that scenario, it would be very cumbersome to maintain all these microservices to run in synchronization, and more importantly, with monitoring. This problem will increase manifold when we start implementing load balancers.

To solve this issue, we need a tool that will monitor and maintain the registry of all the microservices in the ecosystem.

What Is Netflix Eureka?

This is a tool provided by Netflix to provide a solution to the above problem. It consists of the Eureka Server and Eureka clients. Eureka Server is in itself a microservice to which all other microservices registers. Eureka Clients are the independent microservices. We will see how to configure this in a microservice ecosystem.

I will be using Spring Boot to create a few microservices which will act as Eureka Clients and a Discovery Server which will be a Eureka Server. Here is the complete project structure:

microservice1

Let’s Discuss the Eureka Discovery Server

This is the Eureka Server, and for that, we have to include a Eureka dependency in the project. Below is the pom.xml for Eureka Discovery Server.

microService2

Also, we need to update the properties file for this project to indicate that is a discovery server and not a client.

eureka.instance.hostname=localhost
eureka.client.register-with-eureka=false
eureka.client.fetch-registry=false

To bind the discovery application to a specific port and name the application, we need to add the following, as well:

server.port=8000
spring.application.name=DiscoveryServer

microService3

One last thing to do is to annotate the Spring Boot application to enable this as a Eureka Server. To do so, we need to add  @EnableEurekaServer .

microService4

Boot up the application we will see a UI provided by Eureka to list all the servers that get registered. But, at this point, we have none!

microService5

Now, let’s add a few microservices to the ecosystem and register them to the discovery server. For this, we also need to add the dependencies required in each service and register them to the server. We will see how in the details below.

I have created three simple microservices (microservice1, microservice2, microservice3) with Spring Boot and each one running on its own port (8002, 8003 and 8004).

microService6

As a client, it should register itself to the server, and that happens in the property file, as below.

microService7

The main application will be annotated with @EnableEurekaClient in each microservice.

microService8

Boot up this application to run on port 8004 and it will automatically register itself to the discovery server. In a similar manner, I have created two more microservices and registered them on the discovery server.

microService9

We can see that three servers are running in the ecosystem and we can monitor the status of these servers, too.

This eases the monitoring of all the servers and their replicas in case we are using a load balancer.

I hope this will help you get started using Discovery Server and Clients using Eureka.

Reference the Git repository containing the codes for all the projects in this application!

microservice Discovery (law) Spring Framework application Spring Boot

Published at DZone with permission of Sovan Misra. See the original article here.

Opinions expressed by DZone contributors are their own.

Related

  • Distributed Tracing System (Spring Cloud Sleuth + OpenZipkin)
  • Migration of Microservice Applications From WebLogic to Openshift
  • Google Cloud Pub/Sub: Messaging With Spring Boot 2.5
  • Microservices With JHipster

Partner Resources

×

Comments

Loading comments

The comments didn't load

Please try again in a moment.

Likes

Loading

The next likes didn't load. Please try again.

The likes didn't load

Please try again in a moment.

See who liked this

Log in or join DZone for free to see who liked this article.

Log in Join for free
  • RSS
  • X
  • Facebook

ABOUT US

  • About DZone
  • Support and feedback
  • Community research

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 215
  • Nashville, TN 37211
  • [email protected]

Let's be friends:

  • RSS
  • X
  • Facebook