Giter VIP home page Giter VIP logo

liuxiaozhu / smart-cloud Goto Github PK

View Code? Open in Web Editor NEW

This project forked from smart-cloud/smart-cloud

1.0 0.0 0.0 2.15 MB

基于springboot && springcloud的脚手架,支持服务合并部署与拆分部署、接口加解密签名、日志数据 脱敏、接口数据mock、接口文档自动生成、请求幂等校验、接口日志&&sql日志切面打印、分表分库分布式事务、国际化语言等

License: Apache License 2.0

Java 99.54% FreeMarker 0.46%

smart-cloud's Introduction

smart cloud

build codecov Language grade: Java license jdk version EN doc CN doc

一、功能特征

一个基于spring cloud实现的脚手架。所实现功能如下:

示例工程见smart-cloud-examples

二、模块说明

smart-cloud
├── smart-api-core -- 接口权限、加解密、签名等注解 && 用户上下文
│    ├──smart-api-annotation -- 接口权限、加解密、签名等注解
│    └──smart-user-context -- 用户上下文
├── smart-code-generate -- 代码生成
├── smart-common-pojo -- 公共对象(VO、DTO、BO、DO等)
├── smart-common-web -- web模块公共处理
├── smart-constants -- 常量模块
├── smart-exception -- 异常模块
├── smart-mask -- 敏感数据混淆
├── smart-utility -- 工具类
└── smart-could-starter -- 框架封装
     ├── smart-cloud-starter-configure -- 框架配置属性封装
     ├── smart-cloud-starter-core -- 框架核心(自定义注解、异常封装、请求响应公共参数、业务相关工具类)
     ├── smart-cloud-starter-feign -- feign封装(可拆可合、切面处理)
     ├── smart-cloud-starter-job -- 定时任务封装
     ├── smart-cloud-starter-locale -- 国际化封装
     ├── smart-cloud-starter-log4j2 -- 日志封装(log4j2封装,支持日志敏感数据脱敏)
     ├── smart-cloud-starter-method-log -- 方法切面日志封装
     ├── smart-cloud-starter-mock -- mock封装(mock工具类、常用mock策略、请求接口mock拦截器)
     ├── smart-cloud-starter-mp-shardingjdbc -- mybatis plus、dynamic-datasource、shardingjdbc封装(支持多数据源、分库分表、分布式事务;mapper工具类)
     ├── smart-cloud-starter-mybatis-plus -- mybatis plus、dynamic-datasource封装(支持多数据源、分布式事务;mapper工具类、表隐私字段加解密等)
     ├── smart-cloud-starter-rabbitmq -- rabbitmq封装(消费失败,自动放入延迟队列重新消费)
     ├── smart-cloud-starter-redis -- redis封装、自定义分布式锁注解
     ├── smart-cloud-starter-test -- test封装
     └── smart-cloud-starter-web -- web封装(日志切面、异常处理、参数校验)

三、技术栈

名称 说明
spring boot 手脚架
spring cloud gateway 服务网关
nacos 服务注册、配置中心
spring boot admin 服务监控
openfeign 声明式服务调用
sleuthlog4j2 链路追踪、日志
mybatismybatis plus ORM
dynamic-datasource 多数据源
seata 分布式事务
sharding jdbc 分库分表
redisembedded-redis 缓存、集成测试
sentinel 限流、熔断降级
rabbitmq 消息队列
fastdfs 文件存储
xxl-job 定时任务
easyexcel excel导入导出
Hibernator-Validator 参数校验
mockitopodam 单元测试、数据mock
h2 数据库集成测试
embedded-redis redis集成测试
rabbitmq-mock rabbitmq集成测试
freemarker 用于代码生成
yapiidea yapi upload plugin 接口文档
jasypt-spring-boot 配置文件中敏感数据加解密
Lombok 简化代码

四、服务合并原理

  • 合并服务只需修改pom.xml,将待合并的服务import进去即可。
  • rpc接口通过自定义注解SmartFeignClient实现。单个服务独自部署时,FeignClient会生效;当服务提供者和服务消费者合并部署时,FeignClient注解会失效,此时rpc接口将通过实现类对象直接调用。具体逻辑见SmartFeignClientCondition

五、相关说明

(一)服务合并遇到的问题

单个服务以jar的形式,通过maven引入合并服务中。在单体服务中,feign接口通过http请求;服务合并后,feign接口通过内部进程的方式通信。

1、rpc与rpc实现类冲突

自定义条件注解封装FeignClient。使其在单体服务时,rpc走feign;在合体服务时,rpc走内部进程通信。

2、yaml文件的自动加载

自定义注解YamlScan,用来加载配置的yaml文件(支持正则匹配)。通过SPI机制,在spring.factories文件中添加EnvironmentPostProcessor的实现类,通过其方法参数SpringApplication获取启动类的信息,从而获取YamlScan注解配置的yaml文件信息。然后将yaml文件加到ConfigurableEnvironment中。

3、启动类注解冲突

自定义条件注解SmartSpringCloudApplicationCondition,只会让启动类标记的启动注解生效。

4、maven打包异常

合体服务打包时,单体服务依赖的包也打进单体服务jar。通过maven profiles解决

(二)日志数据脱敏

1.从日志侧切入,自定义标签,打印日志时进行脱敏处理;
2.自定义jackson的序列化器;打印日志时,采用自定义的序列化器;
3.通过反射获取log传入参数的MaskRule注解信息,最终根据注解规则进行字符串的截取与替换。

(三)接口mock数据

接口通过切面拦截的方式,通过反射可以获取返回对象的所有信息,然后根据对象的属性类型,可以随机生成数据;对于特定要求的数据,可以制定mock规则,生成指定格式的数据。

(四)测试

1、单元测试

利用单元测试,提高测试覆盖率。

2、集成测试

  • 在集成测试下,关闭nacos,减少依赖。
  • 依赖的服务rpc接口,通过mockito走挡板。
  • redis层使用embedded-redis做集成测试。
  • rabbitmq层使用rabbitmq-mock做集成测试
  • 数据库层使用h2做集成测试(另外两种方案:方案一通过事务回滚还原测试用例对DB的修改;方案二在测试用例执行前删除相关的表)。

3、系统测试

(五)接口文档

1、接口文档由以下步骤自动生成:

通过idea yapi upload plugin插件,上传到yapi server

2、接口文档效果图

概要

详情

六、错误码说明

所属模块 code message
smart-constants 200 成功
smart-constants 101 校验失败
smart-constants 102 数据不存在
smart-constants 103 数据已存在
smart-constants 400 签名错误
smart-constants 401 无权限访问
smart-constants 404 请求url错误
smart-constants 408 请求超时
smart-constants 409 重复提交
smart-constants 412 参数不全
smart-constants 415 请求方式不支持
smart-constants 416 请求类型不支持
smart-constants 417 获取锁失败
smart-constants 418 上传文件大小超过限制
smart-constants 419 当前会话已失效,请重新登陆
smart-constants 500 服务器异常
smart-constants 501 获取Request失败
smart-constants 502 获取Response失败
smart-constants 503 rpc请求失败
smart-constants 504 rpc返回结果异常
smart-cloud-starter-web 2001 待校验参数object不能为null

smart-cloud's People

Contributors

luckyqing avatar

Stargazers

Roman avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.