Spring5学习(二)-spring projects之Spring Cloud

时间:2022-02-27 12:13:44

Spring Cloud

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 builds on Spring Boot by providing a bunch of(一堆) libraries that enhance(提高) the behaviour(行为, 特性, 表现) of an application when added to the classpath. You can take advantage of(利用, 趁, 借) the basic default behaviour to get started really quickly, and then when you need to, you can configure or extend to create a custom solution.





Quick Start

The release train label (see below) is actually(其实, 事实上, 竟) only used explicitly(明白地, 明确地) in one artifact: "spring-cloud-dependencies" (all the others have normal numeric(数字的;数值的) release labels tied to their parent project). The depednencies POM is the one you can use as a BOM(清单) for dependency management. Example using the latest version with the config client and eureka((因找到某物,尤指问题的答案而高兴)我发现了,我找到了) (change the artifact ids to pull in other starters):

current version:Edgware

maven:

<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.6.RELEASE</version>
</parent>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>Edgware.RELEASE</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
<dependency>
<groupId></groupId>
<artifactId>spring-cloud-starter-config</artifactId>
</dependency>
<dependency>
<groupId></groupId>
<artifactId>spring-cloud-starter-eureka</artifactId>
</dependency>
</dependencies>
gradle:

buildscript {
ext {
springBootVersion = '1.5.6.RELEASE'
}
repositories {
mavenCentral()
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
}
}

apply plugin: 'java'
apply plugin: 'spring-boot'

dependencyManagement {
imports {
mavenBom ':spring-cloud-dependencies:Edgware.RELEASE'
}
}

dependencies {
compile ':spring-cloud-starter-config'
compile ':spring-cloud-starter-eureka'
}





Features

Spring Cloud focuses on providing good out of box experience(提供良好的开箱体验) for typical use cases(典型的用例) and extensibility mechanism(可扩展性机制) to cover(覆盖) others.
  • Distributed/versioned configuration(分布式/版本化配置)
  • Service registration and discovery(服务注册和发现)
  • Routing
  • Service-to-service calls(通话,调用)
  • Load balancing(负载均衡)
  • Circuit Breakers(断路器)
  • Global locks(全局锁定)
  • Leadership election and cluster state
  • Distributed messaging(分布式消息)
Spring Cloud takes a very declarative approach(采取非常明确的方法), and often you get a lot of fetaures(通常你会遇到很多问题) with just a classpath change and/or an annotation. Example application that is a discovery client:
@SpringBootApplication
@EnableDiscoveryClient
public class Application {
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
}





Main Projects

Spring Cloud Config

Centralized external configuration management backed(集中的外部配置管理支持) by a git repository. The configuration resources map(资源图) directly to Spring `Environment` but could be used by non-Spring applications(非Spring应用程序) if desired(期望).

Spring Cloud Netflix

Integration with various Netflix OSS components (Eureka, Hystrix, Zuul, Archaius, etc.).

Spring Cloud Bus

An event bus(事件总线) for linking services and service instances together with distributed messaging. Useful for propagating state changes across a cluster (在群集中传播状态更改)(e.g. config change events).

Spring Cloud for Cloud Foundry
Integrates your application with Pivotal Cloudfoundry(参考:官网). Provides a service discovery implementation and also makes it easy to implement SSO and OAuth2 protected resources, and also to create a Cloudfoundry service broker(服务代理).

Spring Cloud Cloud Foundry Service Broker
Provides a starting point for building a service broker that manages a Cloud Foundry managed service.

Spring Cloud Cluster
Leadership election and common stateful patterns with an abstraction(抽象) and implementation for Zookeeper, Redis, Hazelcast, Consul.

Spring Cloud Consul
Service discovery and configuration management with Hashicorp Consul.

Spring Cloud Security
Provides support for load-balanced OAuth2 rest client and authentication header relays(转述( relay的第三人称单数 );转达) in a Zuul proxy.

Spring Cloud Sleuth
Distributed tracing(分布式跟踪) for Spring Cloud applications, compatible with(兼容) Zipkin(zipkin为分布式链路调用监控系统,聚合各业务系统调用延迟数据,达到链路调用监控跟踪。来自:csdn), HTrace(Apache HTrace是Cloudera开源出来的一个分布式系统跟踪框架,支持HDFS和HBase等系统。该项目目前还在孵化阶段。来自:itype) and log-based (e.g. ELK) tracing.

Spring Cloud Data Flow
A cloud-native orchestration service(云本地编排服务) for composable(可组合) microservice applications on modern runtimes. Easy-to-use DSL(DSL的中文名是数字用户线路,是以电话线为传输介质的传输技术组合。), drag-and-drop GUI, and REST-APIs together simplifies the overall(总体) orchestration(管弦乐编曲, 管弦乐作曲法) of microservice based data pipelines.

