《Spring Cloud Alibaba实战》系列-初识

前言

最近刚入职新公司,又刚好公司需要根据一个现有项目,做一个产品。组长让我们每个人空的时候都去想一想架构怎么设计,然后每人发表一下意见。作为一个有经验的新人,这个机会自然是要把握住的。

第一步了解现有的架构,拿到项目后,对着页面熟悉了一下系统业务,然后开始撸代码。了解到现有的架构 Springboot + mybatis + mysql + Dubbo ,还是比较传统的,一些常用的限流,熔断的系统保护,分布式锁,分布式事务都没有考虑到,居然连配置中心也没有使用。当时我初步的架构想法是: Springboot + spring cloud  + mybatisMP + Dubbo + mysql + nacos 。

初识

有了这个想法之后,我就开始上网查资料并自己动手搭了一个框架,其中遇到很多坑,后来看到一篇文章讲的是spring cloud和Dubbo的完美结合,里面提到了Spring Cloud Alibaba按照里面的步骤,很简单的就把框架搭建好了。于是我便疯狂的去查了一些关于Spring Cloud Alibaba资料,也一步步的实践到项目中。跟一个老同事聊了一下自己的想法,他说公司其他产品组都是在用spring cloud,服务调用用的Feign,他建议我也这样,不需要用dubbo。所以最终定下的架构是:Springboot + spring cloud  + mybatisMP + mysql + nacos + Feign + Sentinel + redisson + seata.

在搭建整合的过程遇到很多坑,自己是一步步趟过来的。所以我就想写一个系列文章记录下这些过程,及具体的实践过程,一方面自己做下覆盘,另一方面也让有需要的小伙伴少踩一些坑。

简介

Spring Cloud Alibaba 致力于提供微服务开发的一站式解决方案。此项目包含开发分布式应用微服务的必需组件,方便开发者通过 Spring Cloud 编程模型轻松使用这些组件来开发分布式应用服务。

依托 Spring Cloud Alibaba,您只需要添加一些注解和少量配置,就可以将 Spring Cloud 应用接入阿里微服务解决方案,通过阿里中间件来迅速搭建分布式应用系统。

参考文档 请查看 WIKI 。

使用组件

Nacos:一个更易于构建云原生应用的动态服务发现、配置管理和服务管理平台。
Sentinel:把流量作为切入点,从流量控制、熔断降级、系统负载保护等多个维度保护服务的稳定性。
Seata:阿里巴巴开源产品,一个易于使用的高性能微服务分布式事务解决方案。
RocketMQ:一款开源的分布式消息系统,基于高可用分布式集群技术,提供低延时的、高可靠的消息发布与订阅服务。
Alibaba Cloud SMS: 覆盖全球的短信服务,友好、高效、智能的互联化通讯能力,帮助企业迅速搭建客户触达通道。

准备

搭建一个spring boot项目,我使用的是Idea工具,过程就略过了...

Idea工具安装激活请移步:https://blog.csdn.net/HXNLYW/article/details/81235444

增加统一依赖管理

在 pom.xml 文件中的 <dependencyManagement>标签下添加如下配置。

<!--版本号统一管理-->
<properties>
    <spring-cloud.version>Hoxton.RELEASE</spring-cloud.version>
    <alibaba-cloud.version>2.1.1.RELEASE</alibaba-cloud.version>
</properties>

<!--依赖统一管理-->
<dependencyManagement>
    <dependencies>
        <!--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>
        <!--alibaba cloud -->
        <dependency>
            <groupId>com.alibaba.cloud</groupId>
            <artifactId>spring-cloud-alibaba-dependencies</artifactId>
            <version>${alibaba-cloud.version}</version>
            <type>pom</type>
            <scope>import</scope>
        </dependency>
    </dependencies>
</dependencyManagement>

 避坑:springcloud 版本 和 springboot 的版本需要对应,不然启动会报错。

The method's class, org.springframework.boot.actuate.health.CompositeHealthIndicator, is available from the following locations:
    jar:file:/F:/MavenLib/org/springframework/boot/spring-boot-actuator/2.2.1.RELEASE/spring-boot-actuator-2.2.1.RELEASE.jar!/org/springframework/boot/actuate/health/CompositeHealthIndicator.class
It was loaded from the following location:
    file:/F:/MavenLib/org/springframework/boot/spring-boot-actuator/2.2.1.RELEASE/spring-boot-actuator-2.2.1.RELEASE.jar
Action:
Correct the classpath of your application so that it contains a single, compatible version of org.springframework.boot.actuate.health.CompositeHealthIndicator

版本对应关系:

cloud Release Train Boot Version

Hoxton

2.2.x

Greenwich

2.1.x

Finchley

2.0.x

Edgware

1.5.x

Dalston

1.5.x

最新对应关系可以查看官网:https://spring.io/projects/spring-cloud

这样准备工作就好了,我们需要引用哪个组件,只需要在 <dependencies> 中怎加相应依赖,无需指定<version>。

后面系列会根据案例逐个介绍组件的使用,欢迎大家继续关注。

下一篇:《Spring Cloud Alibaba实战》系列-Nacos之注册中心、配置中心

===============================================

代码均已上传至本人的开源项目

葫芦胡:https://blog.csdn.net/HXNLYW/article/details/98037354

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章