Spring Cloud 介绍

介绍

Spring Cloud作为开发者在分布式环境里快速构建某些常见模式的云应用工具。(比如:配置管理,服务发现,断路器、智能路由、微代理、控制总线、全局锁、决策竞选、分布式会话和集群状态管理)。使用Spring Cloud开发环境能够快速的启动服务并实现。
它们在任何的分布式环境中能够很好的工作,包括开发者的笔记本,数据中心,还有管理平台比如Cloud Foundry。

快速开始

Spring Cloud 构建在Spring Boot基础上的一个库,添加到你的应用程序上下文中,你可以使用它的默认配置来快速的开始,当你需要的时候,你也可以配置或者扩展来创建一个自己的解决方案。

推荐在你的项目里使用依赖管理去使用spring-cloud,你可以粘贴到你的构建环境中,如果需要帮助,可以看我们提供的开始指南章节(怎么使用MavenGradle进行构建)。
下面是maven的配置信息:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.3.7.RELEASE</version>
</parent>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>Brixton.SR6</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-config</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-eureka</artifactId>
</dependency>
</dependencies>

你也可以使用gradle风格:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
buildscript {
ext {
springBootVersion = '1.3.7.RELEASE'
}
repositories {
mavenCentral()
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
}
}

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

dependencyManagement {
imports {
mavenBom 'org.springframework.cloud:spring-cloud-dependencies:Brixton.SR6'
}
}

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

特性

  1. 分布式/版本控制 配置管理
  2. 服务注册和发现
  3. 路由
  4. 服务之间的调用
  5. 负载均衡
  6. 断路器
  7. 全局锁
  8. 选举和集群状态管理
  9. 分布式消息

Spring Cloud 提供了一些注解声明,通过注解可以获得很多特性。比如下面的例子是一个发现客户端:

1
2
3
4
5
6
7
@SpringBootApplication
@EnableDiscoveryClient
public class Application {
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
}

主要的项目

Spring Cloud Config

配置管理工具包,让你可以把配置放到远程服务器,集中化管理集群配置,目前支持本地存储、Git以及Subversion。这些配置信息会映射到Spring 环境中,你也可以使用非Spring应用程序。

Spring Cloud Netflix

各种组件的集成(比如:Eureka(服务发现), Hystrix(熔断器), Zuul(提供动态路由,监控,弹性,安全等边缘服务的框架), Archaius(配置管理),Ribbon(提供云端负载均衡),Turbine(聚合服务器发送事件流数据的一个工具,用来监控集群下hystrix的metrics情况))。

Spring Cloud Bus

事件、消息总线,用于在集群(例如,配置变化事件)中传播状态变化,可与Spring Cloud Config联合实现热部署。

Spring Cloud for Cloud Foundry

通过Oauth2协议绑定服务到CloudFoundry,CloudFoundry是VMware推出的开源PaaS云平台。

Spring Cloud Cloud Foundry Service Broker

作为一个云管理平台服务的切入点。

Spring Cloud Cluster

提供Leadership选举,如:Zookeeper, Redis, Hazelcast, Consul等常见状态模式的抽象和实现。

Spring Cloud Consul

封装了Consul操作,consul是一个服务发现与配置工具,与Docker容器可以无缝集成。

Spring Cloud Security

基于spring security的安全工具包,为你的应用程序添加安全控制。

Spring Cloud Sleuth

日志收集工具包,封装了Dapper和log-based追踪以及Zipkin和HTrace操作,为SpringCloud应用实现了一种分布式追踪解决方案。

Spring Cloud Data Flow

大数据操作工具,作为Spring XD的替代产品,它是一个混合计算模型,结合了流数据与批量数据的处理方式。

Spring Cloud Stream

数据流操作开发包,封装了与Redis,Rabbit、Kafka等发送接收消息。

Spring Cloud Task

提供云端计划任务管理、任务调度。

Spring Cloud Zookeeper

操作Zookeeper的工具包,用于使用zookeeper方式的服务发现和配置管理。

Spring Cloud for Amazon Web Services

和亚马逊服务的集成。

Spring Cloud Connectors

便于云端应用程序在各种PaaS平台连接到后端,如:数据库和消息代理服务。

Spring Cloud Starters

Spring Boot式的启动项目,为Spring Cloud提供开箱即用的依赖管理。

Spring Cloud CLI

基于 Spring Boot CLI,可以让你以命令行方式快速建立云组件。