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 Video Library
Refcards
Trend Reports

Events

View Events Video Library

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

Generative AI has transformed nearly every industry. How can you leverage GenAI to improve your productivity and efficiency?

SBOMs are essential to circumventing software supply chain attacks, and they provide visibility into various software components.

Related

  • Microservices With JHipster
  • How to Develop Microservices With Spring Cloud and Netflix Discovery
  • A New Era Of Spring Cloud
  • NGINX With Eureka Instead of Spring Cloud Gateway or Zuul

Trending

  • Deploying LLMs Across Hybrid Cloud-Fog Topologies Using Progressive Model Pruning
  • Vibe Coding: Conversational Software Development — Part 1 Introduction
  • Parallel Data Conflict Resolution in Enterprise Workflows: Pessimistic vs. Optimistic Locking at Scale
  • *You* Can Shape Trend Reports: Join DZone's Data Engineering Research
  1. DZone
  2. Software Design and Architecture
  3. Cloud Architecture
  4. Spring Cloud Netflix: How Service Registration and Discovery Work

Spring Cloud Netflix: How Service Registration and Discovery Work

See how to integrate some of Netflix's toys into your own Spring Boot project with examples of service registration and discovery.

By 
Rafael Salerno user avatar
Rafael Salerno
·
Aug. 22, 16 · Tutorial
Likes (14)
Comment
Save
Tweet
Share
29.6K Views

Join the DZone community and get the full member experience.

Join For Free

Spring Cloud has a full stack for microservices. The main objective of Spring Cloud is to provide a complete integration between Spring Boot and the Netflix OSS project, where simple annotation allows you to have some components used by Netflix running in your environment

Some pattern provided by Netflix OSS that Spring Cloud provides: 

  • Service Discovery (Eureka).
  • Circuit Breaker (Hystrix).
  • Intelligent Routing (Zuul).
  • Client Side Load Balancing (Ribbon).

In this post, we will talk about service discovery, display the concept, and show how it is possible to, with a few annotations, to have the default working on a project with Spring Boot.

Service Discovery is one of the key tenets of microservice-based architecture. Trying to hand-configure each client or some form of convention can be very difficult to do and can be very brittle. Eureka is the Netflix Service Discovery Server and Client. The server can be configured and deployed to be highly available, with each server replicating state about the registered services to the others.

Why Use Service Discovery?

Let's imagine we have many services dynamically distributed on the network, where instances of services dynamically change because of auto-scaling, failures, upgrades, and we have no control of IP addresses, the name of the instance. In this situation, the simplest solution would be if the service tells the server or other services where it is and if it is available.


This is how the discovery service works, the service entered in the network and register on a server to make it available for the use of some other service. The pattern that will be addressed in this post will be The Server-Side Pattern Discovery.

Where customers know where the server is and send to the server that is available.

Registering

When a client registers with Eureka, it provides meta-data about itself ,such as host and port, health indicator URL, home page, etc. Eureka receives heartbeat messages from each instance belonging to a service. If the heartbeat fails over a configurable timetable, the instance is normally removed from the registry.

Status Page and Health Indicator

The network location of a service instance is registered with the service registry when it starts up. It is removed from the service registry when the instance terminates. The service instance’s registration is typically refreshed periodically using a heartbeat mechanism.

Eureka’s Health Checks

By default, Eureka uses the client heartbeat to determine if a client is up. Unless specified otherwise the Discovery Client will not propagate the current health check status of the application per the Spring Boot Actuator. Which means that after successful registration Eureka will always announce that the application is in 'UP' state. Enabling Eureka health checks can alter this behavior, which results in propagating application status to Eureka. As a consequence, every other application won’t be sending traffic to the application in state other than 'UP'.


Server Code




Client 1 Code

                          

The default zone is the Eureka service address:

Tomcat port to client 1


Client 2 Code

The same as Client 1 but in another port:




Steps to Run

1. Run the Server

It will be available on http://localhost:8761 and will show some information and a screen with the instances available.


2. Run Client 1

Now, in the server, it is possible to see the instance registered: 

 

3. Run Client 2

Now, in the server, it is possible to see the new instance registered:


All registered instances:  

Health information image:  


My Sandbox with the samples above.

With few lines of code and annotation, is possible have all benefits of service discovery with spring boot and eureka.

Spring Framework microservice Spring Cloud Discovery (law)

Opinions expressed by DZone contributors are their own.

Related

  • Microservices With JHipster
  • How to Develop Microservices With Spring Cloud and Netflix Discovery
  • A New Era Of Spring Cloud
  • NGINX With Eureka Instead of Spring Cloud Gateway or Zuul

Partner Resources

×

Comments

The likes didn't load as expected. Please refresh the page and try again.

ABOUT US

  • About DZone
  • Support and feedback
  • Community research
  • Sitemap

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 100
  • Nashville, TN 37211
  • [email protected]

Let's be friends: