1. 程式人生 > >How to Use Netflix’s Eureka and Spring Cloud for Service Registry

How to Use Netflix’s Eureka and Spring Cloud for Service Registry

How to Use Netflix’s Eureka and Spring Cloud for Service Registry

One of the main tenets of the microservice architecture pattern is that a set of loosely-coupled, collaborating services works together to form a cohesive, whole application. In this way, it’s not so much about the individual services, it’s more about ensuring the interactions between the services remains reliable and failure-tolerant.

What this means in practice, is removing hard-coded information and replacing them with dynamically updating environment variables, having separate databases for each service, removing as much dependency between services as possible (so if necessary, a service that needs more instances can easily scale without impacting its counterparts), and generally decreasing the complexity of managing the whole by increasing the complexity of each individual service.

It sounds like a good strategy, but keeping track of all the smaller pieces of the whole makes it a burden on the client to manage all of this.

Which brings me to the topic of my blog today: the Netflix Eureka service registry — and how to use it with Spring Cloud to more effectively manage this complexity.

As the Github repo for Netflix’s Eureka registry says itself:

“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.” — Netflix: Eureka at a Glance, Github

Sounds good? Good. Without further ado, let’s get to setting up this Eureka service registry and a couple of services to see it in practice.

Setting Up the Eureka Server

Setting up a Spring-based Eureka server is actually, very simple. Spring.io, itself, has a great walkthrough here, that helped get me up and running quickly with both a Eureka server and a sample Spring Boot project.

I won’t go through the step-by-step, as you can do that with the tutorial I linked to, or you can download my working example here. But I will highlight the important things to include for the server setup.

Build.gradle File