1 background

After 2008, with the rapid development of the Domestic Internet industry, our demand for software system is no longer the low level of “just use it” in the past. Activities such as grabbing red envelopes and Double Eleven Constantly force us to break through the performance limit of software system. Traditional IT enterprises’ development idea of “just use IT” can no longer meet the performance requirements of Internet with high concurrency and large traffic. The distributed system architecture has been the only way to solve this problem in the field of server development. However, due to the inherent complexity of distributed system, it is not as easy to develop a single application by a bunch of frameworks. Therefore, major Internet companies are investing in the development of their own infrastructure. Some of the more famous ones are Ari’s open source project Dubbo, a series of service frameworks developed by Netflix. In such a situation of “a hundred flowers bloom” and duplicate wheels, it is inevitable to emerge a unified standard to simplify the development of distributed systems, and Spring Cloud came into being.

2 What is Spring Cloud

SpringCloud architecture

Spring Cloud is an ordered collection of frameworks. It takes advantage of the development convenience of Spring Boot to subtly simplify the development of distributed system infrastructure, such as service discovery registry, configuration center, message bus, load balancing, circuit breakers, data monitoring, etc., which can be started and deployed with one click using Spring Boot’s development style. Instead of reinventing the wheel, Spring simply combines mature and proven service frameworks developed by various companies and encapsulates them in the Spring Boot style, masking the complex configuration and implementation principles. Finally, a simple and easy to understand, easy to deploy and easy to maintain distributed system development kit was set aside for developers. Spring Cloud is the further encapsulation of multiple open source components of Netflix, and at the same time realizes good integration with Cloud platform and Spring Boot development framework. Spring Cloud is a relatively new microservices framework with only a 1.0 release in 2016. Although Spring Cloud has the shortest time, compared with RPC frameworks such as Dubbo, Spring Cloud provides a full range of distributed system solutions. Spring Cloud provides developers with tools to quickly build in distributed systems (configuration management, service discovery, fuses, routing, micro proxy, control bus, one-time Token, full residence, Leader election, distributed Session, cluster state). Developers using Spring Cloud can quickly launch services or build applications and connect quickly to Cloud platform resources.

3 Spring Cloud components

The sub-projects of Spring Cloud can be roughly divided into two categories. One is the encapsulation and abstraction of the existing mature framework “Spring booting”, which is also the largest number of projects. The second type is the implementation of the infrastructure of a part of distributed system. For example, Spring Cloud Stream plays the role of Kafka and ActiveMQ. For our developers who want to quickly practice microservices, the first subproject is enough, such as Spring Cloud Netflix, which is the encapsulation of a set of distributed service framework developed by Netflix, including service discovery and registration, load balancing, circuit breakers, REST client, request routing, etc. This project is one of the sub-projects of Spring Cloud, and the main content is a package of Netflix open source products, which provides self-configurable Netflix OSS integration for Spring Boot applications. With a few simple annotations, developers can quickly configure common modules in their applications and build large distributed systems. Its main modules include: Service discovery (Eureka), circuit breaker (Hystrix), Intelligent Routing (Zuul), client load balancing (Ribbon), etc.

Spring Cloud Netflix is a big boss, whose position is second only to that of the big one. All services of the big one depend on it and integrate with various Netflix OSS components to form the core of micro services. Its younger brothers mainly include Eureka, Hystrix, Zuul, Archaius… There are too many

3.1 Spring Cloud Eureka Service Discovery

netflix-eureka

Spring Cloud Eureka service discovery

Eureka

Service Center, Cloud Service Discovery, a REST-based service for locating services to enable cloud middle-tier service discovery and failover. This is the most awesome little brother of SpringCloud, the service center, any little brother needs the support of other little brother need to get from here, similarly you have any special martial arts skills quickly reported, convenient for other little brother to call in the future; The advantage of it is that you don’t need to directly find a variety of younger brother support, you only need to go to the service center to get it, and you don’t need to know where other younger brother to provide support, or several younger brother to support, anyway, just use it, the service center to ensure stability and quality. Spring Cloud Eureka provides the functions of service discovery and service registration in distributed environment. A RESTful service that locates mid-tier services running in an AWS Region. It consists of two components: Eureka server and Eureka client. The Eureka server serves as the service registry server. The Eureka client is a Java client designed to simplify interactions with servers, act as a polling load balancer, and provide failover support for services. Netflix uses a separate client in its production environment that provides weighted load balancing based on traffic, resource utilization, and error status.

3.2 Spring Cloud Ribbon Client Load Balancing

netflix-ribbon

Spring Cloud Ribbon

The Ribbon provides client-side software load balancing algorithms. The Ribbon client component provides a comprehensive set of configuration options, such as connection timeout, retry, retry algorithm, and more. The Ribbon comes with pluggable, customizable load balancing components. Here are some load balancing strategies used:

  • Simple polling load balancing
  • Weighted response time load balancing
  • Region aware polling load balancing
  • Random load balancing

The Ribbon also provides the following functions:

  • Easy integration with service discovery components such as Netflix’s Eureka
  • Use Archaius for runtime configuration
  • Expose o&M metrics using JMX and publish using Servo
  • A variety of pluggable serialization options
  • Asynchronous and batch operations (coming soon)
  • Automatic SLA Framework (coming soon)
  • System Administration/Metrics Console (coming soon)

3.3 Spring Cloud Config

spring-cloud-config

The configuration Center, also known as the Configuration Management toolkit, allows you to centrally manage the configuration of a cluster on a remote server. It currently supports local storage, Git and Subversion. In the future, everyone’s weapons, guns and fire and other things are gathered together, do not casually bring, convenient for unified management, upgrade equipment in the future.

Spring Cloud Config Configuration center

By centralizing the configuration information, you can configure Spring Cloud Bus to dynamically modify the configuration file. This is still static and needs to work with The Spring Cloud Bus for dynamic configuration updates.

Spring Cloud Config

Spring Cloud Config is our usual configuration hub. Spring Cloud Config- Extracts the configuration of an application from a local file and places it on a central server, essentially migrating the configuration information from the local to the Cloud. Thus, it can provide better management and publishing capabilities. Spring Cloud Config consists of a server and a client. The server releases the configuration file stored in Git (SVN) to the REST interface. The client can obtain the configuration from the REST interface on the server. However, clients are not actively aware of configuration changes to obtain new configurations, requiring each client to trigger its own /refresh via POST.

3.4 Spring Cloud Hystrix fuse

netflix-hystrix

Fuse, a fault tolerant management tool designed to provide greater fault tolerance for delays and failures by controlling the nodes of services and third-party libraries through a circuit breaker mechanism. For example, suddenly someone is sick, but you still need its support, and then after calling it, it does not respond for a long time, but you do not know, waiting for the response; There is a chance that other boys are also calling your martial arts stunts, and when there are too many requests, there will be a serious blockage affecting the boss’s overall plan. That’s where Hystrix comes in, when Hystrix sees a guy who’s not in a good state and he’s unstable, they take him off immediately and they bring him in, or they say don’t wait this guy’s not going to be able to do this today, just do what you need to do and get out of the line.

Spring Cloud Hystrix fuse

A Cricuit Breaker is a facility that automatically fuses (switches on) when remote services are unavailable and automatically restores (switches on) when remote services are restored. Spring Cloud provides circuit breakers, resource isolation, and self-healing capabilities through Netflix’s Hystrix component.

A circuit breaker prevents an application from trying multiple times to perform an operation that is likely to fail, allowing it to continue without waiting for recovery or wasting CPU cycles when it determines that the failure is persistent. Breaker mode also enables the application to detect whether the fault has been resolved. If the problem appears to have been corrected, the application can try to invoke the action.

Hystrix01

Circuit breakers add stability and flexibility to a system, providing stability while the system recovers from failure and minimizing the impact of this failure on performance. It helps to quickly reject requests for an operation that is likely to fail, rather than waiting for the operation to time out (or not return) to keep the system’s response time. If the breaker raises the time of each state change event, this information can be used to monitor the health of components of the system protected by the breaker, or to alert administrators when the breaker trips to be in the open state.

Hystrix02

The flow chart of Hystrix

3.5 Spring Cloud Zuul service gateway, intelligent routing

netflix-zuul

Zuul is a framework for providing edge services such as dynamic routing, monitoring, resilience, and security on cloud platforms. Zuul is the front door for all requests from the backend of the Web site for devices and Netflix streaming applications. Be sure to pass through Zuul first when other families send to look for the elder brother to do business, and see if there is any knife to intercept back, or if you need to find the younger brother directly to take over.

Spring Cloud Zuul service Gateway

Zuul

Nginx-like, reverse proxy functionality, but Netflix has added some of its own features to work with other components.

3.6 Spring Netflix Archaius

netflix-archaius

Configuration management API, a set of configuration management apis that provide dynamic typed properties, thread-safe configuration operations, polling framework, callback mechanism, and more. The configuration can be dynamically obtained by reading the content from the configuration source every 60 seconds (configurable by default). In this way, the modified content can take effect without restarting the service after modifying the configuration file. The premise is that archaius API is used to read the content.

3.7 Spring Cloud Bus

spring-cloud-bus

Event, message bus, for propagating state changes in clusters (for example, configuration change events), can be combined with Spring Cloud Config for hot deployment. Equivalent to the water Margin line eight hundred miles of taibao Dai Zong, to ensure that the information between the younger brother to remain unblocked.

Distributed message queue, is the Kafka, MQ encapsulation; Event, message bus, for propagating state changes in clusters (for example, configuration change events), can be combined with Spring Cloud Config for hot deployment. Spring Cloud Bus connects distributed nodes through lightweight message brokers. This is used to broadcast state changes (such as configuration changes) or other message instructions. ** One of the core ideas of Spring Bus is to extend Spring Boot applications through a distributed initiator, which can also be used to establish a communication channel between multiple applications. ** Currently the only way to implement this is to use the AMQP message broker as a channel, and the Settings for the same features (some depending on channel Settings) are in the documentation for more channels. Spring Cloud Bus is widely translated as message bus in China. It can be understood as the management and dissemination of messages in all distributed projects, in fact, the dissemination of messages in distributed systems using MQ broadcast mechanism, currently commonly used Kafka and RabbitMQ. There are many things that can be done by using the mechanism of bus, among which configuration center client refresh is one of the typical application scenarios. We use a diagram to describe the mechanism used by bus in configuration center.

Spring Cloud Bus

According to this figure, we can see the steps of using Spring Cloud Bus to do configuration update:

  1. Submit code triggers POST to send bus/refresh to client A
  2. Client A receives A request to update the configuration from the Server and sends it to the Spring Cloud Bus
  3. Spring Cloud Bus receives the message and notifies the other clients
  4. Other clients receive the notification and request the Server to obtain the latest configuration
  5. All clients have obtained the latest configuration

3.8 Spring Cloud Security

spring-cloud-security

A package of Spring Security that works with Netflix, the Security toolkit, to add Security controls to your applications, mainly OAuth2. Add security controls to your applications based on spring Security’s security toolkit. The younger brother is very ox nose is responsible for the security of the whole gang, set up different doors to visit specific resources, can not leak the secret sunflower treasure book.

3.9 Spring Cloud Zookeeper

spring-cloud-zookeeper

Encapsulation of Zookeeper so that it can be configured for use by other Spring Cloud sub-projects; You can operate the Zookeeper tool package, which is used to register and discover services using Zookeeper. ZooKeeper is a distributed, open source distributed application coordination service. It is an open source implementation of Google’s Chubby and an important component of Hadoop and Hbase. It provides consistency services for distributed applications, including configuration and maintenance, domain name service, distributed synchronization, and group service. ZooKeeper aims to encapsulate key services that are complex and error-prone, and provide users with easy-to-use interfaces, efficient performance, and stable functions. You can operate the Zookeeper tool package, which is used to discover and configure Zookeeper services.

3.10 Spring Cloud Stream

spring-cloud-stream

The data flow; Data flow operation development kit, package with Redis,Rabbit, Kafka and more send and receive messages. Spring Cloud Stream is a framework for creating message-driven microservice applications. Spring Cloud Stream is created based on Spring Boot to build individual/industrial Spring applications using Spring Integration to provide connectivity to message brokers. Data flow operation development kit, package with Redis,Rabbit, Kafka and more send and receive messages. A business involves multiple tasks that are triggered by events, which is what Spring Cloud Stream does.

3.11 Spring Cloud Sleuth

spring-cloud-sleuth

Service tracking; Log collection toolkit that encapsulates Dapper,Zipkin, and HTrace operations. The log collection toolkit, which encapsulates Dapper and log-based tracing as well as Zipkin and HTrace operations, implements a distributed tracing solution for SpringCloud applications.

3.12 Spring Cloud Feign uses HTTP to request remote services

netflix-feign

In Spring Cloud Netflix stack, each microservice exposes its own service in the form of HTTP interface, so it must use HTTP client when calling remote service. We can use JDK native URLConnection, Apache’s Http Client, Netty’s asynchronous Http Client, and Spring’s RestTemplate. But Feign is the easiest and most elegant to use. Feign is a declarative, templated HTTP client. Using Feign in Spring Cloud, we can make remote service requests using HTTP have the same coding experience as local methods, without the developer perceiving that it is a remote method, much less an HTTP request. With Feign, we can make HTTP remote calls completely transparent to developers and get a coding experience consistent with calling local methods. This is similar to the way remote services are exposed in Ali Dubbo, except that Dubbo is based on a private binary protocol, while Feign is essentially an HTTP client. If you’re building a micro service with Spring Cloud Netflix, Feign is the best choice.

3.13 Spring Cloud for Cloud Foundry

pivotal-cloud-foundry

Cloud Foundry is the industry’s first open source PaaS Cloud platform from VMware. It supports multiple frameworks, languages, runtime environments, Cloud platforms and application services, enabling developers to deploy and extend applications in seconds. Not having to worry about any infrastructure issues is really a solution that integrates with CloudFoundry, taking CloudFoundry in its lap.

3.14 Spring Cloud Cluster

spring-cloud-cluster

Spring Cloud Cluster will replace Spring Integration. Provide basic support for clustering in distributed systems, such as: elections, cluster state consistency, global locking, tokens, and other common state patterns abstraction and implementation. If you want to organize different gangs into a unified whole, Spring Cloud Cluster already provides you with a lot of tools for organizing into a unified whole.

3.15 Spring Cloud Consul

hashicorp-consul

Consul is a service software that supports distributed and highly available service discovery and configuration sharing in multiple data centers. Developed by HashiCorp in Go, Consul is open source based on the Mozilla Public License 2.0 protocol. Consul supports health checks and allows HTTP and DNS protocols to call apis to store key-value pairs. Spring Cloud Consul encapsulates Consul operations, and Consul is a service discovery and configuration tool that seamlessly integrates with the Docker container.

3.16 Spring Cloud Data Flow

spring-cloud-data-flow

Data Flow is a unified programming model and managed service for developing and performing a wide range of Data processing patterns including ETL, batch and continuous operations. Spring Cloud Data Flow is a native cloud-configurable service for composable microservices running in modern environments. Spring Cloud Data Flow enables developers to create and orchestrate data pipelines for common use cases like data extraction, real-time analytics, and data import/export. Spring Cloud Data Flow is a redesign of Spring XD based on the native Cloud. The project aims to simplify the development of big data applications. Spring XD’s stream processing and batch module refactoring are Spring Boot-based stream and Task/Batch microservices, respectively. These applications are now automated deployment units and they have native support for modern operating environments like Cloud Foundry, Apache YARN, Apache Mesos, and Kubernetes. Spring Cloud Data Flow provides a set of models and best practices for distributed streaming and batch data channels based on microservices.

3.17 Spring Cloud Task

spring-cloud-task

Spring Cloud Task mainly deals with Task management and scheduling of short-lived microservices, such as certain scheduled tasks running once in the evening or certain data analysis tasks running several times temporarily.

3.18 Spring Cloud Connectors

spring-cloud-connectors

Spring Cloud Connectors simplify the process of connecting to services and getting operations from the Cloud platform, and are highly scalable to build your own Cloud platform with Spring Cloud Connectors. It makes it easy for cloud applications to connect to the backend on various PaaS platforms, such as databases and message broker services.

3.19 Spring Cloud Starters

spring-cloud-starters

A Spring Boot-style startup project that provides out-of-the-box dependency management for Spring Cloud.

3.20 Spring Cloud CLI

spring-cloud-cli

Spring Boot CLI allows you to quickly build cloud components from the command line.

3.21 Netflix Turbine

netflix-turbine

Turbine is a tool for aggregating servers to send event stream data to monitor Hystrix metrics under the cluster.

What is the relationship between 4 and Spring Boot

Spring Boot is a set of Spring fast configuration scaffolding, you can quickly develop a single micro service based on Spring Boot, Spring Cloud is a Cloud application development tool based on Spring Boot implementation; Spring Boot focuses on a single entity for fast and easy integration, while Spring Cloud is a global service governance framework. Spring Boot uses the concept of default greater than configuration, many integration solutions have been selected for you, can not configure, spring Cloud is based on a large part of the Implementation of Spring Boot, can not be based on Spring Boot? Can’t. Spring Boot can be independently used for development projects without Spring Cloud, but Spring Cloud cannot be separated from Spring Boot, which is a dependency.

Spring -> Spring Boot > Spring Cloud.

5. Advantages of Spring Cloud

There are so many microservices frameworks such as Dubbo and Kubernetes, why use Spring Cloud?

  • Produced by the Spring family, Spring is unrivaled in the enterprise development framework, with a big head, which can guarantee the subsequent update and improvement. Dubbo, for example, is almost dead right now
  • Have Spring Boot this independent dry will be able to save a lot of things, large and small live Spring Boot are engaged in pretty good. As a big guy of micro service governance, consider very comprehensive, almost all aspects of service governance are considered, convenient development out of the box.
  • Spring Cloud is highly active, tutorials are plentiful, and it’s easy to find solutions to problems
  • In a few lines of code, various platform functions such as fusing, balancing responsibility and service center are completed
  • Spring Cloud also has the disadvantage that it can only be developed in Java and is not suitable for small independent projects.