Spring Cloud
Spring Boot frees us from tedious configuration files, while Spring Cloud provides a complete set of microservice solutions, which greatly reduces the threshold of microservice development and also reduces the development cost.
The composition of Spring Cloud
Spring Cloud does not refer to any particular framework, but rather a combination of mature frameworks that are packaged in a Spring Boot-style manner, masking complex configuration and implementation principles, and ultimately giving developers a simple, easy-to-understand, easily deploy-able distributed system development kit.
We know that in microservices development, the following infrastructure is necessary:
- Service governance
- Configuration Management Center
- The gateway
- Service fault tolerance
- Service consumer
- Message middleware
- Distributed service Tracking
- security
- Microservice testing
Here is a schematic of the framework included in the Spring Cloud architecture:
Basic Components
Service registration and discovery
Service registration and discovery is one of the most core components in Spring Cloud. All services in the whole system can be registered in the registry and then centrally scheduled by the registry, facilitating subsequent horizontal scaling and failover. There are many ways to implement a registry in the Spring Cloud architecture (see the figure above), which will be covered in subsequent tutorials.
Configuration center
With the increasing of the service, at the same time, each service will have multiple environments (development, test environment, production environment, etc.), each environment configuration file will be different again, but again there are many configuration is can share, if each service to manage these configuration, can bring a lot of trouble to maintain, at this time, We need to introduce a configuration center to manage these configurations. Spring Cloud provides Spring Cloud Config to accomplish this task, but there are better implementations provided by the community, such as Apollo provided by Ctrip. However, how to notify specific services after configuration updates is a problem, so Spring Cloud also provides a Spring Cloud Bus component to communicate between services.
Service consumer
Since it is a microservice architecture, inter-service invocation is inevitable. Spring Cloud provides the Ribbon component, which can be used for inter-service invocation. At the same time, it also supports client load balancing. However, using the Ribbon directly is not very convenient. Therefore, Spring Cloud integrates the Ribbon with Netflix Feign. Spring Cloud OpenFeign implements a declarative service invocation client. Making it easier to write Web service clients.
Service fault tolerance
In microservice architecture, there are usually multiple services that call each other. Once some basic services fail, the whole system may become unusable, which is called service avalanche. In order to avoid this situation, we need to implement fault isolation and service degradation when services fail. In this case, Spring Cloud uses Hystrix for fault tolerance of services.
The gateway
The gateway provides routing, authentication, monitoring, and load balancing functions for the system. Spring Cloud provides two solutions for this: Zuul and Spring Cloud Gateway.
Service tracking
In a microservice architecture, the invocation chain between services becomes more and more complex as the number of services increases, and service tracking becomes important when we troubleshoot problems and monitor metrics for communication between services. The implementation provided by Spring Cloud is: Spring Cloud Sleuth.
Service test
Due to the nature of microservices architecture, each service may depend on other services, and different services may be maintained by different teams. Thus, when we test a service, we need to deploy all the services it depends on, which is very expensive. Using unit tests alone requires a lot of mock data, and once the dependent service interface changes, unit tests alone cannot detect it. So someone proposed CDC (consumer-driver Contracts) to test. The Spring Cloud Contract is an implementation of CDC.
conclusion
This article gives a brief introduction to the components of Spring Cloud, and in a future series of articles, each module will be described in detail in the latest version of Spring Cloud [Greenwich.SR2].
In the next article, I will introduce the Eureka Registry.