➤ How to Code a Game
➤ Array Programs in Java
➤ Java Inline Thread Creation
➤ Java Custom Exception
➤ Hibernate vs JDBC
➤ Object Relational Mapping
➤ Check Oracle DB Size
➤ Check Oracle DB Version
➤ Generation of Computers
➤ XML Pros & Cons
➤ Git Analytics & Its Uses
➤ Top Skills for Cloud Professional
➤ How to Hire Best Candidates
➤ Scrum Master Roles & Work
➤ CyberSecurity in Python
➤ Protect from Cyber-Attack
➤ Solve App Development Challenges
➤ Top Chrome Extensions for Twitch Users
➤ Mistakes That Can Ruin Your Test Metric Program
Spring Cloud Netflix Eureka Server | We will see how the Spring Cloud Netflix Eureka server works in Microservices with examples.
- Microservice Application is implemented using multiple components.
- The Microservice app is coded using Spring ReST (@RestController) with operations like GET, POST, PUT, DELETE, etc.
- Once the Microservice code is completed it must be published with the R&D (Registry & discovery) Server. For this we use
Spring Cloud Netflix Eureka
.
Important points about Spring Cloud Netflix Eureka
:-
- Eureka will not make HTTP calls to any Microservice.
- Eureka will store Microservice’s data and share one Microservice data with another Microservice.
- Data Stored inside Eureka is called Service Instances.
Service Instance = service ID + Instance ID + HOST + PORT + Load Factor
- Service Id = Project name given in
spring.application.name
- Instance Id = A random number given to instance
- HOST = System IP/name
- PORT = Service PORT number
- Load Factor = Current Load/Max Load
ServiceId | InstanceId | Host | Port | Load Factor |
---|---|---|---|---|
SEARCH-APP | SA-5210256 | 192.168.0.10 | 9696 | 0/200 |
SEARCH-APP | SA-0056250 | 192.168.2.32 | 8080 | 0/200 |
CART-APP | CA-8840856 | 202.6.11.109 | 8550 | 0/200 |
CART-APP | CA-8840800 | 208.16.50.12 | 9669 | 0/200 |
In the above table, one line is called one Service Instance.
One Microservice (Module) wants to communicate with another Microservice (Module) Such a process is called ‘Internal/Intra Communication’ to exchange data.
To do intra-communication on the Consumer application side we should write code using one of the below client components:-
- DiscoveryClient + RestTemplate (outdated)
- LoadBalancerClient + RestTemplate
- FeignClient (interface/abstract client) (It is the most commonly used, and it is most fastest client compared to the above clients).
Normal Webservices
Microservice#1 | Microservice#2 |
---|---|
Consumer | Producer |
RestTemplate | RestController |
The above clients go to Eureka to get the Service Instance of Less Load Factor and make HTTP calls using RestTemplate.

