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
Partner Zones AWS Cloud
by AWS Developer Relations
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
Partner Zones
AWS Cloud
by AWS Developer Relations
Building Scalable Real-Time Apps with AstraDB and Vaadin
Register Now

Trending

  • Revolutionizing Algorithmic Trading: The Power of Reinforcement Learning
  • Reactive Programming
  • SRE vs. DevOps
  • Automating the Migration From JS to TS for the ZK Framework

Trending

  • Revolutionizing Algorithmic Trading: The Power of Reinforcement Learning
  • Reactive Programming
  • SRE vs. DevOps
  • Automating the Migration From JS to TS for the ZK Framework
  1. DZone
  2. Coding
  3. Frameworks
  4. The Netflix Stack Using Spring Boot - Part 1: Eureka

The Netflix Stack Using Spring Boot - Part 1: Eureka

Netflix isn't just for streaming movies and television show. The awesome folks over at Netflix are contributing not only to our binge-watching, but also to the open source world. Here's a neat look at the Netflix stack, and using Spring Boot. This overview probes Netflix-created libraries, and incorporating them into Spring apps.

Quinten De Swaef user avatar by
Quinten De Swaef
·
Mar. 16, 16 · Tutorial
Like (18)
Save
Tweet
Share
27.14K Views

Join the DZone community and get the full member experience.

Join For Free

Netflix has always been a proud contributor to the open source world. It's fascinating to see how each of their libraries facilitate a lot of tasks and can help create your development in a tremendous way.

In this series of blog posts - The Netflix stack, using Spring Boot - I'll be going over some of the libraries which Netflix has created and how to incorporate them into your Spring applications. As always, it'll be more of a hands-on experience as this blog post will basically just be an overview of what you can find in the accompanying repository.

Eureka

Today we'll be looking at Eureka. The Netflix Eureka Github introduction:

Eureka is a REST (Representational State Transfer) based service that is primarily used in the AWS cloud for locating services for the purpose of load balancing and failover of middle-tier servers.

Basically, the Eureka infrastructure is set up as a client-server model. You can have one or multiple Eureka Servers and multiple Eureka Clients. It's a registry where clients (your microservices) can connect to (register), making your Eureka server aware of where your microservices are located, how many there are and if they're healthy or not.

As I have always done in my blog posts, I'll accompany this with a Github Repository serving the sole purpose of giving you a working example. 
It's the first time I'm doing a series of blog posts on the same subject. Therefore, I'll create branches for each part, which can individually be checked out. I'll try to keep everything up to date with the newest versions like I'm doing with all of my other examples.

Gradle Setup

My build tool of choice is Gradle, so the entire example will be based on a Gradle configuration. The configuration will consist of a parent, which will include all the microservices, who can be deployed individually. For this example, we'll only have one microservice (the Eureka Client) and one Eureka Service.

Our parent project will be just like a basic parent pom in maven and will facilitate the build of the entire project and microservices. I choose for this setup as it is easily approachable by someone who just wants to check out the code. Check out the Gradle structure in the repository. It's not hard to set this up, but it can be an example of how to set this up.

Eureka Server

By default, a Eureka server will also be a Eureka Client, trying to connect to the Registry.

application.yml - our configuration

In our setup, however, we want 1 main Eureka Discovery Service other clients can connect to. This is the minimal configuration we would need.

server:  
  port: 8761

eureka:  
  instance:
    hostname: localhost
  client:
    registerWithEureka: false
    fetchRegistry: false
    serviceUrl:
      defaultZone: http://${eureka.instance.hostname}:${server.port}/eureka/

EurekaServer.java - Bootstrap the application

@SpringBootApplication
@EnableEurekaServer
public class EurekaServer {

    public static void main(String[] args) {
        SpringApplication eurekaServer = new SpringApplication(EurekaServer.class);
        eurekaServer.addListeners(new ApplicationPidFileWriter("eureka-server.pid"));
        eurekaServer.run();
    }

}

Registering a Service

Registering a microservice is just as easy as creating a Eureka Server. Here's an example of the configuration.

server:  
  port: 9000

spring:  
  application:
    name: notification-service

eureka:  
  client:
    serviceUrl:
      defaultZone: http://localhost:8761/eureka/
  instance:
    preferIpAddress: true

All you need to register the application to the Eureka server would be

@SpringBootApplication
@EnableEurekaClient //or @EnableDiscoveryClient
public class NotificationMicroService {

    public static void main(String[] args) {
        SpringApplication notificationMicroService = new SpringApplication(NotificationMicroService.class);
        notificationMicroService.addListeners(new ApplicationPidFileWriter("notification-micro-service.pid"));
        notificationMicroService.run(args);
    }
}

Running the Example

We provided a startup script which you can build and run all the services. the only prerequisite is that you need Gradle in order for this to run.

./startup.sh

to stop the services, simply run

./stop.sh

Watching Our Services

By default, spring boot Netflix provides a UI on top of the Eureka Server. In our example, we've deployed it to http://localhost:8761/, so navigate to it and watch the health of your Eureka Server and Client.

You'll see something like this.

As you can see, after starting up the server and client, the notification service has registered itself.

Coming Up

This model of microservices that register themselves to a global registry will have a lot of advantages when it comes to building one or multiple applications using a microservice architectural approach. Eureka on its own won't have that much of use, but as you'll see in the future blog posts, Eureka will be the key element to locate all of our microservices.

The Github Repository

As we said before, this is not just an ordinary blog post. It's more of a guide on how to set up your environment to quickly start working with the discussed technology. That's why we're always making sure we have an accompanying GitHub repository available, so people can easily see how it works and have a working example at hand.

The repository that's accompanying this blog post is a bit different. Each time I'm releasing a new part of this series of blog posts, the repository will have a new branch, which will contain the new technology that will be discussed. In the end, I'll hope to come up with a nice example of how all the technologies can work together.

Spring Framework Spring Boot microservice POST (HTTP) Blog

Published at DZone with permission of Quinten De Swaef. See the original article here.

Opinions expressed by DZone contributors are their own.

Trending

  • Revolutionizing Algorithmic Trading: The Power of Reinforcement Learning
  • Reactive Programming
  • SRE vs. DevOps
  • Automating the Migration From JS to TS for the ZK Framework

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

Let's be friends: