Skip to content

danielcasique/building-microservices

Repository files navigation

Building microservices

About

This is an implementation of https://www.youtube.com/watch?v=ZyK5QrKCbwM using the bellow versions:

  • org.springframework.boot 2.0.5.RELEASE
  • org.springframework.cloud Finchley.SR1
  • Java 11

Architecture

Building microservices architecture

config-server

Uses the spring-cloud-config-server in order to allow other modules to get the properties from a centralized site. The folder microservices-config contains the properties files for the modules eureka-service, reservation-client, reservation-service, and hystrix-dashboard. This folder could be located in the github repository or in a local system. The property spring.cloud.uri must be modified according to this set up. If the folder microservices-config is located in a local system, it must be initialized as a git hub repository anyway. (Just use git init)

eureka-service

Uses the spring-cloud-starter-netflix-eureka-server to enable a server for registering, discovering and load balancing microservices. (more info).
The service connects to config-server to get all properties, but it needs to set up inside the module all the properties to connect to config-server. (in the application.properties file)

reservation-service

Spring boot application that exposes services for saving a reservation, list reservations and get a message. The service connects to config-server to get all properties, but it needs to set up inside the module all the properties to connect to config-server. (in the application.properties file). Also, in the config-server is defined the properties to connect to Kafka and exposes the actuator endpoints.
The reservation-service is listening to receive any data coming from Kafka service and save a reservation.

reservation-client

It uses spring-cloud-starter-netflix-zuul to create a proxy server. The service connects to config-server to get all properties, but it needs to set up inside the module all the properties to connect to config-server. (in the application.properties file). Also, in the config-server is defined the properties to connect to Kafka, exposes the actuator endpoints, and define the routes for Zuul service.
The reservation-client exposes the POST service reservations, which recive the data and send it to a Kafka service.
Here more info about how to implement a kafka client (producers and consumers).
Here more infor about how to implement Netflix-Zuul.

hystrix-monitor

To support the tolerance, and monitor the services status. (more info and here).
The reservations-service and reservation-client active the hystrix by using the tags @EnableCircuitBreaker and @HystrixCommand.
The service connects to config-server to get all properties, but it needs to set up inside the module all the properties to connect to config-server. (in the application.properties file)

kafka

It's a docker image. The docker compose file is located at kafka folder (more info)

Zipkin

It's docker image to monitor services (more info)

How to run (Locally)

Prerequisites

  • Set up java 11
  • Set up/Install docker (more info)
  • Install docker-compose (not needed on Windows)
  • In the config-server module, it's needed to update the property spring.cloud.config.server.git.uri in the application.properties according with the locally in the current enviorment. The folder microservices-config must be a git repository if you want to use a local folder.

Steps to run

  1. Start the kafka docker image. Go to kafka folder and execute the below command: docker-compose up -d
  2. Start the Zipkin docker image by executing the below command: docker run -d -p 9411:9411 openzipkin/zipkin
  3. Build the jar files by executing the following command on the root path of the building-microservices mvn clean install
  4. Start each services by executing the following command (located at the roort path of the building-microservices): java -jar config-server\target\config-server-0.0.1-SNAPSHOT.jar java -jar eureka-service\target\eureka-service-0.0.1-SNAPSHOT.jar java -jar hystrix-dashboard\target\hystrix-dashboard-0.0.1-SNAPSHOT.jar java -jar reservation-client\target\reservation-client-0.0.1-SNAPSHOT.jar java -jar reservation-service\target\reservation-service-0.0.1-SNAPSHOT.jar

Testing

  1. The below image shows how the eureka server looks like: testing_01

  2. Testing Netflix-Zuul proxy
    The following image shows the reservations list service get from the reservation-service server. testing_02_01

The following image shows the reservations list service get from the reservation-client server by using zuul proxy. testing_02_02

  1. Testing hystrix
    The hystrix.stream endpoint tests each service tagged with @HystrixCommand testing_03_01

The following image shows how to add the hystrix stream to the hystrix dashboard. After adding the hystrix.stream url, clic on "monitor stream". testing_03_02

The below image shows hystrix stats when all services are working correctly. testing_03_03

Now, you can stop the reservation-service and see how the stats change. testing_03_04

  1. Testing Kafka
    In the left image, you can see the names services called from the browser. After, from postman we added a new reservation (middle image). Finally, in the right image you can see the new reservation was added. In fact, the reservation-client (producer) sent the reservation to the Kafka service, and the reservation-service (consumer) is listening for any change on Kafka service to read the tail and create a new reservation. testing_04

  2. Testing Zipkin
    You need to go to the Zipkin home page and add the service to monitor testing_05_01 You can see more details by clicking on "show" button. testing_05_02

About

This is an example about how to implement Microservices with Spring Cloud.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages