Abstract

What is the main topic of this passage? Why is that? How to do? There are three aspects to SpringCloud, some of which refer to official documentation and technical blogs, with detailed links at the bottom of the article

What is? What is SpringCloud? What's it for? Why is that? Why SpringCloud? What are his strengths? How to do? How do I use SpringCloud? And the role of SpringCloud's various components?Copy the code

What is?

1. Brief introduction to Spring Cloud

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.
Microservices are units of service that can be independently deployed, horizontally scaled, independently accessed (or with a separate database), and springcloud is the steward of these microservices. With microservices as an architecture, the number of projects that springcloud needs to manage are very large.


2. Official introduction

Spring Cloud provides tools for developers to quickly build some of the common patterns in distributed systems (e.g. configuration management, service discovery, circuit breakers, intelligent routing, micro-proxy, control bus, one-time tokens, global locks, leadership election, distributed sessions, cluster state). Coordination of distributed systems leads to boiler plate patterns, and using Spring Cloud developers can quickly stand up services and applications that implement those patterns. They will work well in any distributed environment, including the developer’s own laptop, bare metal data centres, and managed platforms such as Cloud Foundry.

Spring Cloud provides developers with tools to quickly build common patterns in distributed systems (such as configuration management, service discovery, circuit breakers, intelligent routing, micro-proxies, control buses, one-time tokens, global locking, leadership elections, distributed sessions, cluster state). Coordination of distributed systems leads to boilerplate patterns that developers can quickly get up and implement with Spring Cloud services and applications. They work in any distributed environment, including developers’ own laptops, bare-metal data centers, and hosted platforms such as Cloud Foundry.


3. Overview of core members

Service Registry
Spring Cloud Netflix Eureka
Service invocation mode
REST API
Service monitoring
Spring Boot Admin
The circuit breaker
Spring Cloud Netflix Hystrix
The service gateway
Spring Cloud Netflix Zuul
Distributed configuration
Spring Cloud Config
Service tracking
Spring Cloud Sleuth
The message bus
Spring Cloud Bus
The data flow
Spring Cloud Stream
The batch task
Spring Cloud Task


4. What is the relationship with 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.Copy the code



Why is that?

1. Advantages of Spring Cloud?

Spring Cloud focuses on providing good out of box experience for typical use cases and extensibility mechanism to cover others.

Spring Cloud focuses on providing a good out-of-the-box experience for typical use cases and extensibility mechanisms for other users.


In addition, Spring Cloud was born in the era of microservice architecture, which considers all aspects of microservice governance. In addition, Spring Cloud is an ecosystem based on the advantages of Spring and Spring Boot.


2. Why SpringCloud?

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, the platform functions of fusing, load balancing and service center are accomplished
Spring Cloud is a boon for small and medium sized Internet companies, which often do not have the resources or financial resources to develop their own distributed system infrastructure. Using Spring Cloud’s one-stop solution can significantly reduce development costs while taking their business in stride. At the same time, with the popularity of microservice architecture and Docker container concept in recent years, Spring Cloud will also have a neutral place in the future more and more “Cloud” software development style, especially in the current various distributed solutions to provide standardized, full-site technology solutions. The significance may be comparable to the birth of the current Servlet specification, effectively advancing the technological level of the server software system.


The Spring Cloud architecture has interesting and cool technologies. If companies are choosing microservices to restructure their entire technology infrastructure, Spring Cloud is the best microservices framework out there.




How does it work?

1. Introduction to core modules

In order to easily implement microservices architectures, the industry has identified some common patterns to help achieve this. Some well-known patterns are centralized configuration management, service discovery, asynchronous message-driven, and distributed tracing. Spring Cloud provides these patterns as usable modules and helps us follow Cloud native best practices. In addition, the unique value of Spring Cloud can be reflected in the following aspects:
  1. Define common abstractions for common modules. This is a perfect application of Spring’s decoupling philosophy. Each pattern is not tightly tied to implementation. The following uses server configuration as an example. You are free to change backend storage without affecting other services.
  2. Modular components. Spring Cloud is not an all-or-nothing solution; all modules are optional.

A. Use Spring Cloud Config to implement centralized configuration management
To meet the requirements of the Store Config in Environment microservices architecture, we need to place the configuration of all services in a central location. To do this, the following functions are required:
  1. Support for multiple environments, such as Dev, Test, and PROd. We can then build a package for all environments.
  2. Transparent configuration extraction. These centralized configurations should be captured automatically without any user encoding.
  3. Properties are automatically refreshed when they change. The service should be notified of such changes and the new properties reloaded.
  4. Maintain a change history and easily revert to older versions. This is a very useful feature to recover from bad changes in production.
Spring Cloud Config supports all of these features by using a simple annotation @enableconFigServer in the configuration service and including initiators in other services to enable the client. Refer to the Spring Cloud Config documentation for more details.


B. Use Spring Cloud Discovery to discover services
Service discovery plays an important role in most distributed systems and service-oriented architectures. The problem seems simple at first: How do customers know the IP and port of services that might exist on multiple hosts? Things get more complicated when you start deploying more services in a multifunctional cloud environment.
In practice, this is usually done in two steps:
  • Service Registration – the process by which a service registers its location in a central registry. It typically registers its host and port, and sometimes authentication credentials, protocols, versions, and environment details.
  • Service discovery – The process by which a client application queries the central registry to learn the location of a service.
When choosing a service discovery solution, consider the following:
  • Fault tolerance – What happens when the registration service fails? Sometimes it will cancel registration immediately upon normal shutdown, but for the most part we need a timeout mechanism. The service sends a heartbeat constantly to ensure vitality. In addition, customers need to be able to handle failed services by automatically retrying another service.
  • Load Balancing – If multiple hosts are registered under the service, how do we balance the load between hosts? Is load balancing performed on the registry side or client side? Can we provide custom load balancing policies?
  • Integration work – How complex is the integration process? Does it just involve some new dependencies and/or configuration changes? Or is it intrusive discovery code? When your language is not supported, sometimes a separate Sidekick procedure is a good choice.
  • Availability Issues – Is the registry itself highly available? Can I upgrade without downtime? The registry should not be a single point of failure.
Spring Cloud provides a generic abstraction for registration and discovery, which means you only need to use @enableDiscoveryClient to make it work. Examples of Discovery implementations include Spring Cloud Discovery Eureka and Spring Cloud Discovery Zookeeper. You should choose the specific implementation based on your user case. Refer to the Spring Cloud Discovery documentation for more details.


C. Implement a message-driven architecture through Spring Cloud Stream
Suppose we have some microservices that then have to talk to each other. Obviously, the traditional synchronous approach is blocking and difficult to scale, which cannot survive in a complex distributed environment, so asynchronous message-driven is the right approach. In the modern world, each request cloud is treated as a message. As a result, various messaging middleware can use their own message formats and apis. Getting all this middleware to talk to each other is a disaster. In fact, it’s easy to solve this problem; You only need to define a unified message interface, and then each middleware provides an adapter that knows how to convert between their message format and the standard format. You now understand the core design principles of Spring Integration. Spring Integration is driven by the following goals:
  1. Provides a simple model for implementing complex enterprise integration solutions.
  2. Promotes asynchronous, message-driven behavior in Spring-based applications.
  3. Facilitate intuitive, incremental adoption by existing Spring users.
And follow the following principles:
  1. Components should be loosely coupled for modularity and testability.
  2. The framework should enforce separation of concerns between business logic and integration logic.
  3. Extension points should be abstract in nature, but within well-defined boundaries to promote reuse and portability.
Refer to the Spring Integration documentation for more details.
However, Spring Integration is still at a lower level and contains confusing terminology that is not intuitive. The programming model is not as easy to use as other Spring technologies. Hence the invention of Spring Cloud Stream. Based on standard message formats and various adapters provided by Spring integration, it works in a high-level binder abstraction to generate, process, and consume messages in an easier way. It looks like a Unix pipe; You just have to worry about what to do with the message. Messages will come in and out as expected. Spring Cloud Stream provides the following advanced features:
  1. Consumer Group. This was first introduced and popularized by Apache Kafka. It can support publish-subscribe and compete queues in a programming model.
  2. The partition. Messages with the same partitioning key are guaranteed to be generated in a physical segment based on the user-supplied partitioning key. This is critical in stateful processing, where related data needs to be processed together for performance or consistency reasons.
  3. Automatic content negotiation. Message type conversion is automatically performed based on the message type received by the user.
Refer to the Spring Cloud Stream documentation for more details.


D. Distributed tracking through Spring Cloud Sleuth and Zipkin
In a microservice architecture, an external request may involve multiple internal service invocations, and these services may be distributed across many machines. Although most solutions implement centralized logging storage and search, it is still difficult to track end-to-end transactions across multiple services. Figuring out how requests make their way through the application also means manually searching log keywords multiple times for clues. This is time-consuming and error-prone, especially if you don’t know enough about microservices topologies. What we really need is to associate and aggregate these logs in one place.
Spring Cloud Sleuth implements this correlation by introducing the concepts of Span and Trace. Span represents a basic unit of work, such as invoking a service, identified by a Span ID. A set of spans forms a tree-like structure called Trace. The trace ID will remain the same as the one after one microservice call. Both will be included in each log entry. In addition, it automatically sets up common communication channels:
  • We discussed requests for Spring Cloud Stream Binder earlier
  • The HTTP header received by the Spring MVC controller
  • Request RestTemplate
  • . And most other types of requests and replies in Spring-Ecology
With all this raw data, it’s still hard to understand things like microservice calls consuming the most time. Zipkin provides a nice UI to help us visualize and understand. You can prepare the Zipkin server @enableZipkinServer with simple annotations. See the Spring Cloud Sleuth documentation for more details.

2. Netflix is introduced

Netflix is an OTT service that provides on-demand video in many countries [7] and operates a single-fee, mail-in DVD rental service in the United States. The service uses a return envelope to send DVDS and blu-Ray rental discs to the consumer’s designated pick-up address. Founded by Reed Hastings and Marc Randolph on August 29, 1997, the company is headquartered in Los Gatto, California and began offering subscription-based services in 1999. By 2009, Netflix was offering more than 100,000 movies on DVD, with more than 10 million subscribers [8]. On February 25, 2007, Netflix announced that it had shipped the 1 billionth DVD. [9] As of April 2011, Netflix had more than 23 million subscribers in the United States and more than 26 million in the rest of the world. [10] In 2011, Netflix’s total digital revenue exceeded $15 billion. [11] However, on October 23, 2012, Netflix announced that its revenue in the third quarter of the year decreased by 88%[12]. In January 2013, Netflix announced that it had added 2 million subscribers in the United States during the fourth quarter of 2012, bringing the total number of streaming subscribers to 27.1 million in the United States and 29.4 million celebrity subscribers in the rest of the world. In the same period, Netflix’s revenue rose 8 percent to $945 million. [13] In mid-March 2013, Netflix had 33 million subscribers [14]. The number of subscribers reached 36.3 million in April 2013 (29.2 million in the United States) [15]. Since then Netflix’s subscriber numbers and revenue have continued to grow. As of October 2015, Netflix had 69.17 million subscribers worldwide, including more than 43 million in the United States. [16]

Netflix is a DVD rental and video subscription service, with 60 million video subscribers in 13 years, which has contributed to its success in distributed applications.

Spring Cloud Netflix integrates with various Netflix OSS components to form the core of microservices, including Eureka, Hystrix, Zuul, Archaius…

3. Core components

  • Spring Cloud Netflix Eureka
A service center (similar to the concept of a steward, you can pull anything directly from there), a REST-based service for locating services to enable cloud middle-tier service discovery and failover.
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 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.
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 Netflix Zuul
Gateway is a framework that provides dynamic routing, monitoring, elasticity, security and other edge services on the cloud platform. The front door for all requests at the back end of the Web site.
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 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.

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.
  • Spring Cloud Netflix Ribbon Load balancing.
  • Spring Cloud Netflix Fegin REST client.
  • Spring Cloud Bus

Message bus, which uses distributed messaging to connect services and service instances together and is used to propagate changes in state across a cluster.

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.
  • Spring Cloud Cluster 

Cluster tool, based on Zookeeper, Redis, Hazelcast, Consul implementation of leadership election and civilian state pattern abstraction and implementation.

  • Spring Cloud Consul 

Service discovery and configuration management based on Hashicorp Consul implementation.

  • 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.
  • Spring Cloud 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.
  • Spring Cloud for 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 scale applications in seconds without any infrastructure concerns
It’s a set of solutions that integrate with CloudFoundry, embracing CloudFoundry’s lap.
  • Spring Cloud Security 

Security controls that provide load balancing for OAuth2 REST clients and authentication header forwarding in Zuul proxy.

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.
  • Spring Cloud Sleuth 

Distributed link monitoring, distributed tracking system for SpringCloud applications, compatible with Zipkin, HTrace, and ELK.

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.
  • Spring Cloud Task

Short life cycle microservices that add functional and non-functional features to Spring Booot application simple declarations.

Mainly solve the task management and task scheduling of short-lived micro-services, such as some scheduled tasks run once in the evening, or some data analysis run several times temporarily.
  • Spring Cloud Zookeeper 

Service discovery and configuration management are based on Apache 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.
  • Spring Cloud for Amazon Web Services 

Fast and Amazon Web Services integration.

  • Spring Cloud Starters
A Spring Boot-style startup project that provides out-of-the-box dependency management for Spring Cloud.
  • Spring Cloud CLI 
Spring Boot CLI allows you to quickly build cloud components from the command line.
  • Spring Cloud Connectors 

Simplify the process of connecting to services and getting operations from the Cloud platform. It is highly scalable and can be used to build your own Cloud platform using 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.


  • Spring Cloud Stream 

A framework for creating message-driven microservices applications, 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


  • Spring Cloud Data Flow 

Used for big data processing

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.

conclusion

This article focuses on three aspects of SpringCloud:

1. What is SpringCloud?

Spring Cloud is an ordered collection of frameworks that provide developers with tools to quickly build common patterns in distributed systems, addressing service discovery registries, configuration centers, message buses, load balancing, circuit breakers, data monitoring, and more in distributed applications.

2. Why SpringCloud?

  • Based on HTTP protocol, RESTful style, simple and convenient interface, efficient and transparent (Dubbo uses RPC protocol, performance is slightly better than HTTP protocol, but strong coupling degree is higher)
  • Relying on the Spring platform, using Spring Boot to build services, comprehensive and out of the box
  • Community active and well-documented

3. How to use SpringCloud?

A. Component overview of SpringCloud
B. Application architecture
process
  • Requests are unified through the API Gateway (Zuul) to access internal services.
  • Upon receiving the request, the gateway retrieves the available services from the registry center (Eureka).
  • The Ribbon balances the load and distributes it to back-end instances.
  • Microservices communicate with each other through Feign.
  • Hystrix handles service time-out circuit breakers.
  • Turbine monitors indicators related to calls and fuses between services.


This article is only for learning communication, if there is any misunderstanding please correct


Reference:
Zh.wikipedia.org/wiki/Netfli…
Spring. IO/projects/sp…
www.ityouknow.com/springcloud…
www.ityouknow.com/springcloud…
www.cnblogs.com/llsg/p/1135…
www.cnblogs.com/xishuai/p/d…
www.infoq.com/articles/sp…