In short, the microservice architectural style is an approach to developing a single application as a suite of small services
, each running in its own process
and communicating with lightweight mechanisms, often an HTTP resource API. These services are built around business capabilities
and independently deployable
by fully automated deployment machinery. There is a bare minimum of centralized management of these services
, which may be written in different programming languages and use different data storage technologies. -----[摘自官网]html
- a suite of small services --一系列微小服务 - running in its own process --运行在本身的进程里 - built around business capabilities --围绕本身的业务开发 - independently deployable --独立部署 - bare minimum of centralized management of these services --基于分布式管理
官方定义:微服务就是由一系列围绕本身业务开发的微小服务构成,他们独立部署运行在本身的进程里,基于分布式的管理前端
App 应学项目 分类模块 视频模块 评论模块 用户模块 统计模块... 单体应用java
分类服务 独立应用 ---> 计算进程里面 ---> 独立部署web
视频服务 基于分布式服务管理spring
评论服务apache
用户服务api
....服务springboot
通俗定义:微服务是一种架构,这种架构是将单个的总体应用程序分割成更小的项目关联的独立的服务。一个服务一般实现一组独立的特性或功能,包含本身的业务逻辑和适配器。各个微服务之间的关联经过暴露api来实现。这些独立的微服务不须要部署在同一个虚拟机,同一个系统和同一个应用服务器中。服务器
# 1.优势 - 单一架构模式在项目初期很小的时候开发方便,测试方便,部署方便,运行良好。 # 2.缺点 - 应用随着时间的推动,加入的功能愈来愈多,最终会变得巨大,一个项目中颇有可能数百万行的代码,互相之间繁琐的jar包。 - 长此以往,开发效率低,代码维护困难 - 还有一个若是想总体应用采用新的技术,新的框架或者语言,那是不可能的。 - 任意模块的漏洞或者错误都会影响这个应用,下降系统的可靠性
# 1.优势 - 将服务拆分红多个单一职责的小的服务,进行单独部署,服务之间经过网络进行通讯 - 每一个服务应该有本身单独的管理团队,高度自治 - 服务各自有本身单独的职责,服务之间松耦合,避免因一个模块的问题致使服务崩溃 # 2.缺点 - 开发人员要处理分布式系统的复杂性 - 多服务运维难度,随着服务的增长,运维的压力也在增大 - 服务治理 和 服务监控 关键
# 1.架构的演变过程 - [单一应用架构] `===>` [垂直应用架构] `===>` [分布式服务架构] `===>` [流动计算架构]||[微服务架构] `===>` [未知]
# 1. All in One Application 单一架构 - 起初当网站流量很小时,将全部功能都写在一个应用里面,对整个应用进行部署,以减小部署节点和成本。对于这个架构简化增删改查的工做量的数据访问框架(ORM)是关键。 # 2. Vertical Application 垂直架构 - 当访问量逐渐增大,单一应用增长机器带来的加速度愈来愈小,提高效率的方法之一是将应用拆成互不相干的几个应用,以提高效率。此时,用于加速前端页面开发的Web框架(MVC)是关键。 # 3. Distributed Service 分布式服务架构 - 当垂直应用愈来愈多,应用之间交互不可避免,将核心业务抽取出来,做为独立的服务,逐渐造成稳定的服务中心,使前端应用能更快速的响应多变的市场需求。此时,用于提升业务复用及整合的分布式服务框架(RPC)是关键。 # 4. Elastic Computing 流动计算架构即微服务架构 - 当服务愈来愈多,容量的评估,小服务资源的浪费等问题逐渐显现,此时需增长一个调度中心基于访问压力实时管理集群容量,提升集群利用率。此时,用于提升机器利用率的资源调度和治理中心(SOA)是关键
# 1.Dubbo (阿里系) - 初出茅庐:2011年底,阿里巴巴在GitHub上开源了基于Java的分布式服务治理框架Dubbo,以后它成为了国内该类开源项目的佼佼者,许多开发者对其表示青睐。同时,前后有很多公司在实践中基于Dubbo进行分布式系统架构,目前在GitHub上,它的fork、star数均已破万。Dubbo致力于提供高性能和透明化的RPC远程服务调用方案,以及SOA服务治理方案,使得应用可经过高性能RPC实现服务的输出、输入功能和Spring框架无缝集成。Dubbo包含远程通信、集群容错和自动发现三个核心部分。 - 中止维护:从2012年10月23日Dubbo 2.5.3发布后,在Dubbo开源将满一周年之际,阿里基本中止了对Dubbo的主要升级。只在以后的2013年和2014年更新过2次对Dubbo 2.4的维护版本,而后中止了全部维护工做。Dubbo对Srping的支持也停留在了Spring 2.5.6版本上。 - 死而复生:多年漫长的等待,随着微服务的火热兴起,在国内外开发者对阿里再也不升级维护Dubbo的吐槽声中,阿里终于开始从新对Dubbo的升级和维护工做。在2017年9月7日,阿里发布了Dubbo的2.5.4版本,距离上一个版本2.5.3发布已经接近快5年时间了。在随后的几个月中,阿里Dubbo开发团队以差很少每个月一版本的速度开始快速升级迭代,修补了Dubbo老版本多年来存在的诸多bug,并对Spring等组件的支持进行了全面升级。 - 2018年1月8日,Dubbo创始人之一梁飞在Dubbo交流群里透露了Dubbo 3.0正在动工的消息。Dubbo 3.0内核与Dubbo 2.0彻底不一样,但兼容Dubbo 2.0。Dubbo 3.0将以Streaming为内核,再也不是Dubbo 时代的RPC,可是RPC会在Dubbo 3.0中变成远程Streaming对接的一种可选形态。从Dubbo新版本的路线规划上能够看出,新版本的Dubbo在原有服务治理的功能基础上,将全面拥抱微服务解决方案。 - 结论:当前因为RPC协议、注册中心元数据不匹配等问题,在面临微服务基础框架选型时Dubbo与Spring Cloud是只能二选一,这也是为何你们老是拿Dubbo和Spring Cloud作对比的缘由之一。Dubbo以后会积极寻求适配到Spring Cloud生态,好比做为Spring Cloud的二进制通讯方案来发挥Dubbo的性能优点,或者Dubbo经过模块化以及对http的支持适配到Spring Cloud。
# Spring Cloud: - Spring Cloud NetFlix(美国 在线视频网站) 基于美国Netflix公司开源的组件进行封装,提供了微服务一栈式的解决方案。 G版本 - Spring Cloud alibaba 在Spring cloud netflix基础上封装了阿里巴巴的微服务解决方案。 - Spring Cloud 目前spring官方趋势正在逐渐吸取Netflix组件的精华,并在此基础进行二次封装优化,打造spring专有的解决方案
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
). 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. -------[摘自官网]markdown
# 1.翻译 - springcloud为开发人员提供了在分布式系统中快速构建一些通用模式的工具(例如配置管理、服务发现、断路器、智能路由、微代理、控制总线)。分布式系统的协调致使了锅炉板模式,使用springcloud开发人员能够快速地创建实现这些模式的服务和应用程序。 # 2.通俗理解 - springcloud是一个含概多个子项目的开发工具集,集合了众多的开源框架,他利用了Spring Boot开发的便利性实现了不少功能,如服务注册,服务注册发现,负载均衡等.SpringCloud在整合过程当中主要是针对Netflix(耐非)开源组件的封装.SpringCloud的出现真正的简化了分布式架构的开发。 - NetFlix 是美国的一个在线视频网站,微服务业的翘楚,他是公认的大规模生产级微服务的杰出实践者,NetFlix的开源组件已经在他大规模分布式微服务环境中通过多年的生产实战验证,所以Spring Cloud中不少组件都是基于NetFlix组件的封装。 # 3.微服务架构下所存在问题? - 基于独立业务拆分红一个微小的服务 每一个服务独立部署 运行在本身的进程里面 服务之间使用http rest的方式进行通讯 - 单体应用 分类模块 视频模块 用户模块 产生 测试 前端 pc app 统一入口 localhost:8989 - 微服务架构应用 分类服务 8080 视频服务 8081 用户服务 8082 8083 ..... - 问题 1.要有个组件帮助咱们记录服务,监控服务,服务发现 服务注册和发现组件 注册中心 2.服务调用问题http rest方式调用 --- 如何调用? 服务调用时如何实现服务负载均衡 ? 3.服务雪崩效应? 4.服务配置文件管理? 5.网关组件?
# 1.核心组件说明 - eurekaserver、consul、nacos 服务注册中心组件 - rabbion & openfeign 服务负载均衡 和 服务调用组件 - hystrix & hystrix dashboard 服务断路器 和 服务监控组件 - zuul、gateway 服务网关组件 - config 统一配置中心组件 - bus 消息总线组件 ......
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. ---[摘自官网]
# 1.翻译 - springcloud 版本管理方式: 命名方式 Angel.SR1~6 Brixton.SR1~6 Camden.SR1~6 - springcloud是一个由众多独立子项目组成的大型综合项目,原则每一个子项目上有不一样的发布节奏,都维护本身发布版本号。为了更好的管理springcloud的版本,经过一个资源清单BOM(Bill of Materials),为避免与子项目的发布号混淆,因此没有采用版本号的方式,而是经过命名的方式。这些名字是按字母顺序排列的。如伦敦地铁站的名称(“天使”是第一个版本,“布里斯顿”是第二个版本,"卡姆登"是第三个版本)。当单个项目的点发布累积到一个临界量,或者其中一个项目中有一个关键缺陷须要每一个人均可以使用时,发布序列将推出名称以“.SRX”结尾的“服务发布”,其中“X”是一个数字。 # 2.伦敦地铁站名称 [了解] - Angel、Brixton、Camden、Dalston、Edgware、Finchley、Greenwich、Hoxton、
# 1.版本选择官方建议 https://spring.io/projects/spring-cloud - Angel 版本基于springboot1.2.x版本构建与1.3版本不兼容 - Brixton 版本基于springboot1.3.x版本构建与1.2版本不兼容 `2017年Brixton and Angel release官方宣布报废 - Camden 版本基于springboot1.4.x版本构建并在1.5版本经过测试 `2018年Camden release官方宣布报废 - Dalston、Edgware 版本基于springboot1.5.x版本构建目前不能再springboot2.0.x版本中使用 `Dalston(达尔斯顿)将于2018年12月官方宣布报废。Edgware将遵循Spring Boot 1.5.x的生命周期结束。 - Finchley 版本基于springboot2.0.x版本进行构建,不能兼容1.x版本 - Greenwich 版本基于springboot2.1.x版本进行构建,不能兼容1.x版本 - Hoxton 版本基于springboot2.2.x版本进行构建
仍是建立springboot的方式
# 0.说明 - springboot 2.2.x.RELEASE+ - springcloud Hoxton SR1~6 - java8+ - maven 3.3.6+ - idea 2018.3.5+ # 1.建立springboot项目 指定版本为 2.2.5版本
# 2.引入springcloud的版本管理
<!--定义springcloud使用版本号--> <properties> <java.version>1.8</java.version> <spring-cloud.version>Hoxton.SR6</spring-cloud.version> </properties> <!--全局管理springcloud版本,并不会引入具体依赖--> <dependencyManagement> <dependencies> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-dependencies</artifactId> <version>${spring-cloud.version}</version> <type>pom</type> <scope>import</scope> </dependency> </dependencies> </dependencyManagement>
# 3.完成上述操做springboot与springcloud环境搭建完成 - 接下来就是使用到具体的springcloud组件,在项目中引入具体的组件便可
<?xml version="1.0" encoding="UTF-8"?> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>2.2.5.RELEASE</version> <relativePath/> <!-- lookup parent from repository --> </parent> <groupId>com.md</groupId> <artifactId>01-hello</artifactId> <version>0.0.1-SNAPSHOT</version> <name>01-hello</name> <description>Demo project for Spring Boot</description> <properties> <java.version>1.8</java.version> <!--定义springcloud使用版本号--> <spring-cloud.version>Hoxton.SR6</spring-cloud.version> </properties> <dependencies> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-test</artifactId> <scope>test</scope> </dependency> </dependencies> <!--全局管理springcloud版本,并不会引入具体依赖--> <dependencyManagement> <dependencies> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-dependencies</artifactId> <version>${spring-cloud.version}</version> <type>pom</type> <scope>import</scope> </dependency> </dependencies> </dependencyManagement> <build> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> </plugin> </plugins> </build> </project>