Registering microservices with Eureka

To register any microservice with the Eureka Name server, we would need to add the dependency on Eureka Starter project. The following dependency needs to be added to the pom.xml file of Microservice A:

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

The next step is to add EnableDiscoveryClient to the SpringBootApplication classes. An example of MicroserviceAApplication is shown here:

    @SpringBootApplication
@EnableDiscoveryClient
public class MicroserviceAApplication {
Spring Cloud Commons hosts the common classes used in different Spring Cloud implementations. A good example is the @EnableDiscoveryClient annotation. Different implementations are provided by Spring Cloud Netflix Eureka, Spring Cloud Consul Discovery, and Spring Cloud Zookeeper Discovery.

We will configure the URL of the naming server in the application configuration. For Microservice A, the application configuration is in the local Git repository file, git-localconfig-repomicroservice-a.properties:

    eureka.client.serviceUrl.defaultZone=
http://localhost:8761/eureka

When both instances of Microservice A are restarted, you will see these messages in the log of Eureka Server:

    Registered instance MICROSERVICE-A/192.168.1.5:microservice-a
with status UP (replication=false)
Registered instance MICROSERVICE-A/192.168.1.5:microservice-a:
8081 with status UP (replication=false)

A screenshot of the Eureka Dashboard at http://localhost:8761 is shown as follows:

Two instances of Microservice A are now registered with Eureka Server. Similar updates can be done on Config Server in order to connect it to Eureka Server.

In the next step, we would want to connect the service consumer microservice to pick up URLs of instances of Microservice A from the Eureka server.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset