什么是微服务
Martin Flowler 在其论文中对微服务做了如下阐述:
While there is no precise definition of this architectural style
目前业界并没有一个统一的,标准的定义
In short, the microservice architectural style [1] 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.
微服务架构是一种架构风格,提倡将单一应用程序拆分为一组小的服务,每个服务由独立的进程运行,服务之间采用轻量级的通信机制(HTTP + JSON 的 RESTful API)实现相互调用,相互协作。每个服务都基于具体业务构建,并且能够被独立的部署。服务之间非集中式管理,可以使用不同的语言来编写服务,可以使用不同的数据存储。
总结:
- 一组小的服务,基于业务的相对小的服务
- 独立的进程,每个服务运行于独立的进程
- 服务之间采用轻量级的通信机制(RESTful API,采用 HTTP + JSON)
- 基于业务构建服务
- 服务可以被独立部署
- 服务无集中式管理
微服务 VS 微服务架构
微服务
简单来说,强调的是服务本身,比如服务的大小,服务解决的业务,服务的实现方式,服务的具体功能等等
微服务架构
倾向于描述架构的风格,强调的是服务间的关系,服务间的通信机制,服务之间是否存在耦合等等
微服务架构优点 VS 微服务架构缺点
优点和缺点都是相对的。
优点
每个服务足够内聚,代码更容易阅读和理解,具有强模块化边界
每个服务开发简单,开发效率高,适合小规模团队的开发
每个服务可以聚集于业务实现,开发更加专注
服务间是松散耦合,可独立开发,独立测试,独立上线,独立部署
服务的开发语言可以多种多样,数据存储可以多种多样
缺点
分布式系统的复杂性,集成测试复杂,运维复杂
分布式通信,分布式事务,数据一致性
分布式服务调用链监控
分布式服务性能监控
微服务技术栈
服务开发:Spring SpringMVC SpringBoot
服务配置与管理: Netflix Archaius ,Alibaba Diamond
服务注册与发现:Eureka Consul Zookeeper
服务调用:RESTful RPC gRPC
服务熔断器:Hystrix Envoy
负载均衡:Ribbon Nginx
服务接口调用:Feign
消息队列:Kafka RabbitMQ ActiveMQ
服务配置中心:SpringCloud Config
服务网关:Zuul
服务监控:Zabbix Nagios Metrics Spectator
全链路追踪:Zipkin Brave Dapper
服务部署:Docker OpenStack Kubernetes
数据流:SpringCloud Stream
事件消息总线:SpringCloud Bus
为什么选择 SpringCloud
SpringCloud 提供整体解决方案,框架成熟度高
SpringCloud 社区热
SpringCloud 可维护性高
SpringCloud 学习成本低
参考资料
Martin Flowler 微服务论文地址:Microservices