简介

SpringCloud Alibaba是阿里巴巴集团开源的一套微服务架构解决方案。

微服务架构是为了更好的分布式系统开发,将一个应用拆分成多个子应用,每一个服务都是可以独立运行的子工程。其中涵盖了非常多的内容,包括:服务治理、配置管理、限流降级以及对阿里开源生态(Dubbo、RocketMQ等)支持的N多组件。

SpringCloud Alibaba相关组件

  • Sentinel:阿里巴巴开源产品,把流量作为切入点,从流量控制、熔断降级、系统负载保护等多个维度保护服务的稳定性。
  • Nacos:阿里巴巴开源产品,一个更易于构建云原生应用的动态服务发现、配置管理和服务管理平台。
  • RocketMQ:Apache RocketMQ 基于 Java 的高性能、高吞吐量的分布式消息和流计算平台。
  • Dubbo:Apache Dubbo 是一款高性能 Java RPC 框架。
  • Seata:阿里巴巴开源产品,一个易于使用的高性能微服务分布式事务解决方案。
  • Alibaba Cloud ACM:一款在分布式架构环境中对应用配置进行集中管理和推送的应用配置中心产品。
  • Alibaba Cloud OSS: 阿里云对象存储服务(Object Storage Service,简称 OSS),是阿里云提供的海量、安全、低成本、高可靠的云存储服务。您可以在任何应用、任何时间、任何地点存储和访问任意类型的数据。
  • Alibaba Cloud SchedulerX: 阿里中间件团队开发的一款分布式任务调度产品,提供秒级、精准、高可靠、高可用的定时(基于 Cron 表达式)任务调度服务。
  • Alibaba Cloud SMS: 覆盖全球的短信服务,友好、高效、智能的互联化通讯能力,帮助企业迅速搭建客户触达通道。

主要功能

  • 服务限流降级:默认支持 WebServlet、WebFlux, OpenFeign、RestTemplate、Spring Cloud Gateway, Zuul, Dubbo 和 RocketMQ 限流降级功能的接入,可以在运行时通过控制台实时修改限流降级规则,还支持查看限流降级 Metrics 监控。
  • 服务注册与发现:适配 Spring Cloud 服务注册与发现标准,默认集成了 Ribbon 的支持。
  • 分布式配置管理:支持分布式系统中的外部化配置,配置更改时自动刷新。
  • 消息驱动能力:基于 Spring Cloud Stream 为微服务应用构建消息驱动能力。
  • 分布式事务:使用 @GlobalTransactional 注解, 高效并且对业务零侵入地解决分布式事务问题。。
  • 阿里云对象存储:阿里云提供的海量、安全、低成本、高可靠的云存储服务。支持在任何应用、任何时间、任何地点存储和访问任意类型的数据。
  • 分布式任务调度:提供秒级、精准、高可靠、高可用的定时(基于 Cron 表达式)任务调度服务。同时提供分布式的任务执行模型,如网格任务。网格任务支持海量子任务均匀分配到所有 Worker(schedulerx-client)上执行。
  • 阿里云短信服务:覆盖全球的短信服务,友好、高效、智能的互联化通讯能力,帮助企业迅速搭建客户触达通道。

组件版本关系

Spring Cloud Alibaba Version Sentinel Version Nacos Version RocketMQ Version Dubbo Version Seata Version
2.2.6.RELEASE 1.8.1 1.4.2 4.4.0 2.7.8 1.3.0
2021.1 or 2.2.5.RELEASE or 2.1.4.RELEASE or 2.0.4.RELEASE 1.8.0 1.4.1 4.4.0 2.7.8 1.3.0
2.2.3.RELEASE or 2.1.3.RELEASE or 2.0.3.RELEASE 1.8.0 1.3.3 4.4.0 2.7.8 1.3.0
2.2.1.RELEASE or 2.1.2.RELEASE or 2.0.2.RELEASE 1.7.1 1.2.1 4.4.0 2.7.6 1.2.0
2.2.0.RELEASE 1.7.1 1.1.4 4.4.0 2.7.4.1 1.0.0
2.1.1.RELEASE or 2.0.1.RELEASE or 1.5.1.RELEASE 1.7.0 1.1.4 4.4.0 2.7.3 0.9.0
2.1.0.RELEASE or 2.0.0.RELEASE or 1.5.0.RELEASE 1.6.3 1.1.1 4.4.0 2.7.3 0.7.1

