Using Netflix Eureka with Spring Cloud

In the world of microservices it becomes more and more important to easily find / locate services. They can run anywhere in the cloud, even and often multiple times (multiple instances per service). Fortunately Netflix did open source some of its great internal tools that can help us with these problems.

The is about using an Eureka server to maintain a registry of microservices. All with the help of the spring cloud project.

BTW: When you search for infos about eureka you can discover funny things!

Setting up an Eureka registry

Eureka can run standalone. You can download the code and build the war file, put it on a web container and run it.

If you are running spring boot applications, there is an equally easy way of running it:

Create a spring boot application with dependency to spring-cloud-eureka


and a starter class

public class EurekaApplication {

	public static void main(String[] args) throws Exception {, args);


and your registry is a spring boot application. See this great example for details. There is even a docker container with it.

For my project I started by using this docker container and ended up having my own spring boot application inside a docker container. Mainly because I needed to fine tune to JVM settings (memory set to only 256MB).


Securing an eureka instance is quite easy.


Add the following dependency to your pom:


Add the following to its application.yml:

    enabled: true
      name: myuser
      password: mypassword

You probably can use any spring security solution here (see this github examples). But basic auth makes it quite simple to use in the client:

      defaultZone: http://myuser:mypassword@localhost:8761/eureka/


Since we should not send the authentication in plain text over the line, we need to switch the eureka server to SSL:

  port: 8761
    key-store: eureka-server/keystore.jks
    key-store-password: password
    key-password: password
    clientAuth: want

You can create the self-signed certificate with

keytool -genkey -keyalg RSA -alias selfsigned -dname "cn=Test Cert, ou=MOSERP, o=ORG" -keystore keystore.jks -storepass password -validity 360 -keysize 2048 -keypass password

You have to import it into your environment or configure your JVM to use it. See these docs for examples.

Service Naming

I found out that it is wise to name services like domain names. Spring let you use service names in RestTemplates or FeignClients and some of them check for valid URLs before querying the registry.

For example for MOS ERP the domain is used as base name, with services having names like . This could even be migrated to a DNS based service registry.


For spring boot clients, add the following maven dependency


And the following lines to the bootstrap.yml:

    nonSecurePort: ${server.port:9301}
    preferIpAddress: true
    statusPageUrlPath: /structure
      defaultZone: ${EUREKA_URL:http://localhost:8761}/eureka/

To activate discovery client your spring boot application class should look like

public class Application {

    public static void main(String[] args) {, args);

Other Clients

The eureka server exposes a simple REST api. That can be used from any program to check for registering or querying services.