no

Implement a Service Registry Using Netflix Eureka

Go Back to Course Outline Let’s go ahead and create our service registry project (terawarehouse-service-discovery). A service registry ...


Go Back to Course Outline

Let’s go ahead and create our service registry project (terawarehouse-service-discovery). A service registry like Netflix Eureka is a fixed point that allows the services to find and communicate with each other without knowing the hostname nor the port but with only the Spring application name. Eureka enables client-side load balancing and with a peer setup each client can act as a server as each client communicates and synchronize with each other.

Let’s start with:

  1. Setting up the Eureka Server - terawarehouse-service-discovery
  2. Create a new SpringBoot project.
  3. Add dependency to spring-cloud-starter-netflix-eureka-server which will provide the necessary dependencies to make this project a service registry server.
  4. Add dependencies spring-boot-starter-web and spring-boot-starter-actuator to let us display the server information.
  5. Annotate SpringBootApplication with EnableEurekaServer.
  6. Create an application.yml configuration file with 2 profiles. Notice that I use different network IP for each profile. Don’t register the eureka server as a client.
    1. instance1 - which we will deploy on our machine
    2. instance2 - which we will deploy on another machine
  7. Run the config server.
  8. Run 2 instances with different profiles.
  9. Check that they are a replica of each other.

Configuring the Client 

  1. Add dependency to spring-cloud-starter-netflix-eureka-client. This will provide the needed dependencies for this project to connect to the service discovery server.
  2. Annotate the SpringBoot class with EnableDiscoveryClient.
  3. And finally add the eureka client information to our project’s configuration:
    eureka.client.register-with-eureka: true
    eureka.client.fetch-registry: true
    eureka.client.service-url.defaultZone:
    http://192.168.1.100:8761/eureka,http://192.168.1.101:8761/eureka
    eureka.client.instance.prefer-ip-address: true
    eureka.client.instance.ip-address: 192.168.1.100
  4. Run the client.
  5. Check if the client properly registers with the eureka server.
Later on, as we introduce new microservices (inventory, order, etc) we can use this service registry for the catalog to send a request to the inventory or simply allow REST communication between them with only the spring application name.

In the next lesson, we will introduce a server-side load balancer that will receive the requests from a client and forward it to the appropriate API using the service discovery information.

I hope everything is clear to this point. You can always ask questions in the comment section below and I’ll be sure to address them.

If you want to get notified when I upload the next video, please subscribe to my channel and hit the bell icon. That will validate that what I’m doing is indeed helpful and will definitely inspire me to create more similar learning videos.

I hope to catch you in the next one. Thanks for watching and have a nice day. Bye.

References

Related

spring-microservice 6848575077118226745

Post a Comment Default Comments

item