一、SpringCloud简介

springcloud官方文档(Hoxton SR5
springcloud中文文档
76b412fd4b8a48cd912c5048b49d7e59.png
20200603155055794.png

1、服务治理

服务治理就是进行服务的自动化管理,其核心是服务的自动注册与发现。

  • 服务注册:服务实例将自身服务信息注册到注册中心
  • 服务发现:服务实例通过注册中心,获取到注册到其中的服务实例的信息,通过这些信息去请求它们提供的服务。
  • 服务剔除:服务注册中心将出问题的服务自动剔除到可用列表之外,使其不会被调用到。

    2、服务调用

    多个服务之间的远程调用,目前主流的远程调用技术有基于HTTP的RESTful接口以及基于TCP的RPC协议。
    a5980306d1c646b999d8632c284889a3.png

    3、服务网关

    API网关直面意思是将所有API调用统一接入到API网关层,由网关层统一接入和输出。
    一个网关的基本功能有:统一接入、安全防护、协议适配、流量管控、长短链接支持、容错能力。

    4、服务容错

    在微服务当中,一个请求经常会涉及到调用几个服务,如果其中某个服务不可用,没有做服务容错的话,极有可能会造成一连串的服务不可用,这就是雪崩效应。
    我们没法预防雪崩效应的发生,只能尽可能去做好容错。服务容错的三个核心思想是:
  1. 不被外界环境影响
  2. 不被上游请求压垮
  3. 不被下游响应拖垮

fa67b8575dd0407ab1e49c623cc31ad9.png

5、链路追踪

一次请求往往需要涉及到多个服务,因此需要对一次请求涉及的多个服务链路进行日志记录,性能监控即链路追踪。

二、Spring Cloud Alibaba

1、简介

Spring官网:https://spring.io/projects/spring-cloud-alibaba
GitHub:https://github.com/alibaba/spring-cloud-alibaba
GitHub中文文档:https://github.com/alibaba/spring-cloud-alibaba/blob/master/README-zh.md
版本说明:https://github.com/alibaba/spring-cloud-alibaba/wiki/版本说明
阿里云脚手架构建项目:https://start.aliyun.com/bootstrap.html
版本说明

Spring Cloud Alibaba Version Spring Cloud Version Spring Boot Version
2021.0.4.0* Spring Cloud 2021.0.4 2.6.11
2021.0.1.0 Spring Cloud 2021.0.1 2.6.3
2021.1 Spring Cloud 2020.0.1 2.4.2

组件版本关系

Spring Cloud Alibaba Version Sentinel Version Nacos Version RocketMQ Version Dubbo Version Seata Version
2.2.10-RC1 1.8.6 2.2.0 4.9.4 ~ 1.6.1
2022.0.0.0-RC1 1.8.6 2.2.1-RC 4.9.4 ~ 1.6.1
2.2.9.RELEASE 1.8.5 2.1.0 4.9.4 ~ 1.5.2
2021.0.4.0 1.8.5 2.0.4 4.9.4 ~ 1.5.2
2.2.8.RELEASE 1.8.4 2.1.0 4.9.3 ~ 1.5.1
2021.0.1.0 1.8.3 1.4.2 4.9.2 ~ 1.4.2
2.2.7.RELEASE 1.8.1 2.0.3 4.6.1 2.7.13 1.3.0
2.2.6.RELEASE 1.8.1 1.4.2 4.4.0 2.7.8 1.3.0

2、搭建框架

利用阿里云脚手架构建项目:https://start.aliyun.com/bootstrap.html,进行搭建。
这里选择SpringBoot版本为:2.6.11,对应的SpringCloudAlibaba版本为2021.0.4.0
版本说明:https://spring-cloud-alibaba-group.github.io/github-pages/2021/zh-cn/index.html

  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  3. xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
  4. <modelVersion>4.0.0</modelVersion>
  5. <parent>
  6. <groupId>org.springframework.boot</groupId>
  7. <artifactId>spring-boot-starter-parent</artifactId>
  8. <version>2.6.11</version>
  9. <relativePath/> <!-- lookup parent from repository -->
  10. </parent>
  11. <groupId>com.example</groupId>
  12. <artifactId>demo</artifactId>
  13. <version>0.0.1-SNAPSHOT</version>
  14. <name>demo</name>
  15. <description>Demo project for Spring Boot</description>
  16. <properties>
  17. <java.version>1.8</java.version>
  18. <spring-cloud-alibaba.version>2021.0.4.0</spring-cloud-alibaba.version>
  19. </properties>
  20. <dependencies>
  21. <dependency>
  22. <groupId>org.springframework.boot</groupId>
  23. <artifactId>spring-boot-starter</artifactId>
  24. </dependency>
  25. <dependency>
  26. <groupId>com.alibaba.cloud</groupId>
  27. <artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId>
  28. </dependency>
  29. <dependency>
  30. <groupId>org.springframework.boot</groupId>
  31. <artifactId>spring-boot-starter-test</artifactId>
  32. <scope>test</scope>
  33. </dependency>
  34. </dependencies>
  35. <dependencyManagement>
  36. <dependencies>
  37. <dependency>
  38. <groupId>com.alibaba.cloud</groupId>
  39. <artifactId>spring-cloud-alibaba-dependencies</artifactId>
  40. <version>${spring-cloud-alibaba.version}</version>
  41. <type>pom</type>
  42. <scope>import</scope>
  43. </dependency>
  44. </dependencies>
  45. </dependencyManagement>
  46. <build>
  47. <plugins>
  48. <plugin>
  49. <groupId>org.apache.maven.plugins</groupId>
  50. <artifactId>maven-compiler-plugin</artifactId>
  51. <version>3.8.1</version>
  52. <configuration>
  53. <source>1.8</source>
  54. <target>1.8</target>
  55. <encoding>UTF-8</encoding>
  56. </configuration>
  57. </plugin>
  58. <plugin>
  59. <groupId>org.springframework.boot</groupId>
  60. <artifactId>spring-boot-maven-plugin</artifactId>
  61. </plugin>
  62. </plugins>
  63. </build>
  64. </project>