Configuring Netflix Eureka Service Registry in Spring Cloud Applications

Establishing the Central Registry (Server)

The Eureka server acts as the backbone for service discovery within a distributed architecture. Initializing it requires pulling the appropriate Spring Cloud starter and applying the correct startup annotation.

Project Dependency

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.7.18</version>
    </parent>

    <groupId>io.docs.registry</groupId>
    <artifactId>eureka-registry-node</artifactId>
    <version>1.2.0</version>
    <packaging>jar</packaging>

    <properties>
        <java.version>17</java.version>
        <spring-cloud.version>2021.0.9</spring-cloud.version>
    </properties>

    <dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>org.springframework.cloud</groupId>
                <artifactId>spring-cloud-dependencies</artifactId>
                <version>${spring-cloud.version}</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
        </dependencies>
    </dependencyManagement>

    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-actuator</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-netflix-eureka-server</artifactId>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>
</project>

Bootstrap Entry Point

package io.docs.registry;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.netflix.eureka.server.EnableEurekaServer;

@EnableEurekaServer
@SpringBootApplication
public class RegistryApplication {
    public static void main(String[] args) {
        SpringApplication.run(RegistryApplication.class, args);
    }
}

Runtime Configuraton

server:
  port: 8761

spring:
  application:
    name: eureka-registry

eureka:
  client:
    # Prevent circular self-registration
    register-with-eureka: false
    fetch-registry: false
    service-url:
      defaultZone: http://localhost:8761/eureka
  instance:
    prefer-ip-address: true
    hostname: registry-host

Integrating Microservices (Client)

Application nodes register themselves automatically upon startup when equipped with the client starter. The following setup demonstrates a typical consumer service.

Client Dependencies

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.7.18</version>
    </parent>

    <groupId>io.docs.services</groupId>
    <artifactId>order-processing-svc</artifactId>
    <version>1.0.4</version>

    <properties>
        <java.version>17</java.version>
        <spring-cloud.version>2021.0.9</spring-cloud.version>
    </properties>

    <dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>org.springframework.cloud</groupId>
                <artifactId>spring-cloud-dependencies</artifactId>
                <version>${spring-cloud.version}</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
        </dependencies>
    </dependencyManagement>

    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-actuator</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
        </dependency>
    </dependencies>
</project>

Discovery Activation

package io.docs.order;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.netflix.eureka.EnableEurekaClient;

@EnableEurekaClient
@SpringBootApplication
public class OrderProcessingApplication {
    public static void main(String[] args) {
        SpringApplication.run(OrderProcessingApplication.class, args);
    }
}

Client Registration Properties

server:
  port: 0

spring:
  application:
    name: order-processing-svc

eureka:
  client:
    register-with-eureka: true
    fetch-registry: true
    service-url:
      defaultZone: http://localhost:8761/eureka
  instance:
    prefer-ip-address: true
    lease-renewal-interval-in-seconds: 30
    lease-expiration-duration-in-seconds: 90

Configuration Parameter Reference

Eureka exposes extensive tuning options through its underlying Java configuration beans. The tables below outline the most critical properties for production deployment.

Enstance Metadata & Heartbeat Settings

Property Key Default Value Behavior Description
spring.application.name unknown Logical identifier used as the virtual hostname and metadata grouping.
eureka.instance.prefer-ip-address false When true, publishes the container/OS IP adress instead of resolving DNS hostnames.
eureka.instance.lease-renewal-interval-in-seconds 30 Frequency at which the client sends heartbeat pings to acknowledge availability.
eureka.instance.lease-expiration-duration-in-seconds 90 Maximum tolerated silence duration before the server marks the instance as DOWN and evicts it.
eureka.instance.metadata-map {} Arbitrary key-value pairs attached to the registry record, accessible via discovery clients.
eureka.instance.health-check-url-path /health Relative path exposed by Actuator for liveness probes.

Client Discovery & Replication Logic

Property Key Default Value Behavior Description
eureka.client.enabled true Toggles the entire client-side registry initialization lifecycle.
eureka.client.registry-fetch-interval-seconds 30 Cache refresh cycle. Determines how often the client polls the server for updated service listings.
eureka.client.initial-instance-info-replication-interval-seconds 40 Delay applied before the very first metadata push to the registry occurs.
eureka.client.eureka-server-read-timeout-seconds 8 HTTP read timeout threshold for REST calls directed at the registry endpoints.
eureka.client.eureka-server-connect-timeout-seconds 5 Socket connection timeout when establishing TCP sessions to registry peers.
eureka.client.fetch-registry true If false, the node registers itself but never downloads the global service catalog (useful for pure servers).
eureka.client.should-unregister-on-shutdown true Sends an explicit DELETE request to the server upon JVM termination to trigger immediate eviction.

Server Eviction & Synchronization Policies

Property Key Default Value Behavior Description
eureka.server.enable-self-preservation true Activates protection mode. If heartbeats drop below threshold, the server stops deleting instances to prevent mass outage during network partitions.
eureka.server.renewal-percent-threshold 0.85 Percantage ratio of expected renewals. Falling below this value triggers self-preservation mode.
eureka.server.eviction-interval-timer-in-ms 60000 Interval between execution cycles of the background thread responsible for scanning and removing stale entries.
eureka.server.response-cache-update-interval-ms 30000 How frequently the internal read-only cache is regenerated from the active registry database.
eureka.server.peer-node-connection-idle-timeout-seconds 30 Duration allowed for HTTP connections between clustered registry nodes before teardown.
eureka.server.delta-retention-timer-interval-in-ms 30000 Cleanup frequency for incremental change queues used to optimize replication traffic between peers.

Monitoring Console Exposure

Property Key Default Value Behavior Description
eureka.dashboard.path / Base URL route mapping for the built-in administration console.
eureka.dashboard.enabled true Switches rendering of the UI interface on and off.

Tags: spring-cloud-netflix-eureka microservices-registry spring-boot-configuration java-distributed-systems service-discovery-pattern

Posted on Sat, 23 May 2026 20:45:31 +0000 by Space Cowboy