认识微服务
单体框架
将所有的业务功能集中在一个项目中开发,打包和部署
优点:
- 架构简单
- 部署成本低
缺点:
- 耦合度高
分布式框架
根据业务功能拆分成多个独立的业务模块进行开发和部署,每个独立的业务模块称为服务
优点:
- 降低服务耦合
- 有利于服务升级扩展
分布式框架要考虑的问题:
- 服务之间如何实现远程调用
- 服务集群地址如何维护
微服务
微服务得从两个方面去理解,什么是"微"、什么是"服务",微 狭义来讲就是体积小、意思是说单个服务的的独立开发,将所有参与设计、开发、测试、运维的组成独立的开发小组。 而所谓服务,一个或者一组相对较小且独立的业务功能单元。
微服务架构特征:
- 单一职责:微服务拆分粒度更小,每一个服务都对应唯一的业务功能,做到单一职责,避免重复业务开发
- 面向服务:微服务对外暴露业务接口
- 自治:团队独立、技术独立、数据独立、部署独立
- 隔离性强:服务调用做好隔离、容错、降级、避免出现级联问题
优点:拆分粒度更小、服务更独立、耦合度更低
缺点:架构非常复杂,运维、监控、部署难度提高
微服务结构
SpringCloud是目前国内使用最广泛的微服务框架。官网地址:https://spring.io/projects/spring-cloud
SpringCloud集成了各种微服务功能组件,并给予SpringBoot实现了这些组件的自动装配,从而提供了良好的开箱即用体验
服务注册发现:Eureka、Nacos、Consul
统一配置管理:SpringCloudConfig、Nacos
服务远程调用:OpenFeign、Dubbo
统一网关路由:SpringCloudGateway、Zuul
服务链路监控:Zipkin、Sleuth
流控、降级、保护:Hystix、Sentinel
SpringCloud与SpringBoot的版本兼容关系如下: