Microservices Part 01: Creating Service Registry Application

In order to create a Microservices Application we will first require a Service Registry which is nothing but a special kind of microservice that will have a list of microservices registered inside it. There are total three steps to create a Service Registry. Step1: We are going to write our Service Registry microservice application using the spring-cloud-starter-netflix-eureka-server dependency. 4.0.0 org.springframework.boot spring-boot-starter-parent 3.4.1 com.sky service-registry 1.0 service-registry Registry for Job Portal Application 21 2024.0.0 org.springframework.boot spring-boot-starter-web org.springframework.cloud spring-cloud-starter-netflix-eureka-server org.springframework.boot spring-boot-starter-test test org.springframework.cloud spring-cloud-dependencies ${spring-cloud.version} pom import org.springframework.boot spring-boot-maven-plugin service-registry/pom.xml Step 2: Now, we need to also include the annotation @EnableEurekaServer to notify that this particular application will act as a Registry Server. package com.sky.service_registry; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.cloud.netflix.eureka.server.EnableEurekaServer; @SpringBootApplication @EnableEurekaServer public class ServiceRegistryApplication { public static void main(String[] args) { SpringApplication.run(ServiceRegistryApplication.class, args); } } service_registry/ServiceRegistryApplication.java Step 3: We need to also specify the below details. To tell Spring to not register this application as a microservice. As all the other microservices will be registered inside this special microservice. spring.application.name=service-registry server.port=8761 eureka.instance.hostname=localhost eureka.client.register-with-eureka=false eureka.client.fetch-registry=false /service-registry/src/main/resources/application.properties Step 4: We will create a new microservice and try to register it in the Service Registry that was created in the previous steps. We need to add the spring-cloud-starter-netflix-eureka-client dependency in our pom.xml of the new microservice in order to make it available/discoverable for registeration in the Service Registry. org.springframework.boot spring-boot-starter-web org.springframework.cloud spring-cloud-starter-netflix-eureka-client org.springframework.boot spring-boot-starter-test test Step 5: Also, we have to add below configuration for newly created microservice to specify the url for eureka server i.e. our Service Registry. spring.application.name=job-search-service server.port=8762 eureka.client.service-url.defaultZone=http://localhost:8761/eureka Step 6: Now, make sure the Service Registry and the newly created microservice is running. To validate if the registration is success we can go to the Eureka Server URL(http://localhost:8761/) and locate the new microservice name there as shown in below snapshot. Stay tuned for the next part of the Microservices Blog. Thanks for reading!

Jan 16, 2025 - 20:19
Microservices Part 01: Creating Service Registry Application

In order to create a Microservices Application we will first require a Service Registry which is nothing but a special kind of microservice that will have a list of microservices registered inside it.

There are total three steps to create a Service Registry.

Step1: We are going to write our Service Registry microservice application using the spring-cloud-starter-netflix-eureka-server dependency.


    4.0.0
    
        org.springframework.boot
        spring-boot-starter-parent
        3.4.1
         
    
    com.sky
    service-registry
    1.0
    service-registry
    Registry for Job Portal Application
    
    
        
    
    
        
    
    
        
        
        
        
    
    
        21
        2024.0.0
    
    
        
            org.springframework.boot
            spring-boot-starter-web
        
        
            org.springframework.cloud
            spring-cloud-starter-netflix-eureka-server
        

        
            org.springframework.boot
            spring-boot-starter-test
            test
        
    
    
        
            
                org.springframework.cloud
                spring-cloud-dependencies
                ${spring-cloud.version}
                pom
                import
            
        
    

    
        
            
                org.springframework.boot
                spring-boot-maven-plugin
            
        
    


service-registry/pom.xml

Step 2: Now, we need to also include the annotation @EnableEurekaServer to notify that this particular application will act as a Registry Server.

package com.sky.service_registry;

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

@SpringBootApplication
@EnableEurekaServer
public class ServiceRegistryApplication {

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

}
service_registry/ServiceRegistryApplication.java

Step 3: We need to also specify the below details. To tell Spring to not register this application as a microservice. As all the other microservices will be registered inside this special microservice.

spring.application.name=service-registry
server.port=8761

eureka.instance.hostname=localhost
eureka.client.register-with-eureka=false
eureka.client.fetch-registry=false
/service-registry/src/main/resources/application.properties

Step 4: We will create a new microservice and try to register it in the Service Registry that was created in the previous steps.

We need to add the spring-cloud-starter-netflix-eureka-client dependency in our pom.xml of the new microservice in order to make it available/discoverable for registeration in the Service Registry.

    
        
            org.springframework.boot
            spring-boot-starter-web
        
        
            org.springframework.cloud
            spring-cloud-starter-netflix-eureka-client
        

        
            org.springframework.boot
            spring-boot-starter-test
            test
        
    

Step 5: Also, we have to add below configuration for newly created microservice to specify the url for eureka server i.e. our Service Registry.

spring.application.name=job-search-service
server.port=8762

eureka.client.service-url.defaultZone=http://localhost:8761/eureka

Step 6: Now, make sure the Service Registry and the newly created microservice is running. To validate if the registration is success we can go to the Eureka Server URL(http://localhost:8761/) and locate the new microservice name there as shown in below snapshot.

Eureka Server Snapshot

Stay tuned for the next part of the Microservices Blog.
Thanks for reading!