Spring Cloud Stream
A lightweight event-driven microservices framework to quickly build applications that can connect to external(外部) systems. Simple declarative model(简单的声明模型) to send and receive messages using Apache Kafka or RabbitMQ between Spring Boot apps.

Spring Cloud Stream App Starters
Spring Cloud Stream App Starters are Spring Boot based Spring Integration applications that provide integration with external systems.

Spring Cloud Task
A short-lived(短命的, 短暂的) microservices framework to quickly build applications that perform finite(有限) amounts of data processing. Simple declarative for adding both functional and non-functional features to Spring Boot apps.

Spring Cloud Task App Starters
Spring Cloud Task App Starters are Spring Boot applications that may be any process including Spring Batch jobs that do not run forever, and they end/stop after a finite period of data processing.

Spring Cloud Zookeeper
Service discovery and configuration management with Apache Zookeeper.

Spring Cloud for Amazon Web Services
Easy integration with hosted Amazon Web Services. It offers a convenient way to interact(相互作用) with AWS provided services using well-known Spring idioms(惯用语法) and APIs, such as the messaging or caching API. Developers can build their application around the hosted services without having to care about infrastructure or maintenance.

Spring Cloud Connectors
Makes it easy for PaaS applications in a variety of(在各种各样) platforms to connect to backend services(后台服务) like databases and message brokers(消息代理) (the project formerly known as "Spring Cloud").

Spring Cloud Starters
Spring Boot-style starter projects to ease(缓解) dependency management for consumers(消费者) of Spring Cloud. (Discontinued as a project and merged with the other projects after Angel.SR2.)

Spring Cloud CLI
Spring Boot CLI plugin for creating Spring Cloud component applications quickly in Groovy

Spring Cloud Contract
Spring Cloud Contract is an umbrella project holding solutions that help users in successfully implementing the Consumer Driven Contracts approach.

Spring Cloud Gateway
Spring Cloud Gateway is an intelligent and programmable router based on Project Reactor.




Release Trains

Spring Cloud is an umbrella project consisting of independent(独立的) projects with, in principle(原则上), different release cadences(不同的发行节奏). To manage the portfolio(皮包, 箧, 部长职务) a BOM (Bill of Materials) is published with a curated(策划) set of dependencies on the individual(个人的) project (see below). The release trains have names, not versions, to avoid confusion(混乱) with the sub-projects. The names are an alphabetic sequence(字母顺序) (so you can sort them chronologically(按时间顺序)) with names of London Tube(伦敦地铁) stations ("Angel" is the first release, "Brixton" is the second). When point releases of the individual projects accumulate(积累) to a critical mass(弥撒, 块, 堆, 大多数), or if there is a critical(临界, 严重, 批评, 危急) bug in one of them that needs to be available to everyone, the release train will push out "service releases" with names ending ".SRX", where "X" is a number.

Release train contents:

Component Camden.SR7 Dalston.SR4 Edgware.RELEASE Finchley.M4 Finchley.BUILD-SNAPSHOT
spring-cloud-aws 1.1.4.RELEASE 1.2.1.RELEASE 1.2.2.RELEASE 2.0.0.M2 2.0.0.BUILD-SNAPSHOT
spring-cloud-bus 1.2.2.RELEASE 1.3.1.RELEASE 1.3.2.RELEASE 2.0.0.M3 2.0.0.BUILD-SNAPSHOT
spring-cloud-cli 1.2.4.RELEASE 1.3.4.RELEASE 1.4.0.RELEASE 2.0.0.M1 2.0.0.BUILD-SNAPSHOT
spring-cloud-commons 1.1.9.RELEASE 1.2.4.RELEASE 1.3.0.RELEASE 2.0.0.M4 2.0.0.BUILD-SNAPSHOT
spring-cloud-contract 1.0.5.RELEASE 1.1.4.RELEASE 1.2.0.RELEASE 2.0.0.M4 2.0.0.BUILD-SNAPSHOT
spring-cloud-config 1.2.3.RELEASE 1.3.3.RELEASE 1.4.0.RELEASE 2.0.0.M4 2.0.0.BUILD-SNAPSHOT
spring-cloud-netflix 1.2.7.RELEASE 1.3.5.RELEASE 1.4.0.RELEASE 2.0.0.M4 2.0.0.BUILD-SNAPSHOT
spring-cloud-security 1.1.4.RELEASE 1.2.1.RELEASE 1.2.1.RELEASE 2.0.0.M1 2.0.0.BUILD-SNAPSHOT
spring-cloud-cloudfoundry 1.0.1.RELEASE 1.1.0.RELEASE 1.1.0.RELEASE 2.0.0.M1 2.0.0.BUILD-SNAPSHOT
spring-cloud-consul 1.1.4.RELEASE 1.2.1.RELEASE 1.3.0.RELEASE 2.0.0.M3 2.0.0.BUILD-SNAPSHOT
spring-cloud-sleuth 1.1.3.RELEASE 1.2.5.RELEASE 1.3.0.RELEASE 2.0.0.M4 2.0.0.BUILD-SNAPSHOT
spring-cloud-stream *lyn.SR3 Chelsea.SR2 Ditmars.RELEASE Elmhurst.M3 Elmhurst.BUILD-SNAPSHOT
spring-cloud-zookeeper 1.0.4.RELEASE 1.1.2.RELEASE 1.2.0.RELEASE 2.0.0.M3 2.0.0.BUILD-SNAPSHOT
spring-boot 1.4.5.RELEASE 1.5.4.RELEASE 1.5.8.RELEASE 2.0.0.M6 2.0.0.BUILD-SNAPSHOT
spring-cloud-task 1.0.3.RELEASE 1.1.2.RELEASE 1.2.2.RELEASE 2.0.0.M2 2.0.0.RELEASE
spring-cloud-vault
1.0.2.RELEASE 1.1.0.RELEASE 2.0.0.M4 2.0.0.BUILD-SNAPSHOT
spring-cloud-gateway

1.0.0.RELEASE 2.0.0.M4 2.0.0.BUILD-SNAPSHOT
Finchley([地名] [英国] 芬奇利) builds and works with Spring Boot 2.0.x, and is not expected to work with Spring Boot 1.5.x.

The Dalston and Edgware release trains build on Spring Boot 1.5.x, and are not expected to work with Spring Boot 2.0.x.

The Camden release train builds on Spring Boot 1.4.x, but is also tested with 1.5.x.

NOTE: The Brixton and Angel release trains were marked end-of-life (EOL) in July 2017.

The Brixton release train builds on Spring Boot 1.3.x, but is also tested with 1.4.x.

The Angel release train builds on Spring Boot 1.2.x, and is incompatible(不相容的) in some areas with Spring Boot 1.3.x. Brixton builds on Spring Boot 1.3.x and is similarly incompatible with 1.2.x. Some libraries and most apps built on Angel will run fine on Brixton, but changes will be required anywhere that the OAuth2 features from spring-cloud-security 1.0.x are used (they were mostly moved to Spring Boot in 1.3.0).

Use your dependency management tools to control the version. If you are using Maven remember that the first version declared wins, so declare the BOMs in order, with the first one usually being the most recent (e.g. if you want to use Spring Boot 1.3.6 with Brixton.RELEASE, put the Boot BOM first). The same rule applies to Gradle if you use the Spring dependency management plugin.

NOTE: The release train contains a spring-cloud-dependencies as well as the spring-cloud-starter-parent. You can use the parent as you would the spring-boot-starter-parent (if you are using Maven). If you only need dependency management, the "dependencies" version is a BOM-only version of the same thing (it just contains dependency management and no plugin declarations or direct references to Spring or Spring Boot). If you are using the Spring Boot parent POM, then you can use the BOM from Spring Cloud. The opposite(相反的) is not true: using the Cloud parent makes it impossible(不可能的), or at least(至少) unreliable(不可靠的), to also use the Boot BOM to change the version of Spring Boot and its dependencies.




说明:

