Setting up Eureka naming Server and integrating with Config Server

Setting up Eureka naming Server and integrating with Config Server

In the last article, we have seen how to set up a config server using a spring cloud environment. https://pinepad.in/java/spring-boot/what-are-microservices/
Now we will be going to see how to set up the Eureka naming server. I have explained What is a Eureka server in my previous article, The link is Here 
Eureka Server is again Spring Boot Application We need to create a Spring Boot application by selecting the following startup project.
Select the following dependency as mentioned in the Screenshot and apart from you need to add the following starter project in your pom.xml

	org.springframework.cloud
	spring-cloud-starter-bootstrap


Generate the project and import the project in your favorite IDE. as mentioned in the screenshot. Remove the application. properties. After successful import, my project looks like this

I have done following changes in the project. I have renamed main file to “Application.java” (no need to change). in the applicatoin.properties file I have added following entries.

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

Then, Application.java file i have added @EnableEurekaServer as below

@EnableEurekaServer
@SpringBootApplication
public class Application {

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

}

Once started the Eureka Server, We can access the Eureka Server Dashboard by using the following endpoint
http://localhost:8761/
and you will be getting the following screens as in the screenshot.

When you look at the dashboard it shows that the eureka server itself registered as Eureka client but we don’t want this configuration. add the following attribute in properties files to ignore this config.

eureka.client.register-with-eureka=false
eureka.client.fetch-registry=false

Now we have successfully set up the Eureka Server. but We have not configured the properties in Config Server. Then, we have to register the config Server in Eureka Service. These two tasks is pending now. First, we will see how to read the Eureka configuration from Config Service. 
Make sure that your config service application.yml file is having the following section of configuration.

cloud:
  config:
    server:
      git:
        uri: file:///d:\test

Go to your Eureka Server and create a new file called bootstrap. properties file. In this file, you have to mention. the Eureka server application name and config Service access endpoint like below.

spring.application.name=service-registry
spring.cloud.config.uri=http://localhost:8888

The meaning of this configuration is, your service registry application name is service-registry, and pointing out config service endpoint, using this endpoint eureka server loads all configuration details from GIT Hub Repository. In the git-hub repository, you have to create a service-registry.yml file that matches your application name in the bootstrap.properties file.

In the Service Registry application, you have to add the following artifact. This starter bootstrap is mandatory to load config data from the config Server.

<dependency>
   <groupId>org.springframework.cloud</groupId>
   <artifactId>spring-cloud-starter-bootstrap</artifactId>
</dependency>

While creating the Eureka service from https://start.spring.io/ we have already added the following dependency apart from this dependency you need to add the above dependency(spring-cloud-starter-bootstrap)

<dependency>
   <groupId>org.springframework.cloud</groupId>
   <artifactId>spring-cloud-starter-config</artifactId>
</dependency>

In the Eureka Service Application, we don’t need the application properties file. remove that properties file from the project and test folder we must keep the service.registry.yml file with the following configuration.

server:
  port: 8761
spring:
  application:
    name: service-registry
billing:
  app: This is billing App Service Discovery default service
eureka:
  client:
    register-with-eureka: false
    fetch-registry: false

Make sure this file committed to your local git repository. First, start the Config Service and start the Eureka Naming Service(we name it as registry-service) 
After a successful start of the Sever, you see the Eureka naming server dashboard like a blow.

Now we will going to start how to register Config Service in our Eureka naming Server. In order to do that you have to add the following starter project in the Service-registry application. that’s it you have done now. Whenever you start config service, The eureka server register this service in the eureka registry.

<dependency>
   <groupId>org.springframework.cloud</groupId>
   <artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
</dependency>

Let’s restart the config Service and test it. Once you start the config service you can see the following additional output in your Server console which says that the eureka server registers the config service in the Eureka service.

If you refresh the following eureka server endpoint you will be seeing config service registration details like below
http://localhost:8761/

We have successfully set up the Config Service and Eureka Service. In the next post, we will be going to setup the following service which s an account-service, product-service and reporting-service where we implement our business functionality and this server registered Eureka server and load the properties from config Service

=================================================================
Healthy Women makes healthy India. Buy Organic Sanitary napkin made up of using pure cotton and bamboo fiber.
Pure cotton XL Size

Pure Cotton XXL Size

Pure Bamboo XL Size

Pure Bamboo XXL Size

 

Close Menu
×
×

Cart