微服务的详解以及选型
微服务的优缺点
微服务重点在于把一个项目的各个模块和服务独立成单独的项目对外提供服务,互不影响,单个服务的下线更新不影响其他应用的使用,各个团队在协作提交代码的难度上会大大降低,但是也会带来整体项目架构变的复杂,衍生出服务之间互相调用,消息的互相传递,事务的链路回滚等一系列的问题。
SpringCloud的技术选型
作用 | 功能 | 选择方案 |
---|---|---|
分布式配置中心 | Spring cloud config,zk,Nacos | |
服务注册与发现 | Eureka,Consul,zk,Nacos | |
服务官网路由 | Zuul,SpringCloud Gateway | |
服务调用 | RestTemplate,Ribbon,Feign | |
客户端负载均衡 | Ribbon | |
断路器 | Hystrix,Sentinel | |
分布式消息 | SpringCloud Stream+Kafka,RabbitMq,RocketMq |
其中Eureka,Hystrix已经停止停止维护。
Sentinel和Seata是SpringCloud Alibaba的阉割版,完整版在阿里云上需要付费使用。
Sentinel的商用版本AHas才提供配置持久化的功能。
SpringBoot和SpringCloud版本的选择
SpringBoot的版本说明
<!--
2:是主版本号,表示是springboot的第二代产品
2:是次版本号,增加了一些新功能但是主题架构是没有变化的,是兼容的
6:是bug的修复版笨
SNAPSHOT(开发版本)、M1...M3(里程碑版本)、RELEASE(正式版本)
-->
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.2.6.RELEASE</version>
<relativePath />
</parent>
SpringCloud的版本说明
<!--
Hoxton:以伦敦地铁站命名的主版本A-Z,目前到H
SNAPSHOT(快照版本:不稳定)、
M(MileStone:里程碑版本)、
RC(Release Candidate:后选版本,PRE标识预览版)、
SR3(Service Release:稳定正式版,GA:GenerallyAvailable标识用的比较多的版本)
end-of-life(停止维护的版本)
tips:推荐使用SR2之后的版本
-->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>Hoxton.SR3</version>
<type>pom</type>
<scope>import</scope>
</dependency>
spring官网查看当前版本:https://spring.io/projects/spring-cloud#learn
SpringCloud和SpringBoot以及Spring Cloud Alibaba的版本兼容问题
spring Cloud Release Train | Boot Version | Spring Cloud Alibaba |
---|---|---|
Hoxton.SR3 | 2.2.1.RELEASE | 2.2.5.RELEASE |
Hoxton.RELEASE | 2.2.0.RELEASE | 2.2.X.RELEASE |
Greenwich | 2.1.x | 2.1.0 |
Finchley | 2.0.x | 2.0.X |
Edgware | 1.5.x | 1.5.X |