Skip to main content

Financial Services

Tutorial 02 – Spring Cloud – Netflix Eureka Server

What To Consider Before Leaping Into Microservices
You may learn microservices in-depth from beginner to expert in this set of tutorials.

click here for previous blog: – Tutorial 01 – Microservices Architectural Design by using Spring Boot

Introduction: –

Netflix Eureka Server – To enable discovery and communication between microservices, it is necessary to register or publish the microservice with the R&D (Registrar and Discovery) server.

  • Each R&D server is a Spring Boot project with dependencies on other R&D servers. No installation is required, unlike with Tomcat, Wildfly, and other programs.
  • Registration activity is the process of storing/publishing microservice details in the R&D server.
  • Discovery Operation is the process of finding/fetching microservice details from an R&D server in order to communicate with or interact with another microservice.

The details appear as follows when we publish several instances of various microservices to an R&D server like Eureka Server.

Diagram: – Eureka Server Internal Structure.

Eurekaserver

  • Document-less servers, like Eureka Server, are known. To put it another way, the server does not contain any XML or JSON files.
  • Every time, the Service ID (also known as the Service Name) is the Project name.
  • Instance ID is the unique ID. For every instance one unique instance ID will be generate.
  • When a single instance is present, we shall not supply the instance ID. Service ID is used as the instance ID in that case.
  • During the registration and publication process, Eureka Server automatically detects the host name and port information.

Load Factor = Current Load / Max Load

Diagram: – Eureka Server

Eurekainstance

Procedure to create Spring Boot project acting as Eureka Server

1: –

  • Create Spring Boot Project adding Eureka Server as dependencies.

Note: – Do not add Spring Web Starter by mistake.

 

EurekaprojectDependency

 

2: –

  • Add @EnableEurekaServer on the top of Main class.
package com.eureka;

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

@SpringBootApplication
@EnableEurekaServer
public class MsProj01EurekaServerApplication {

    public static void main(String[] args) {
        SpringApplication.run(MsProj01EurekaServerApplication.class, args);
    }

}

3: –

  • Enter the following data in the application.properties that prevent the project from becoming a microservice and instead display it as an R&D server.
    #Eureka Server port number
    server.port=8761
    
    #MS name
    spring.application.name=MS-EurekaServer
    
    eureka.client.fetch-registry=false       // Mandatory to make this project itself as
    eureka.client.register-with-eureka=false // the Eureka Server and not as Rest API component.
  • Default port number for Eureka Server 8761.
  • The fetch-registry and register-with-eureka attributes have true as their default value.

Eureka Server Architecture

Eureka Architecture

  • Each microservice needs to be prepared in order to register with the Eureka Server. Due to the fact that Eureka Server itself cannot be registered with Eureka Server. For the “eureka.client.register-with-eureka” property, we must set the default value of “true” inherited from the Spring Cloud project to “false” in the Eureka Sever Project.
  • While registering with the Eureka server, each microservice project should be kept prepared for communication and discovery. The default value of “true” for “eureka.client.fetch-registry” in the Spring Cloud Project must be changed to “false” in the Eureka Server Project since the Eureka Server project cannot be kept available for fetching or discovery.

 

The forthcoming tutorial will cover Eureka Server and Eureka Client development and publication.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Bhushan Patil

Bhushan Patil is a passionate Java developer with 4+ years of experience building and maintaining high-performing web applications. He thrives in collaborative environments and possesses a strong ability to translate complex business requirements into clean, maintainable, and scalable Java code. Bhushan has a proven track record of success in designing and implementing RESTful APIs using Spring Boot and microservices and integrating them with various databases (e.g., Oracle and MongoDB). He is also well-versed in front-end technologies like JavaScript and proficient in unit testing frameworks like JUnit. He achieved this by optimizing code for performance, implementing robust security measures, and ensuring a seamless user experience. Bhushan is a continuous learner and stays updated with the latest advancements in the Java ecosystem.

More from this Author

Follow Us