毕业版本依赖关系

Spring Cloud Version Spring Cloud Alibaba Version Spring Boot Version
Spring Cloud 2020.0.1 2021.1 2.4.2
Spring Cloud Hoxton.SR9 2.2.6.RELEASE 2.3.2.RELEASE
Spring Cloud Greenwich.SR6 2.1.4.RELEASE 2.1.13.RELEASE
Spring Cloud Hoxton.SR3 2.2.1.RELEASE 2.2.5.RELEASE
Spring Cloud Hoxton.RELEASE 2.2.0.RELEASE 2.2.X.RELEASE
Spring Cloud Greenwich 2.1.2.RELEASE 2.1.X.RELEASE
Spring Cloud Finchley 2.0.4.RELEASE(停止维护,建议升级) 2.0.X.RELEASE
Spring Cloud Edgware 1.5.1.RELEASE(停止维护,建议升级) 1.5.X.RELEASE

官方版本关系说明文档: https://github.com/alibaba/spring-cloud-alibaba/wiki/%E7%89%88%E6%9C%AC%E8%AF%B4%E6%98%8E

工程准备

依赖管理工程(spring-cloud-alibaba-version-parent)

创建该pom工程主要用于管理依赖使用的版本。

pom.xml

<?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 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion> <groupId>com.gitee</groupId>
<artifactId>spring-cloud-alibaba-version-parent</artifactId>
<version>0.0.1</version> <properties>
<!-- 编码与JDK版本 -->
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<!-- SpringBoot SpringCloud Spring Cloud Alibaba 三件套 -->
<spring.boot.version>2.5.2</spring.boot.version>
<spring.cloud.version>2020.0.3</spring.cloud.version>
<spring.cloud.alibaba.version>2021.1</spring.cloud.alibaba.version>
<!-- JSON 转换依赖 -->
<fastjson.version>1.2.78</fastjson.version>
<!-- 工具包 -->
<hutool.version>5.7.3</hutool.version>
<mapstruct.version>1.2.0.Final</mapstruct.version>
<lombok.version>1.18.20</lombok.version>
<!-- Swagger -->
<springfox.boot.starter.version>3.0.0</springfox.boot.starter.version>
</properties> <!-- 开发人员 -->
<developers>
<developer>
<name>wuwentao</name>
<email>lovelyWu98k@gmail.com</email>
</developer>
</developers> <!-- 引入依赖管理 -->
<dependencyManagement>
<dependencies>
<!-- spring boot 依赖 -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-dependencies</artifactId>
<version>${spring.boot.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
<!-- spring cloud 依赖 -->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>${spring.cloud.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
<!-- spring cloud alibaba 依赖 -->
<dependency>
<groupId>com.alibaba.cloud</groupId>
<artifactId>spring-cloud-alibaba-dependencies</artifactId>
<version>${spring.cloud.alibaba.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement> <!-- 构建方式 -->
<build>
<finalName>${project.name}</finalName>
<resources>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
</resource>
</resources>
<!-- 打包插件管理 -->
<pluginManagement>
<plugins>
<!-- Spring Boot 打包插件 -->
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<version>${spring.boot.version}</version>
<configuration>
<finalName>${project.build.finalName}</finalName>
<layers>
<enabled>true</enabled>
</layers>
</configuration>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</pluginManagement>
</build> </project>
服务公共依赖工程(spring-cloud-alibaba-common)

创建该jar工程主要用于存放业务服务公用的内容,如统一响应实体,统一异常处理等等。

pom.xml

<?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 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.gitee</groupId>
<artifactId>spring-cloud-alibaba-version-parent</artifactId>
<version>0.0.1</version>
</parent> <groupId>com.gitee</groupId>
<artifactId>spring-cloud-alibaba-common</artifactId>
<version>0.0.1</version> <dependencies>
<!-- 工具依赖 -->
<dependency>
<groupId>cn.hutool</groupId>
<artifactId>hutool-all</artifactId>
<version>${hutool.version}</version>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
</dependency>
<dependency>
<groupId>org.mapstruct</groupId>
<artifactId>mapstruct-jdk8</artifactId>
<version>${mapstruct.version}</version>
</dependency>
<dependency>
<groupId>org.mapstruct</groupId>
<artifactId>mapstruct-processor</artifactId>
<version>${mapstruct.version}</version>
</dependency>
<!-- fastjson 序列化 -->
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>fastjson</artifactId>
<version>${fastjson.version}</version>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.20</version>
<scope>provided</scope>
</dependency>
<!-- 引用Swagger类 -->
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-boot-starter</artifactId>
<version>${springfox.boot.starter.version}</version>
<scope>provided</scope>
</dependency>
</dependencies> </project>
请求统一响应返回类定义

创建该类用于Controller处理完成后返回给前端或调用放的返回值对象。

Response.java

import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data; /**
* 请求统一响应实体类
*
* @param <T> 返回结果类型
* @author wentao.wu
*/
@Data
@ApiModel(value = "请求响应实体类")
public class Response<T> {
@ApiModelProperty(value = "请求成功响应编码")
private String code;
@ApiModelProperty(value = "请求成功响应消息")
private String msg;
@ApiModelProperty(value = "请求失败响应编码")
private String errorCode;
@ApiModelProperty(value = "请求失败响应消息")
private String errorMsg;
@ApiModelProperty(value = "返回结果")
private T result;
}
统一业务服务异常定义

创建该类主要用户识别,发生该异常是由业务服务抛出,后期可以做全局异常统一处理。

ServiceException.java

import lombok.Getter;

/**
* 服务业务运行时异常
*
* @author wentao.wu
*/
@Getter
public class ServiceException extends RuntimeException {
public ServiceException(String errorCode, String errorMsg) {
super();
this.errorCode = errorCode;
this.errorMsg = errorMsg;
} /**
* 异常编码
*/
private String errorCode;
/**
* 异常信息
*/
private String errorMsg;
}

注意事项

后期所有工程都依赖上方两个工程。

目录

标题 传送门
Nacos Server 介绍安装部署篇 未更新
Sentinle Server 介绍安装部署篇 未更新
Seata Server 介绍安装部署篇 未更新
RocketMQ Server 介绍安装部署篇 未更新
SkyWalking 介绍安装部署篇 未更新
Spring Cloud Alibaba 介绍及工程准备 前往
Spring Cloud Alibaba 使用Nacos作为服务注册中心 前往
Spring Cloud Alibaba 使用Nacos作为配置管理中心 前往
Spring Cloud Alibaba 使用RestTemplate进行服务消费 前往
Spring Cloud Alibaba 使用Feign进行服务消费 前往
Spring Cloud Alibaba 使用Seata解决分布式事务 前往
Spring Cloud Alibaba 使用Gateway作为服务网关 前往
Spring Cloud Alibaba 使用Sentinel进行熔断&降级 前往
Spring Cloud Alibaba 使用SkyWalking进行分布式链路跟踪 前往
Spring Cloud Alibaba 使用RocketMQ进行消息生产 前往
Spring Cloud Alibaba 使用RocketMQ进行消息消费 前往
持续更新中.... 持续更新
源码代码存放地址

gitee: https://gitee.com/SimpleWu/spring-cloud-alibaba-example.git

cnblogs: https://www.cnblogs.com/SimpleWu

Spring Cloud Alibaba 介绍及工程准备的更多相关文章

  1. Spring 社区的唯一一个国产开源项目 - Spring Cloud Alibaba 毕业了

    阿里妹导读:一年多前,Java 界最近发生了一件大事,阿里开源 Spring Cloud Alibaba,并推出首个预览版.Spring Cloud 本身是一套微服务规范,并不是一个拿来即可用的框架, ...

  2. 来自 Spring Cloud 官方的消息,Spring Cloud Alibaba 即将毕业

    2019 年 7 月 24 日晚,Spring Cloud 官方发布公告: 仓库迁移是官方决定 Spring Cloud Alibaba 即将毕业 根据官方最新的发版规则,我们会把孵化器中的 Spri ...

  3. Spring Cloud Alibaba Nacos

    1. Spring Cloud Alibaba 介绍 Spring Cloud Alibaba 为分布式应用程序开发提供了一站式解决方案.它包含了开发分布式应用程序所需的所有组件,使得你可以轻松地使用 ...

  4. Spring Cloud Alibaba | Nacos动态网关路由

    Spring Cloud Alibaba | Gateway基于Nacos动态网关路由 本篇实战所使用Spring有关版本: SpringBoot:2.1.7.RELEASE Spring Cloud ...

  5. Spring Cloud Alibaba | 微服务分布式事务之Seata

    Spring Cloud Alibaba | 微服务分布式事务之Seata 本篇实战所使用Spring有关版本: SpringBoot:2.1.7.RELEASE Spring Cloud:Green ...

  6. Spring Cloud Alibaba | Sentinel:分布式系统的流量防卫兵基础实战

    Spring Cloud Alibaba | Sentinel:分布式系统的流量防卫兵基础实战 Springboot: 2.1.8.RELEASE SpringCloud: Greenwich.SR2 ...

  7. Spring Cloud Alibaba | Sentinel:分布式系统的流量防卫兵进阶实战

    Spring Cloud Alibaba | Sentinel:分布式系统的流量防卫兵进阶实战 在阅读本文前,建议先阅读<Spring Cloud Alibaba | Sentinel:分布式系 ...

  8. Spring Cloud Alibaba | Sentinel:分布式系统的流量防卫兵动态限流规则

    Spring Cloud Alibaba | Sentinel:分布式系统的流量防卫兵动态限流规则 前面几篇文章较为详细的介绍了Sentinel的使用姿势,还没看过的小伙伴可以访问以下链接查看: &l ...

  9. Spring Cloud Alibaba(四)实现Dubbo服务消费

    本项目演示如何使用 Spring Cloud Alibaba 完成 Dubbo 的RPC调用. Spring Cloud与Dubbo Spring Cloud是一套完整的微服务架构方案 Dubbo是国 ...

随机推荐

  1. Sa-Token之注解鉴权:优雅的将鉴权与业务代码分离!

    Sa-Token之注解鉴权:优雅的将鉴权与业务代码分离! Sa-Token 介绍: Sa-Token 是一个轻量级 Java 权限认证框架,主要解决:登录认证.权限认证.Session会话.单点登录. ...

  2. Typora + PicGo做个人知识库

    最近在做个人知识库,考察了一圈各种平台和工具,发现还是直接用文件系统管理Markdown文件更符合我当前的需求.以Markdown文件作为文字载体,以文件目录作为分类结构,承载以计算机知识为主的学习笔 ...

  3. J2EE分布式微服务云开发架构 Spring Cloud+Mybatis+ElementUI 前后端分离J2EE分布式微服务云开发架构 Spring Cloud+Mybatis+ElementUI 前后端分离

    ​ 鸿鹄云架构[系统管理平台]是一个大型企业.分布式.微服务.云架构的JavaEE体系快速研发平台,基于模块化.微服务化.原子化.热部署的设计思想,使用成熟领先的无商业限制的主流开源技术(Spring ...

  4. GMAP.NET系列学习文档

    http://www.cnblogs.com/enjoyeclipse/archive/2013/01/13/2858392.html http://www.cnblogs.com/luxiaoxun ...

  5. nohup命令的用法

    在应用Unix/Linux时,我们一般想让某个程序在后台运行,于是我们将常会用 & 在程序结尾来让程序自动运行.比如我们要运行mysql在后台: /usr/local/mysql/bin/my ...

  6. paramido简单使用教程

    之前很少用paramilko  今天想安装一下使用,然后百度了一下,然后就是各种 奇云技巧 ,各大博客照 着做都难成功,,然后火了,直接在CMD下输入 pip install paramiko     ...

  7. sed 找出含有某个字符串的行 注释掉

    1.源文件例子 [root@node1 ~]# cat /etc/fstab # # /etc/fstab # Created by anaconda on Mon Mar 1 18:32:15 20 ...

  8. PTA 面向对象程序设计6-2 统计数字

    对于给定的一个字符串,统计其中数字字符出现的次数. 类和函数接口定义: 设计一个类Solution,其中包含一个成员函数count_digits,其功能是统计传入的string类型参数中数字字符的个数 ...

  9. 使用metaweblog API实现通用博客发布 之 API测试

    使用metaweblog API实现通用博客发布 之 API测试 使用博客比较少,一则是文笔有限,怕写出的东西狗屁不通,有碍观瞻, 二则是懒,很讨厌要登录到网站上写东西,也没有那么多时间(借口).个人 ...

  10. PHP的Mhash扩展函数的学习

    这次我们要学习的又是一个 Hash 加密扩展.不过这个扩展 Mhash 已经集成在了 Hash 扩展中.同时也需要注意的是,这个扩展已经不推荐使用了,我们应该直接使用 Hash 扩展中的函数来进行 H ...