31
Confidential ©2020 VMware, Inc. Microservice & Spring Catalyze enterprise transformation through software 罗治年 Robert Luo [email protected] Jun, 2020

微服务架构最佳实践 - Spring 框架-课件¾®服务架构最佳... · Confidential │ ©2020VMware, Inc. 3 微 服务架构是一种方式将单一的应用使用一套微型服务的方式来构建,

  • Upload
    others

  • View
    16

  • Download
    0

Embed Size (px)

Citation preview

Page 1: 微服务架构最佳实践 - Spring 框架-课件¾®服务架构最佳... · Confidential │ ©2020VMware, Inc. 3 微 服务架构是一种方式将单一的应用使用一套微型服务的方式来构建,

Confidential │ ©2020 VMware, Inc.

Microservice & SpringCatalyze enterprise transformation through software

罗治年 Robert Luo

[email protected]

Jun, 2020

Page 2: 微服务架构最佳实践 - Spring 框架-课件¾®服务架构最佳... · Confidential │ ©2020VMware, Inc. 3 微 服务架构是一种方式将单一的应用使用一套微型服务的方式来构建,

2Confidential │ ©2020 VMware, Inc.

微服务

Page 3: 微服务架构最佳实践 - Spring 框架-课件¾®服务架构最佳... · Confidential │ ©2020VMware, Inc. 3 微 服务架构是一种方式将单一的应用使用一套微型服务的方式来构建,

3Confidential │ ©2020 VMware, Inc.

微服务架构是一种方式将单一的应用使用一套微型服务的方式来构建,这些微型的服务在各自的进程中运行并通过轻量级的进程通讯方式交互(通常是HTTP的API方式)。这些服务基于业务职能构建并能够由全自动的部署方式进行单独的部署,这些服务是去中心化的并有可能由不同的开发语言使用不同的数据存储模式来构建。

Page 4: 微服务架构最佳实践 - Spring 框架-课件¾®服务架构最佳... · Confidential │ ©2020VMware, Inc. 3 微 服务架构是一种方式将单一的应用使用一套微型服务的方式来构建,

Confidential │ ©2020 VMware, Inc. 4

单体架构 ->微服务架构

https://martinfowler.com/bliki/MicroservicePremium.html

2-pizza team

Page 5: 微服务架构最佳实践 - Spring 框架-课件¾®服务架构最佳... · Confidential │ ©2020VMware, Inc. 3 微 服务架构是一种方式将单一的应用使用一套微型服务的方式来构建,

Confidential │ ©2020 VMware, Inc.

单体-> 模块化单体 -> 微服务

痛定思痛后的架构转型● Ebay (1999)●Microsoft (2002)●Amazon (2004): Jeff Bezos 备忘录● Google (2005): 自动测试文化● Twitter (2008)● LinkedIn (2011): 2个月的feature freeze● Etsy (2009)

Page 6: 微服务架构最佳实践 - Spring 框架-课件¾®服务架构最佳... · Confidential │ ©2020VMware, Inc. 3 微 服务架构是一种方式将单一的应用使用一套微型服务的方式来构建,

Confidential │ ©2020 VMware, Inc.

亚马逊 – Bezos 备忘录 (2004)

• 所有团队必须要以服务接口的方式,提供业务数据和功能

• 团队间必须通过接口来交互

• 只允许网络调用方式,不允许任何其他形式的相互操作:

• 不允许直接读其他团队的数据,不允许共享内存,不允许任何形式的后门

• 具体实现方式和技术没有强制规定, HTTP,消息通信,自定义协议等都可以

• 所有服务接口,必须都是对外公开的开放接口

• 谁构建的服务,谁就负责运行(全生命周期)

• 如不遵守以上原则,就会被解雇

Page 7: 微服务架构最佳实践 - Spring 框架-课件¾®服务架构最佳... · Confidential │ ©2020VMware, Inc. 3 微 服务架构是一种方式将单一的应用使用一套微型服务的方式来构建,

Confidential │ ©2020 VMware, Inc.

模块化单体->微服务:遵循同样的设计原则

‣ 高聚合

‣ 低耦合

‣ 聚焦于业务能力

‣ 限界上下文/聚合

‣ 独⽴部署

‣ 独⽴发布/升级

‣ 独⽴扩展伸缩

‣ 不同种技术栈

Page 8: 微服务架构最佳实践 - Spring 框架-课件¾®服务架构最佳... · Confidential │ ©2020VMware, Inc. 3 微 服务架构是一种方式将单一的应用使用一套微型服务的方式来构建,

Confidential │ ©2020 VMware, Inc. 8

微服务到底应该有多”微”?

Page 9: 微服务架构最佳实践 - Spring 框架-课件¾®服务架构最佳... · Confidential │ ©2020VMware, Inc. 3 微 服务架构是一种方式将单一的应用使用一套微型服务的方式来构建,

Confidential │ ©2020 VMware, Inc. 9

微服务拆分考虑要素首先基于业务领域,然后再考虑……

业务需求变化的速度

发布的周期与节奏

不同的伸缩/扩展/安全需求

控制失效范围/故障影响

屏蔽外部依赖或系统的变化

最适合的技术选择

Page 10: 微服务架构最佳实践 - Spring 框架-课件¾®服务架构最佳... · Confidential │ ©2020VMware, Inc. 3 微 服务架构是一种方式将单一的应用使用一套微型服务的方式来构建,

Confidential │ ©2020 VMware, Inc. 10

微服务模式

Page 11: 微服务架构最佳实践 - Spring 框架-课件¾®服务架构最佳... · Confidential │ ©2020VMware, Inc. 3 微 服务架构是一种方式将单一的应用使用一套微型服务的方式来构建,

11Confidential │ ©2020 VMware, Inc.

Spring

Page 12: 微服务架构最佳实践 - Spring 框架-课件¾®服务架构最佳... · Confidential │ ©2020VMware, Inc. 3 微 服务架构是一种方式将单一的应用使用一套微型服务的方式来构建,

Confidential │ ©2020 VMware, Inc.

12

Java 仍然是企业使用最广泛的开发语言

According to the annual TIOBE Index - TIOBE checks more than 1056 million lines of software code for its customers world-wide, every day.

Page 13: 微服务架构最佳实践 - Spring 框架-课件¾®服务架构最佳... · Confidential │ ©2020VMware, Inc. 3 微 服务架构是一种方式将单一的应用使用一套微型服务的方式来构建,

Confidential │ ©2020 VMware, Inc.

JetB

rain

s Jav

a Su

rvey

201

9

Page 14: 微服务架构最佳实践 - Spring 框架-课件¾®服务架构最佳... · Confidential │ ©2020VMware, Inc. 3 微 服务架构是一种方式将单一的应用使用一套微型服务的方式来构建,

Confidential │ ©2020 VMware, Inc.

Spring的使用与日俱增...

In 2018 Spring Initializrgenerated over 10 million

Spring projects!

Page 15: 微服务架构最佳实践 - Spring 框架-课件¾®服务架构最佳... · Confidential │ ©2020VMware, Inc. 3 微 服务架构是一种方式将单一的应用使用一套微型服务的方式来构建,

Confidential │ ©2020 VMware, Inc.

使用Spring Initializr创建微服务项目骨架

Page 16: 微服务架构最佳实践 - Spring 框架-课件¾®服务架构最佳... · Confidential │ ©2020VMware, Inc. 3 微 服务架构是一种方式将单一的应用使用一套微型服务的方式来构建,

Confidential │ ©2020 VMware, Inc.

Page 17: 微服务架构最佳实践 - Spring 框架-课件¾®服务架构最佳... · Confidential │ ©2020VMware, Inc. 3 微 服务架构是一种方式将单一的应用使用一套微型服务的方式来构建,

Confidential │ ©2020 VMware, Inc. 17

Spring Framework企业级 Java 应用框架/类库

A Rich, Fully Integrated Toolbox:

🔐 OAuth2, Kerberos, SAML🔌 REST, MVC, HATEOAS, Sockets, SOAP🔎 JDBC, JPA, noSQL, Search📬 Batching, scheduling, messaging, caching📱Mobile, iOS & Android⏰ Reactive, asynchronous, synchronous✅ Testing, AOP, expressions, metrics…☕ Java, Groovy, Kotlin

Page 18: 微服务架构最佳实践 - Spring 框架-课件¾®服务架构最佳... · Confidential │ ©2020VMware, Inc. 3 微 服务架构是一种方式将单一的应用使用一套微型服务的方式来构建,

Confidential │ ©2020 VMware, Inc.

Spring Boot构建一切

Spring Cloud协调一切

Spring Cloud Data Flow连接一切

Spring:云原生Java的标准

代码清晰 | 降低复杂性 | 减少技术负债 | 专注于业务逻辑 | 测试覆盖面更广 | 代码完成速度更快

Page 19: 微服务架构最佳实践 - Spring 框架-课件¾®服务架构最佳... · Confidential │ ©2020VMware, Inc. 3 微 服务架构是一种方式将单一的应用使用一套微型服务的方式来构建,

Confidential │ ©2020 VMware, Inc.

Spring Boot – Spring微服务的开发框架

Spring Boot

Auto Configure

POM Starters

Quick Start

Actuator

Dev Tools

$ java –jar myapp.jar

ConfigurationConvention

五分钟运行微服务

聚焦于应用逻辑

Page 20: 微服务架构最佳实践 - Spring 框架-课件¾®服务架构最佳... · Confidential │ ©2020VMware, Inc. 3 微 服务架构是一种方式将单一的应用使用一套微型服务的方式来构建,

Confidential │ ©2020 VMware, Inc.

Spring Boot 2

Spring Boot 2

Page 21: 微服务架构最佳实践 - Spring 框架-课件¾®服务架构最佳... · Confidential │ ©2020VMware, Inc. 3 微 服务架构是一种方式将单一的应用使用一套微型服务的方式来构建,

Confidential │ ©2020 VMware, Inc.

Spring Cloud –微服务“全家桶”

Gateway

TracingDiscovery

Breaker

Connector

Config

微服务组件 Spring Cloud

服务注册中心 Spring Cloud Service Discovery (Netflix Eureka)

断路器 Spring Cloud Circuit Breaker(Hystrix + Turbine / Resilience4J)

服务网关 Spring Cloud Gateway, Spring Cloud Netflix Zuul

负载均衡 Spring Cloud Load Balancer (Netflix Ribbon)

分布式配置 Spring Cloud Config

服务跟踪 Spring Cloud Sleuth

消息总线 Spring Cloud Bus

数据流处理 Spring Cloud Stream

批处理任务 Spring Cloud Task

安全 Spring Cloud Security

数据微服务框架 Spring Cloud Data Flow

函数 Spring Cloud Function

Kubernetes Spring Cloud Kubernetes

Page 22: 微服务架构最佳实践 - Spring 框架-课件¾®服务架构最佳... · Confidential │ ©2020VMware, Inc. 3 微 服务架构是一种方式将单一的应用使用一套微型服务的方式来构建,

Confidential │ ©2020 VMware, Inc.

Netflix不再提供活跃支持怎么办?

From To

Spring Cloud Netflix Ribbon Spring Cloud Load Balancer

Spring Cloud Netflix Zuul Spring Cloud Gateway

Spring Cloud Netflix Hystrix Spring Cloud Circuit Breaker +Resilience4J

Spring Cloud Netflix Turbine Micrometer + Prometheus

Spring Cloud Netflix Archaius Spring Cloud Config Server

Spring Cloud Netflix Eureka Spring Cloud Service Discovery

Page 23: 微服务架构最佳实践 - Spring 框架-课件¾®服务架构最佳... · Confidential │ ©2020VMware, Inc. 3 微 服务架构是一种方式将单一的应用使用一套微型服务的方式来构建,

Confidential │ ©2020 VMware, Inc.

Steeltoe: cloud native .Net microservices

Service DiscoveryHow do you keep track of the services you depend on, as they dynamically scale out and in, changing addresses along the way? Simple, Netflix Eureka.

Config ServerSpring Cloud Config Server provides a mechanism to store your application’s configuration externally, and have it injected into your application at runtime.

Cloud Security ProvidersIntegrate a variety of identity providers, like ADFS, with a cloud native .NET application, by simply binding to the application.

Circuit BreakersBypass a failing service, allowing it time to recover, and prevent your users from seeing error messages with Netflix Hystrix.

Cloud ConnectorsAutomatically configuring and wiring up connections to common Cloud Foundry services like Redis, RabbitMQ, MySQL and Postgres

.Net Steeltoe Initializer:https://start.steeltoe.io/

Page 24: 微服务架构最佳实践 - Spring 框架-课件¾®服务架构最佳... · Confidential │ ©2020VMware, Inc. 3 微 服务架构是一种方式将单一的应用使用一套微型服务的方式来构建,

Confidential │ ©2020 VMware, Inc.

Spring Cloud Data Flow

由Spring Boot应用组成的数据流水线, 使用Spring Cloud Stream 事件流处理,使用 Spring Cloud Task 批处理.

有超过60个现成的流处理或批处理的组件供数据集成.

有DSL, 图形界面, 和 REST-APIs 用于构建和调度数据流水线,运行在 Kubernetes 和 Cloud Foundry上.

通过Spring Cloud Skipper 持续交付流处理数据流水线.

使用Spring Cloud Scheduler调度时间(cron)触发的批处理数据流水线.

数据类应用框架,用于数据集

成,实时流处理,批处理等数

据流水线.

Page 25: 微服务架构最佳实践 - Spring 框架-课件¾®服务架构最佳... · Confidential │ ©2020VMware, Inc. 3 微 服务架构是一种方式将单一的应用使用一套微型服务的方式来构建,

Confidential │ ©2020 VMware, Inc.

Spring Cloud Task + Spring cloud Stream

批处理

Spring Cloud Task

Task是短生命周期的Spring Boot 微服务,

连接到数据源/持久化存储,系统追踪任务

的调用和退出状态

流处理

Spring Cloud Stream

基于事件的消息流的微服务. 支持消息中间

件(如RabbitMQ或Kafka),Pub/Sub主题订阅

模式确保松耦合

Page 26: 微服务架构最佳实践 - Spring 框架-课件¾®服务架构最佳... · Confidential │ ©2020VMware, Inc. 3 微 服务架构是一种方式将单一的应用使用一套微型服务的方式来构建,

Confidential │ ©2020 VMware, Inc.

Spring Cloud Data Flow

Page 27: 微服务架构最佳实践 - Spring 框架-课件¾®服务架构最佳... · Confidential │ ©2020VMware, Inc. 3 微 服务架构是一种方式将单一的应用使用一套微型服务的方式来构建,

Confidential │ ©2020 VMware, Inc.

Spring Cloud Kubernetes• Spring cloud Kubernetes已经实现了

与Kubernetes的初步整合,包括• 服务发现• 客户端负载均衡

• 配置管理

• Spring Cloud Kubernetes将持续跟踪发展,简化开发人员的工作

Page 28: 微服务架构最佳实践 - Spring 框架-课件¾®服务架构最佳... · Confidential │ ©2020VMware, Inc. 3 微 服务架构是一种方式将单一的应用使用一套微型服务的方式来构建,

Confidential │ ©2020 VMware, Inc.

Spring Cloud +公有云

● Nacos configuration &Service Discovery

● Sentinel flow control &circuit breaker

● Dubbo RPC● RocketMQ● Storage (OSS)

● Auto configuration● Messaging● Storage

● Auto configuration● Active Directory● Key Vault● Storage

● Auto configuration● RDS● SQS

Page 29: 微服务架构最佳实践 - Spring 框架-课件¾®服务架构最佳... · Confidential │ ©2020VMware, Inc. 3 微 服务架构是一种方式将单一的应用使用一套微型服务的方式来构建,

Confidential │ ©2020 VMware, Inc.

Spring Cloud Function

• FaaS Portable • And run in Spring Boot• REST, Tasks, or Streams

一个Spring开源FaaS项目

Page 30: 微服务架构最佳实践 - Spring 框架-课件¾®服务架构最佳... · Confidential │ ©2020VMware, Inc. 3 微 服务架构是一种方式将单一的应用使用一套微型服务的方式来构建,

Confidential │ ©2020 VMware, Inc. 30

无需注册和许可证免费遥测 Spring Boot 应用

免费的自动配置的遥测与监控

现成的仪表盘,显示RED, 和服务调用关

系图.数据保留5天

Metrics - 50 pps, Traces - 25 sps,

Histograms - 10 dps, Span logs

Spring Cloud Sleuth &

Open Tracing

无需注册和许可证

Page 31: 微服务架构最佳实践 - Spring 框架-课件¾®服务架构最佳... · Confidential │ ©2020VMware, Inc. 3 微 服务架构是一种方式将单一的应用使用一套微型服务的方式来构建,

Confidential │ ©2020 VMware, Inc.

Thank YouPlease email any questions to [email protected]