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
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports Events Over 2 million developers have joined DZone. Join Today! Thanks for visiting DZone today,
Edit Profile Manage Email Subscriptions Moderation Admin Console How to Post to DZone Article Submission Guidelines
View Profile
Sign Out
Refcards
Trend Reports
Events
Zones
Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Join us today at 1 PM EST: "3-Step Approach to Comprehensive Runtime Application Security"
Save your seat
  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.

Sovan Misra user avatar by
Sovan Misra
·
Aug. 29, 18 · Tutorial
Like (14)
Save
Tweet
Share
45.47K Views

Join the DZone community and get the full member experience.

Join For Free

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, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

Popular on DZone

  • Playwright vs. Cypress: The King Is Dead, Long Live the King?
  • Simulate Network Latency and Packet Drop In Linux
  • Cloud Native London Meetup: 3 Pitfalls Everyone Should Avoid With Cloud Data
  • When AI Strengthens Good Old Chatbots: A Brief History of Conversational AI

Comments

Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

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

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 600 Park Offices Drive
  • Suite 300
  • Durham, NC 27709
  • support@dzone.com
  • +1 (919) 678-0300

Let's be friends: