microservices 简介

油鹳视频 Microservices explained - the What, Why and How?
https://www.youtube.com/watch?v=rv4LlmLmVWk&t=2s


microservices 是一种软件体系结构, microservices architecture(微服务架构) 是与传统的 monolithic architecture(整体式架构,一体式架构) 相对而言的。简单地说,微服务架构就是将一个大的 app 进行拆分,分成若干小的的应用程序,各自独立开发部署。

1 一体式架构 monolithic architecture

1.1 一体式架构的特点

  1. 所有组件都合属于一个单一的整体: user-auth, product-catalog, shopping-cart, payment…
  2. 所有组件都作为一个整体进行开发,部署以及扩展。
  3. App 各组件必须使用同一技术栈。
  4. 组件相互依存,各个组件开发团队必须小心避免影响到其他团队的开发。
  5. 一个组件被修改,整个 app 重新部署。

1.2 一体式架构面临的挑战

  1. app 太大太复杂
  2. 各个组成部分纠缠在一起
  3. 如果需要扩展就必须扩展整个 app,不能是单个模块,单个服务。
  4. 不同的组件依赖于相同的第三方组件,然而各自依赖的版本却不同,该如何解决这个问题?

在这里插入图片描述

  1. 任何组件发生改变,整个 app 必须重新测试,重新构建,重新部署。
  2. 任何模块的 bug 都能让整个 app crash。

为了应对如上问题,出现了 microservices architecture 微服务软件架构 。

2 微服务架构 microservices architecture

使用微服务架构,将一体式的 app 进行拆分,分成多个更小的、独立的应用程序 / 微服务,这些相互独立的微应用程序共同组成一个大型的 app。

这些不同的微服务可以由不同的 team 使用不同的技术栈独立进行开发部署。

在这里插入图片描述

要使用这种架构,需要考虑如下问题:

  1. 如何拆分 app?

  2. 要拆分成多少个 microservices?

  3. microservices 的规模?

  4. 如何组织这些 microservices?

  5. 这些被拆分的 microservices 之间如何通信?

2.1 app 的拆分

根据业务功能对 app 进行拆分,以在线购物 app 为例,拆成 user, products, shopping carts, checkout 等不同的 micorservice,一个 micorservice 负责一项特定的工作。
各个 micorservice 高内聚,micorservice 之间低耦合,各个 micorservice 的开发、部署与扩展与其他 micorservice 互相独立。各个 micorservice 也因此拥有各自独立的版本,发布周期各自独立,如果更新并部署 一个 micorservice,其他 micorservice 不受影响。

在这里插入图片描述

2.2 微服务之间如何通信

2.2.1 使用 API 调用通信

在这里插入图片描述

各个微服务之间使用 API 通信,这种通信方式为同步通信

2.2.2 使用 Message Broker 通信

一种 Message Broker: RabbitMQ

在这里插入图片描述

在这里插入图片描述

微服务首先与 Message Broker 通信,再由 Message Broker 转发,这种通信方式为异步通信

2.2.3 使用服务网格 service mesh 进行通信

这种通信方式也被 Kubernetes 广为使用。

在这里插入图片描述

3 微服务架构的缺点以及解决方案

微服务架构本质上是一个分布式系统,这种体系结构比整体式架构复杂。首先需要配置各个微服务之间的通信,而且监视分布在多个服务器上的微服务实例也非易事。

Kubernetes 是运行大型微服务应用程序的完美平台, 除此以外, HashiCorp 也可以用于微服务架构开发。

在这里插入图片描述

4 微服务的 CI/CD 管道

CI /CD: Continuous Integration/ Continuous Delivery
持续集成 / 持续交付,
( delivery: 分发,交付,部署 )
在这里插入图片描述
一些大型应用程序由上百个 microservice 组成,每天进行数千次的部署,CI/CD 管道用于配置 release 过程。

5 代码管理:Monorepo vs Polyrepo

组织和管理代码有两种方法, Monorepo (单个库) vs Polyrepo (多个库)

在这里插入图片描述

1, 使用单个 git 库,存放若干工程代码。缺点,容易产生高耦合代码,代码库巨大,push pull 等操作变慢,需额外设置 CI/CD 管道。(CI/CD 平台有 gitlab, jenkens) 虽有缺点,但 Google 就使用 monorepo.

2,使用多个 git 库,一个库一个微应用程序。
Gitlab 使用 group 将多个共属于一个app的工程放到相同的组。

在这里插入图片描述

Polyrepo 也有缺点,例如多个项目之间资源共享变得困难,项目之间的切换变得繁琐等等。

所以这两种方法各有优缺点,基本的原则是,小的项目使用单个库 monorepo,如果开发大型 app,有多个 team,使用多个库 polyrepo 则是更好的选择。


  1. https://aws.amazon.com/cn/microservices/
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Book Description Build a microservices architecture with Spring Boot, by evolving an application from a small monolith to an event-driven architecture composed of several services. This book follows an incremental approach to teach microservice structure, test-driven development, Eureka, Ribbon, Zuul, and end-to-end tests with Cucumber. Author Moises Macero follows a very pragmatic approach to explain the benefits of using this type of software architecture, instead of keeping you distracted with theoretical concepts. He covers some of the state-of-the-art techniques in computer programming, from a practical point of view. You'll focus on what's important, starting with the minimum viable product but keeping the flexibility to evolve it. What You'll Learn Build microservices with Spring Boot Use event-driven architecture and messaging with RabbitMQ Create RESTful services with Spring Master service discovery with Eureka and load balancing with Ribbon Route requests with Zuul as your API gateway Write end-to-end rest tests for an event-driven architecture using Cucumber Carry out continuous integration and deployment Who This Book Is For Those with at least some prior experience with Java programming. Some prior exposure to Spring Boot recommended but not required. Table of Contents Chapter 1: Introduction Chapter 2: The Basic Spring Boot Application Chapter 3: A Real Three-Tier Spring Boot Application Chapter 4: Starting with Microservices Chapter 5: The Microservices Journey Through Tools Chapter 6: Testing the Distributed System Appendix A: Upgrading to Spring Boot 2.0

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值