Service Registration and Discovery :: Learn how to register and find services with Eureka
Clone or download


This guide walks you through the process of standing up and consuming the Netflix Eureka service

What you’ll build

You’ll setup a Netflix Eureka service registry and then build a client that both registers itself with the registry and uses it to resolve its own host. A service registry is useful because it enables client-side load-balancing and decouples service providers from consumers without the need for DNS.

Build with Gradle

Build with Gradle





Build with Maven

Build with Maven





Stand up a Eureka Service Registry

You’ll first need a Eureka Service registry. You can use Spring Cloud’s @EnableEurekaServer to standup a registry that other applications can talk to. This is a regular Spring Boot application with one annotation added to enable the service registry.



When the registry starts up it will complain, with a stacktrace, that there are no replica nodes for the registry to connect to. In a production environment, you will want more than one instance of the registry. For our simple purposes, however, it sufficies to disable the relevant logging.

By default, the registry will also attempt to register itself, so you’ll need to disable that, as well.

It’s a good convention to put this registry on a separate port when using it locally.

Add some properties to your eureka-service/src/main/resources/ to handle all of these requirements.



Talking to the Registry

Now that we’ve stood up a service registry, let’s stand up a client that both registers itself with the registry and uses the Spring Cloud DiscoveryClient abstraction to interrogate the registry for it’s own host and port. The @EnableDiscoveryClient activates the Netflix Eureka DiscoveryClient implementation. There are other implementations for other service registries like Hashicorp’s Consul or Apache Zookeeper.



Whatever implementation you choose, you’ll soon see the eureka-client registered under whatever name you specify in the property. This property is used a lot in Spring Cloud, often in the earliest phases of a service’s configuration. This property is used in service bootstrap and so by convention lives in eureka-client/src/main/resources/ where it’s found before src/main/resources/



The eureka-client defines a Spring MVC REST endpoint, ServiceInstanceRestController, that returns an enumeration of all the ServiceInstance instances registered in the registry at http://localhost:8080/service-instances/a-bootiful-client. Consult the Building a RESTful Web Service guide to learn more about building REST services with Spring MVC and Spring Boot.

Test the application

Test the end-to-end result by starting the eureka-service first and then, once loaded, starting the eureka-client. The eureka-client will take about a minute to register itself in the registry and to refresh its own list of registered instances from the registry. All of these thresholds are configurable. Visit the eureka-client in the browser, http://localhost:8080/service-instances/a-bootiful-client. There, you should see the ServiceInstance for the eureka-client reflected in the response.


Congratulations! You’ve just used Spring to stand up a Netflix Eureka service registry and to use that registry in a client application.