How to Register MicroServices with the Eureka Registry Server
We need to publish/register our microservice with the Eureka server. To do this add key value eureka.client.register-with-eureka=true
in the properties file.
Do we need to publish/register our microservice with Eureka Server?
Yes. By adding key:- eureka.client.register-with-eureka=true
. When you set eureka.client.register-with-eureka=true
, it ensures that your microservice registers itself with the Eureka server. This registration is crucial for service discovery, allowing other microservices to find and communicate with it. If you don’t set this key to true
, your microservice won’t be registered with the Eureka server. As a result, other microservices won’t be able to discover and communicate with it through Eureka. The default value of eureka.client.register-with-eureka
is true
.
Can our microservice fetch data of other microservices from the Eureka Server?
Yes. By adding key:- eureka.client.fetch-registry=true
. Setting eureka.client.fetch-registry=true
allows your microservice to fetch the registry information from the Eureka server. This means your microservice will be able to retrieve the list of all registered microservices and their instances, enabling it to discover and communicate with them. If you don’t set this key to true
, your microservice won’t fetch the registry, and it won’t be able to discover other services registered with Eureka. The default value of eureka.client.fetch-registry
is true
.
If we don’t register microservices with Eureka then when other microservices try searching for them they won’t be able to find them. So for intra-communication, we must register microservices with Eureka.
Since the default value for eureka.client.register-with-eureka
and eureka.client.fetch-registry
is true
therefore we don’t have to add this key explicitly in every microservices properties file. But if we want to disable them then we have to add this key by setting the value false
.
Eureka Server Configuration
- Create a new spring starter project
SpringCloudEurekaServer
with dependencies:- Eureka Server (spring-cloud-starter-netflix-eureka-server
). - In the starter class add the annotation:-
@EnableEurekaServer
- For
application.properties
file:-
Can the Eureka server register with the Eureka server itself and fetch data from Eureka itself?
No. Eureka server (project: SpringCloudEurekaServer
) is also a microservice, but it doesn’t have to register it with itself. The default value for eureka.client.register-with-eureka
and eureka.client.fetch-registry
are true
. Eureka Server should not do register and fetch from itself. So we must modify these keys with the value false
.
In application.properties
file:-
# Eureka server recommended port number is 8761
server.port=8761
# Eureka server itself should not be register and fetch data
eureka.client.register-with-eureka=false
eureka.client.fetch-registry=false
- Run the main class and enter the URL:- http://localhost:8761/
- Stop the Application.
Also see:- Intra-communication Between Microservices in Spring using Eureka Server
Spring Cloud
Can one Java class have multiple superclasses? No, Java doesn’t support multiple inheritance through classes. But a Java class contains a HAS-A relationship with multiple classes.
class A { }
class B { }
class C extends A, B { } // not possible
// valid
class C extends A {
B obj; // HAS-A
}
Similarly, Can one maven Project have multiple Parents? No. One Maven project can have at max one Parent Project. However, another maven project can be added as BOM (Bill Of Materials) (or <dependencyManagement>
).
For normal Spring Boot projects, spring-boot-starter-parent
is the parent project that contains pre-defined code JDBC, JPA, Schedule, and declaration for Web MVC, Rest, etc.
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>3.2.9-SNAPSHOT</version>
<relativePath/>
</parent>
Similar to spring-boot-starter-parent
, spring-cloud-dependencies
is there. The spring-cloud-dependencies
contains the declaration of Eureka, Config server, Ribbon, Zuul, etc.
To work with Spring Cloud we need both spring-boot-starter-parent
, and spring-cloud-dependencies
. Since one maven project can’t have multiple parents therefore pivotal team (Spring dev team) made spring-boot-starter-parent
as a parent project and spring-cloud-dependencies
as <dependencyManagement>
.
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>3.2.9-SNAPSHOT</version>
<relativePath/>
</parent>
<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>
Every Cloud Application, Eureka, Config server, Microservices, Zuul, etc contains one common parent project used as BOM. Given as: spring-cloud-dependencies
.
It provides common keys, code, config, jars, objects, etc to all Cloud Micro Services/Eureka/etc applications.
Intra-communication of Micro Services can be implemented using Client codes. There are 3 types:-
- DiscoveryClient + RestTemplate
- LoadBalancerClient + RestTemplate
- Open Feign | Feign Client | Abstract Client
Client code will:-
- First, go to Eureka with Provider Application ServiceID.
- Fetch the ServiceInstance object from Eureka.
- Then create a URL using host, port, and path.
- Make an HTTP call to the provider application.
- Get the response back and give it to RestController.

How can we provide serviceId and instanceId to Micro Services? By using Project name we can give serviceId.
# ServiceId
spring.application.name=<project-name>
And to provide instanceId:-
eureka.instance.instance-id=<any-number>
What does a ServiceInstance object contain? ServiceInstance contains ServiceId + InstanceId + Host + Port + Load Factor.
If you enjoyed this post, share it with your friends. Do you want to share more information about the topic discussed above or do you find anything incorrect? Let us know in the comments. Thank you!