Javatpoint Logo
Javatpoint Logo

Connecting Microservices to Eureka naming server

In this section, we will connect the currency-conversion-service and currency-exchange-service to the Eureka naming server.

First, we will connect the currency-conversion-service.

Step 1: Select the currency-conversion-service project.

Step 2: Open the pom.xml file and add the eureka-client dependency.

Step 3: Open CurrencyConversionServiceApplication.java file and enable discovery client by using the annotation @EnableDiscoveryClient.

CurrencyConversionServiceApplication.java

After enabling the discovery client, configure the URL for the Eureka naming server.

Step 4: Open the application.properties file and configure the URL for the Eureka naming server.

application.properties

If we look at the Eureka UI, we see that there is no instance registered with the Eureka server.

Step 5: Run the CurrencyConversionServiceApplication.java file.

Step 6: Open the browser and refresh the Eureka server page. It shows the instances of registered microservices.

Connecting Microservices to Eureka naming server

We see that an instance of currency-conversion-service is registered with the Eureka naming server, and running on port 8100.

Let's connect currency-exchange-service with Eureka naming server.

Step 1: Select the currency-exchange-service project.

Step 2: Open the pom.xml file and add the eureka-client dependency.

Step 3: Open CurrencyExchangeServiceApplication.java file and enable the discovery client by using the annotation @EnableDiscoveryClient.

CurrencyExchangeServiceApplication.java

Step 4: Open the application.properties file and configure the URL for Eureka naming server.

application.properties

Step 5: Run the two instances of CurrencyExchangeServiceApplication.java. First instance on port 8000 and the second instance on port 8001.

Step 6: Open the browser and refresh the Eureka server. It shows the registered microservice.

Connecting Microservices to Eureka naming server

We see that the two instances of currency-exchange-service are registered with the Eureka naming server. The two instances are running on port 8001 and 8000.

In the following image, we can see that both the microservices has registered with the Eureka naming server.

Connecting Microservices to Eureka naming server





Help Others, Please Share

facebook twitter pinterest

Learn Latest Tutorials


Preparation


Trending Technologies


B.Tech / MCA