1. distributed systems:分布式系统(distributed system)是建立在网络之上的软件系统。正是因为软件的特性,所以分布式系统具有高度的内聚性和透明性。因此,网络和分布式系统之间的区别更多的在于高层软件(特别是操作系统),而不是硬件。内聚性是指每一个数据库分布节点高度自治,有本地的数据库管理系统。透明性是指每一个数据库分布节点对用户的应用来说都是透明的,看不出是本地还是远程。在分布式数据库系统中,用户感觉不到数据是分布的,即用户不须知道关系是否分割、有无副本、数据存于哪个站点以及事务在哪个站点上执行等。(来自:百度百科


2. service discovery:Service discovery is the automatic detection(自动检测) of devices and services offered by these devices on a computer network. A service discovery protocol (SDP) is a network protocol that helps accomplish(完成, 做到, 达成) service discovery.Service discovery requires a common language to allow software agents to make use of one another's services without the need for continuous user intervention(持续的用户干预).(来自:wikipedia


3. circuit breakers:A circuit breaker is an automatically operated electrical switch designed to protect an electrical circuit from damage caused by excess current, typically resulting from an overload or short circuit. Its basic function is to interrupt current flow after a fault is detected. (断路器是一种自动操作的电气开关,其设计用于保护电路免受过电流损害,典型地由过载或短路引起。其基本功能是在检测到故障后中断电流。这里指程序的断路器)(来自:wikipedia


4. intelligent routing:智能路由器也就是智能化管理的路由器,通常具有独立的操作系统,可以由用户自行安装各种应用,自行控制带宽、自行控制在线人数、自行控制浏览网页、自行控制在线时间、同时拥有强大的USB共享功能,真正做到网络和设备的智能化管理。(来自:百度百科


5. micro-proxy:这个没有找到


6. control bus:In computer architecture, a control bus is part of the system bus, used by CPUs for communicating with other devices within the computer.(在计算机体系结构中,控制总线是系统总线的一部分,由CPU用于与计算机内的其他设备进行通信。)(来自:wikipedia


7. one-time tokens:A one-time password token (OTP token) is a security device or software program that produces new single-use passwords or passcodes at preset time intervals(以预设的时间间隔). (来自:searchsecurity


8. global locks:这个没有找到


9. leadership election:A leadership election is a political contest held(举行的政治竞赛) in various countries by which the members of a political party(一个政党) determine(确定, 决定, 判断) who will be the leader of their party.Generally, any political party can determine its own rules governing(治理) how and when a leadership election is to be held for that party.(来自:wikipedia


10. distributed sessions:分布式Session。(参考:csdn blogs


11. cluster state:In quantum(量子) information and quantum computing(计算), a cluster state(集群状态) is a type of highly entangled state of multiple qubits(一种多重量子比特高度纠缠的状态).(来自:wikipedia


12. Load balancing:In computing, load balancing improves the distribution of workloads across multiple computing resources, such as computers, a computer cluster, network links, central processing units, or disk drives.Load balancing aims to optimize resource use, maximize throughput, minimize response time, and avoid overload of any single resource. Using multiple components with load balancing instead of a single component may increase reliability and availability through redundancy. Load balancing usually involves dedicated software or hardware, such as a multilayer switch or a Domain Name System server process.(在计算中,负载平衡可以改善工作负载在多个计算资源(如计算机,计算机集群,网络链接,*处理单元或磁盘驱动器)上的分布。负载均衡旨在优化资源使用,最大化吞吐量,最小化响应时间并避免任何单一资源的过载。使用具有负载平衡的多个组件而不是单个组件可以通过冗余来提高可靠性和可用性。负载平衡通常涉及专用软件或硬件,例如多层交换机或域名系统服务器进程。)(来自:wikipedia


13. Distributed messaging: (参考:csdn blogs kafka csdn blogs


14. Netflix OSS:Netflix OSS是由Netflix公司主持开发的一套代码框架和库,目的是解决上了规模之后的分布式系统可能出现的一些有趣问题。(来自:infoq  github)


15. Apache ZooKeeper:Apache ZooKeeper is a software project of the Apache Software Foundation. It is essentially a distributed hierarchical key-value store, which is used to provide a distributed configuration service, synchronization service, and naming registry for large distributed systems. ZooKeeper was a sub-project of Hadoop but is now a top-level Apache project in its own right.(Apache ZooKeeper是Apache Software Foundation的一个软件项目。它本质上是一个分布式的分层键值存储,用于为大型分布式系统提供分布式配置服务,同步服务和命名注册表。 ZooKeeper是Hadoop的一个子项目,但现在它是一个*的Apache项目。)(来自:wikipedia


16. Hazelcast:In computing, Hazelcast is an open source in-memory data grid based on Java. It is also the name of the company developing the product. The Hazelcast company is funded by venture capital(风险投资).In a Hazelcast grid, data is evenly distributed among the nodes of a computer cluster, allowing for horizontal scaling(水平缩放) of processing and available storage. Backups are also distributed among nodes to protect against failure of any single node. Hazelcast provides central, predictable scaling of applications through in-memory access to frequently used data and across an elastically(弹性) scalable(可扩展性) data grid. These techniques reduce the query load on databases and improve speed.(来自:wikipedia


17. Hashicorp Consul:Service Discovery and Configuration Made Easy。(来自:官网


18. Zuul proxy:(参考:baeldung


19. Groovy:Apache Groovy is an object-oriented programming language for the Java platform. It is a dynamic language with features similar to those of Python, Ruby, Perl, and Smalltalk. It can be used as a scripting language for the Java Platform, is dynamically compiled to Java virtual machine (JVM) bytecode, and interoperates with other Java code and libraries.(来自:wikipedia