Introduction on Different Components of Microservices



Spring Cloud Components:

  • Configuration: Using Spring cloud config server.
  • Service Discovery and Registry: using Eureka server.
  • API Gateway: Using Zuul API or Spring Cloud Gateway.
  • Routing and messaging: using Feign API
  • Tracing with request visualization: Spring cloud sleuth and Zipkin
  • Circuit Breaker: Hystrix.


  • Spring Config Server:     Spring clouds config provides server and client-side support for externalized configuration in a distributed system. The default implementation of the server storage backed use git. 

In another word, Spring cloud provides tools for developers to quickly build some of the common patterns in distributed system and it will enables us to quickly developed cloud-native applications. One of the features is to maintain application configurations outside the application. This will enable configuration change without restarting microservice application.

The dependency for adding spring config cloud :
                 

We use spring cloud's @EnableConfigServer to create a config server that can be communicate with. So, this is just a normal Spring boot application with annotation added to enable the Config Server.



To ensure that there is no conflict between ports for our Config Service and client, we specify a different port for the Config Service:





  • Eureka Naming Server:     Eureka Server is a REST-based that holds the information about all client-service applications. Every Micro service will register into the Eureka server and Eureka server knows all the client applications running on each port and IP address. Eureka Server is also known as Discovery Server. Eureka naming server comes with the bundle of Spring Cloud. It runs on the default port 8761
The Eureka naming server comes into existence when we want to make maintenance easier. Whenever a new instance of a microservice comes up, it would register itself with the Eureka naming server. The registration of microservice with the naming server is called Service Registration.

The dependency of adding Eureka server in pom.xml


We use @EnableEurekaServer to create a  Eureka Server. So, this is just a normal Spring boot application with annotation added to enable the  Eureka Server.


For registering the micro-services into the Eureka server we used @EnableEurekaClient.


  • API Gateway:    The API Gateway is a server. It is a single entry point into a system. API Gateway encapsulates the internal system architecture. It provides an API that is tailored to each client. It also has other responsibilities such as authentication, monitoring, load balancing, caching, request shaping and management, and static response handling.
API Gateway is also responsible for request routing, composition, and protocol translation. All the requests made by the client go through the API Gateway. After that, the API Gateway routes requests to the appropriate microservice.
  • Spring Cloud Gateway:    Spring Cloud Gateway is a non blocking API. When using non blocking API, a thread is always available to process the incoming request. These request are then processed asynchronously in the background and once completed the response is returned. So no incoming request never gets blocked when using Spring Cloud Gateway.


The Configuration of application.yml



  • Hystrix:     In a distributed environment, inevitably some of the many service dependencies will fail. Hystrix is a library that helps you control the interactions between these distributed services by adding latency tolerance and fault tolerance logic. Hystrix does this by isolating points of access between the services, stopping cascading failures across them, and providing fallback options, all of which improve your system’s overall resiliency.
    Hystrix is based on the  Circuit Breaker Pattern.
Add below maven entries in pom.xml file

Add @EnableHystrixDashboard  annotations 






Fallback method will execute if any service is down or connection time out or any exception.


For better understanding see the following picture: 


Comments

Popular posts from this blog

Easy way to learn Spring boot: Introduction Part