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 ...
https://www.czetsuyatech.com/2019/10/spring-microservice-service-registry-using-nextflix-eureka.html
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:
- Setting up the Eureka Server - terawarehouse-service-discovery
- Create a new SpringBoot project.
- Add dependency to spring-cloud-starter-netflix-eureka-server which will provide the necessary dependencies to make this project a service registry server.
- Add dependencies spring-boot-starter-web and spring-boot-starter-actuator to let us display the server information.
- Annotate SpringBootApplication with EnableEurekaServer.
- 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.
- instance1 - which we will deploy on our machine
- instance2 - which we will deploy on another machine
- Run the config server.
- Run 2 instances with different profiles.
- Check that they are a replica of each other.
Configuring the Client
- 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.
- Annotate the SpringBoot class with EnableDiscoveryClient.
- 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 - Run the client.
- Check if the client properly registers with the eureka server.
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.
Post a Comment