SpringCloud 是什么?
Spring 官网:https://spring.io/
SpringCloud 和 SpringBoot 的关系
- SpringBoot 专注于开苏方便的开发单个个体微服务;
- SpringCloud 是关注全局的微服务协调整理治理框架,它将 SpringBoot 开发的一个个单体微服务,整合并管理起来,为各个微服务之间提供:配置管理、服务发现、断路器、路由、为代理、事件总栈、全局锁、决策竞选、分布式会话等等集成服务;
- SpringBoot 可以离开 SpringCloud 独立使用,开发项目,但 SpringCloud 离不开 SpringBoot,属于依赖关系;
- SpringBoot 专注于快速、方便的开发单个个体微服务,SpringCloud 关注全局的服务治理框架;
Dubbo 和 SpringCloud 技术选型
1. 分布式+服务治理 Dubbo
目前成熟的互联网架构,应用服务化拆分 + 消息中间件
2. Dubbo 和 SpringCloud 对比
可以看一下社区活跃度:
https://github.com/dubbo
https://github.com/spring-cloud
对比结果:
Dubbo | SpringCloud | |
---|---|---|
服务注册中心 | Zookeeper | Spring Cloud Netfilx Eureka |
服务调用方式 | RPC | REST API |
服务监控 | Dubbo-monitor | Spring Boot Admin |
断路器 | 不完善 | Spring Cloud Netfilx Hystrix |
服务网关 | 无 | Spring Cloud Netfilx Zuul |
分布式配置 | 无 | Spring Cloud Config |
服务跟踪 | 无 | Spring Cloud Sleuth |
消息总栈 | 无 | Spring Cloud Bus |
数据流 | 无 | Spring Cloud Stream |
批量任务 | 无 | Spring Cloud Task |
最大区别:Spring Cloud 抛弃了 Dubbo 的 RPC 通信,采用的是基于 HTTP 的 REST 方式
严格来说,这两种方式各有优劣。虽然从一定程度上来说,后者牺牲了服务调用的性能,但也避免了上面提到的原生 RPC 带来的问题。而且 REST 相比 RPC 更为灵活,服务提供方和调用方的依赖只依靠一纸契约,不存在代码级别的强依赖,这个优点在当下强调快速演化的微服务环境下,显得更加合适。
品牌机和组装机的区别
社区支持与更新力度的区别
总结:二者解决的问题域不一样:Dubbo 的定位是一款 RPC 框架,而 SpringCloud 的目标是微服务架构下的一站式解决方案。
3、SpringCloud 能干嘛?
- Distributed/versioned configuration 分布式/版本控制配置
- Service registration and discovery 服务注册与发现
- Routing 路由
- Service-to-service calls 服务到服务的调用
- Load balancing 负载均衡配置
- Circuit Breakers 断路器
- Distributed messaging 分布式消息管理
- …
4、SpringCloud 下载
官网:http://projects.spring.io/spring-cloud/
版本号有点特别:
SpringCloud 没有采用数字编号的方式命名版本号,而是采用了伦敦地铁站的名称,同时根据字母表的顺序来对应版本时间顺序,比如最早的 Realse 版本:Angel,第二个 Realse 版本:Brixton,然后是 Camden、Dalston、Edgware,目前最新的是 Hoxton SR4 CURRENT GA 通用稳定版。
自学参考书:
- SpringCloud Netflix 中文文档:https://springcloud.cc/spring-cloud-netflix.html
- SpringCloud 中文 API 文档(官方文档翻译版):https://springcloud.cc/spring-cloud-dalston.html
- SpringCloud 中国社区:http://springcloud.cn/
- SpringCloud 中文网:https://springcloud.cc
SpringCloud Rest 学习环境搭建:服务提供者
介绍
- 我们会使用一个 Dept 部门模块做一个微服务通用案例Consumer消费者(Client)通过 REST 调用Provider提供者(Server)提供的服务。
- 回顾 Spring,SpringMVC,Mybatis 等以往学习的知识。
- Maven 的分包分模块架构复习。
一个简单的 Maven 模块结构是这样的:– app-parent: 一个父项目(app-parent)聚合了很多子项目(app-util\app-dao\app-web…) |– pom.xml | |– app-core ||—- pom.xml | |– app-web ||—- pom.xml ……
一个父工程带着多个 Moudule 子模块
MicroServiceCloud 父工程(Project)下初次带着 3 个子模块(Module)
- microservicecloud-api 【封装的整体 entity/接口/公共配置等】
- microservicecloud-consumer-dept-80 【服务提供者】
- microservicecloud-provider-dept-8001 【服务消费者】
SpringCloud 版本选择
大版本说明
SpringBoot | SpringCloud | 关系 |
---|---|---|
1.2.x | Angel 版本(天使) | 兼容 SpringBoot1.2x |
1.3.x | Brixton 版本(布里克斯顿) | 兼容 SpringBoot1.3x,也兼容 SpringBoot1.4x |
1.4.x | Camden 版本(卡姆登) | 兼容 SpringBoot1.4x,也兼容 SpringBoot1.5x |
1.5.x | Dalston 版本(多尔斯顿) | 兼容 SpringBoot1.5x,不兼容 SpringBoot2.0x |
1.5.x | Edgware 版本(埃奇韦尔) | 兼容 SpringBoot1.5x,不兼容 SpringBoot2.0x |
2.0.x | Finchley 版本(芬奇利) | 兼容 SpringBoot2.0x,不兼容 SpringBoot1.5x |
2.1.x | Greenwich 版本(格林威治) |
实际开发版本关系
spring-boot-starter-parent | spring-cloud-dependencles | ||
---|---|---|---|
版本号 | 发布日期 | 版本号 | 发布日期 |
1.5.2.RELEASE | 2017-03 | Dalston.RC1 | 2017-x |
1.5.9.RELEASE | 2017-11 | Edgware.RELEASE | 2017-11 |
1.5.16.RELEASE | 2018-04 | Edgware.SR5 | 2018-10 |
1.5.20.RELEASE | 2018-09 | Edgware.SR5 | 2018-10 |
2.0.2.RELEASE | 2018-05 | Fomchiey.BULD-SNAPSHOT | 2018-x |
2.0.6.RELEASE | 2018-10 | Fomchiey-SR2 | 2018-10 |
2.1.4.RELEASE | 2019-04 | Greenwich.SR1 | 2019-03 |
使用后两个
创建父工程
- 新建父工程项目 springcloud,切记Packageing 是 pom 模式
- 主要是定义 POM 文件,将后续各个子模块公用的 jar 包等统一提取出来,类似一个抽象父类
pom.xml
1 |
|