santteegt / spring-cloud-zookeeper-service-discovery-demo

Tutorial using docker compose to present an spring cloud zookeeper service discovery demo

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

spring-cloud-zookeeper-service-discovery-demo

Tutorial using docker compose to present a hands-on session on how to use spring cloud zookeeper for service discovery.

How is works ?

This tutorial includes two (Spring Boot) microservices called GreetingMicroservice and GreetingConsumer. So, the aim of this tutorial is to demonstrate how a consumer can discover the Greeting service through Apache Zookeeper and Apache Curator Service Discovery. The latter can be easily implemented in Spring Boot applications using the Spring Cloud Zookeeper API. We also used Netflix Feign for writing the REST consumer behavour. Finally, for this demonstration, we use a Zookeeper instance with 2 nodes (see Docker Compose).

Installation Instructions

  1. Requirements
  • Docker 3.2+
  1. Run the following commands
$ git clone <REPO_GIT_URL>
$ cd spring-cloud-zookeeper-service-discovery-demo
$ docker-compose up 

Checking everything works

Once the compose is deployed, make a request using the consumer microservice by accesing the following URL: http://localhost:8180/get-greeting

Implementation notes

GreetingMicroservice

  • GreetingMicroservice has the SimpleController class which implements an Spring Boot application and specify the @EnableDiscoveryClient annotation to automatically enable the Discovery Client implementation and register the service in a zookeeper instance.
  • The spring.cloud.zookeeper.connect-string 'spring.application.name' must be specificed in the application.yml file.

GreetingConsumer

  • The ServiceConsumerClient class manages the communication with the Service Discovery by implementing a REST call using a FeignClient and the service name specified in the GreetingMicroservice's application.yml file.

About

Tutorial using docker compose to present an spring cloud zookeeper service discovery demo

License:Apache License 2.0


Languages

Language:Java 78.0%Language:Dockerfile 22.0%