Apache License 2.0

技术解读

以下内容由 GitRead 中文社区 编辑团队基于项目 README 与官方资料整理, 结合中文开发者的常见使用场景补充技术选型建议。具体以项目官方文档为准。

Twelvet 微服务框架深度技术分析

项目背景与痛点

在微服务理念逐步成为主流的当下,不少企业正逐步将其服务架构从单一的大规模应用向分布式微服务架构迁移。Spring Boot 和Spring Cloud 的组合为微服务平台提供了强大的支持。然而,开发者仍然面临着一系列挑战,包括但不限于跨服务协作、服务注册与发现、数据一致性以及高可用性等问题。再加上不同云平台对微服务生态链造成了多元化的布局,如何在保持技术栈一致的同时,兼容并利用不同的云服务生态系统,成为了一项重要课题。

Twelvet 框架应运而生,它以 Spring Boot 3.X 为基础,结合了 Spring Cloud Alibaba和 Spring Cloud Tencent 的丰富功能,旨在为企业提供一个轻量级、高效能的微服务框架。该框架不仅简化了微服务项目开发难度,还提供了丰富的功能模块,以应对实际业务中的复杂需求,如限流、熔断、服务调用链路监控等。

核心技术揭秘

Twelvet 在架构和技术栈层面的设计旨在提供一个高效能且易维护的微服务框架,充分利用了Spring Cloud Aggregation的功能,同时也结合了腾讯和阿里的解决方案。

技术栈与设计模式

在技术栈方面,Twelvet 主要采用 Spring Boot 3.X 为应用的核心技术,并结合 Spring Cloud 系列框架,如Spring Cloud Alibaba 和 Spring Cloud Tencent。此外,它还集成了序列化、反序列化、数据加密等基础工具包,方便开发者快速构建高效能的微服务应用。

在架构层面,Twelvet 支持 RESTful 服务、事件驱动模式、以及基于注解的便捷配置方式,这使得微服务的开发和运维更加方便。

数据流图示模

graph TD A[用户请求] --> B{"微服务入口"} B -->|"路由匹配"| C[服务提供者] B -->|"参数校验失败"| D[错误处理] C --> E{"服务路由与负载均衡"} E -->|"服务调用"| F[业务逻辑处理] E -->|"服务调用失败"| G[异常处理] F --> H[数据结果处理] H --> I{"数据响应与缓存"} I -->|"缓存命中"| J[响应请求] I -->|"缓存未命中"| K[数据库操作] K --> L{"数据操作"} L -->|"数据读取成功"| M[数据结果返回] L -->|"数据操作失败"| N[错误处理] M --> J H --> O{"SQL 执行优化"} O --> P[结果优化] P --> M

此图展示了Twelvet 微服务框架中的数据流,涵盖了从用户请求到数据操作的全过程。

功能亮点与差异

相比于同类竞品,Twelvet 拥有一系列独特的设计:

  • 轻量灵活:基于Spring Boot 3.X,提供了轻量级的微服务框架,非常灵活,适应多种企业环境。
  • 丰富的功能模块:包含面向业务开发的多种功能模块,涵盖基本的限流与熔断、TOKEN校验等, 提供了一个由上到下的完备解决方案。
  • 兼容性强大:完美兼容Spring Cloud Tencent与Alibaba的功能和服务,能够灵活部署于各类云环境。
  • 开源贡献支持:活跃的社区和开发团队,良好的贡献机制,极大地增加了框架的可持续性和可扩展性。

应用场景与落地建议

在生产环境上使用Twelvet 框架时需注意以下几点:

  • 服务容错处理:确保每个微服务实例均具备基本的容错处理能力,例如为服务实例部署健康检查服务、同时采用时间窗口和桶限流等管理策略,有效应对高并发访问。
  • 负载均衡实践:密切关注包括实例路由、访问延迟以及客户端投票平衡等关键参数,以优化负载均衡效果,确保服务高可用性。
  • 监控与排障:服务调用过程中可能面临链路中的问题,务必依赖现有的监控工具和动态日志、泄漏堆等手段进行统一动态管理,从而提升可视性。

Twelvet框架适用于需要将原有业务系统拆分为多个服务的场景,尤其是关注于微服务的轻量化以及云服务兼容性的场景。

综合评价

优:

  • 轻松构建与部署:大幅简化了微服务的构建和部署流程。
  • 强大的自我修复能力:对服务化过程中可能出现的问题具有较好的应对机制。
  • 社区支持与贡献:高度活跃的社区,持续贡献者,确保长期发展与更新。

缺:

  • 学习门槛:虽然使用简便,但由于同时涉及Spring Cloud Alibaba、Tencent、React等多种技术,在初次使用时可能存在一定的学习曲线。
  • 特定场景解决方案:虽然框架具有广泛的适用性,但某些领域或特定问题可能需要开发者提供额外的定制化方案。

综上所述,Twelvet微服务框架作为一个集多种优秀服务化解决方案于一体的开源项目,能够帮助企业极大程度上提升开发效率与运维效果,减少开发维护成本,是微服务架构下不容错过的一项选择。

语言占比

CSS
FreeMarker
HTML
Java
JavaScript
Shell

README

中文 | English

🚀twelvet

JDK >= 17

AUR GitHub stars GitHub forks star fork

A permission management system based on Spring Cloud Alibaba that integrates popular libraries on the market and can act as a framework for rapid development.

A scaffolding framework based on microservices architecture, using the Spring Cloud Alibaba series for architecture. Learning and understanding it will enable you to quickly grasp the core basics of microservices. This project aims to reduce duplication of business code and has a common core business code that is universal for both microservices and monoliths.

But more importantly, it is for learning the concept of microservices and development. You can use it for website management backstage, website member center, CMS, CRM, OA and other systems development. Of course, not just small systems, we can produce more service modules and continuously improve the project.

The initial intention of the system is to be able to quickly meet the business needs, to bring better experience and more time. It will be used to incubate some practical functional points. We hope that they are lightweight, highly portable functional plugins.

Backend source code: https://github.com/twelvet-projects/twelvet

Frontend source code: https://github.com/twelvet-s/twelvet-ui

Technical documents: https://doc.twelvet.cn/

Official blog: https://twelvet.cn

🍎 Branch Description

Branch Description Additional Description
master java17 + springboot 3.x + springcloud 2022 + spring cloud alibaba master
jdk8 java8 + springboot 2.7.x + springcloud 2021 + spring cloud alibaba jdk8
spring-cloud-tencent java17 + springboot 3.x + springcloud 2022 + spring cloud tencent Demonstration branch, does not support compatibility with too many new features

System Module

com.twelvet     
├── twelvet-ui              // Front-end Framework [80]
├── twelvet                 // Public dependencies
│      └── pom.xml                // Public dependencies
│      └── twelvet-api             // Interface module
│               └── twelvet-api-system                             // System interface
│               └── twelvet-api-dfs                                // DFS interface
│               └── twelvet-api-job                                // Scheduled task interface
│               └── twelvet-api-ai                                 // AI interface
│      └── twelvet-framework       // Core module
│               └── twelvet-framework-core                         // Core module
│               └── twelvet-framework-log                          // Logging
│               └── twelvet-framework-datascope                    // Data permission
│               └── twelvet-framework-jdbc                         // jdbc
│               └── twelvet-framework-swagger                      // swagger document
│               └── twelvet-framework-redis                        // Cache service
│               └── twelvet-framework-snowflake                    // snowflake ID
│               └── twelvet-framework-security                     // Security module
│               └── twelvet-framework-utils                        // Tool module
├── twelvet-gateway         // Gateway module [88]
├── twelvet-nacos           // nacos [8848]
├── twelvet-auth            // Authentication Center [8888]
├── twelvet-server         // Business module
│       └── twelvet-server-system                          // System module [8081]
│       └── twelvet-server-job                             // Scheduled task [8082]
│       └── twelvet-server-dfs                             // DFS service [8083]
│       └── twelvet-server-gen                             // Code generation [8084]
│       └── twelvet-server-ai                               // AI module [8085]
├── twelvet-visual        // Graphic Management Module
|       └── twelvet-visual-sentinel                        // sentinel [8101]
│       └── twelvet-visual-monitor                         // Monitoring center [8102]

Built-in Functions

  1. User management: Users are operators of the system, and this function mainly completes the configuration of system users.
  2. Department management: configure the system organization structure (company, department, group), tree structure display supports data permissions.
  3. Post management: Configure the positions held by system users.
  4. Menu Management: Configure system menus, operation permissions, button permission identifiers, etc.
  5. Role Management: Role menu permission allocation, set role data range permission division by organization.
  6. Dictionary management: Maintain some relatively fixed data commonly used in the system.
  7. Parameter management: Dynamic configuration of commonly used parameters in the system.
  8. Asynchronous: Login log / system operation log / system login log recording and inquiry.
  9. Scheduled task: Online (add, modify, delete) task scheduling includes execution result logs.
  10. Code generation: One-click generation of CRUD front-end and back-end code, providing faster speed for business development.
  11. Service monitoring: Monitor current system CPU, memory, disk, stack and other related information.
  12. Connection pool monitoring: Monitor the status of the current system database connection pool, and analyze SQL to find out the system performance bottleneck.
  13. Distributed file storage.
  14. Swagger gateway aggregation document.
  15. Sentinel flow restriction center.
  16. Nacos registration + configuration center.
  17. RAG knowledge base

Demonstration

Online Experience

  • admin/123456

Demonstration address:https://cloud.twelvet.cn

Architecture Diagram

✈️✈️✈️ Quickly start Microservices

Memory > 16 Maven, Docker, Docker-compose, Node, and Yarn need to be installed manually.

# mvn twelvet
cd ./twelvet && mvn clean && mvn install -DskipTests
# mvn twelvet-auth
cd ../twelvet-auth && mvn clean && mvn install -DskipTests
# mvn twelvet-gateway
cd ../twelvet-gateway && mvn clean && mvn install -DskipTests
# mvn twelvet-server-system
cd ../twelvet-server/twelvet-server-system && mvn clean && mvn install -DskipTests
# Enter the script directory
cd ../../docker
# Set executable permissions
chmod 751 deploy.sh
# Perform startup (execute parameters as needed, [init | port | base | server | stop | rm])
# Initialization
./deploy.sh init
# Basic services
./deploy.sh base
# Start Twelvet
./deploy.sh server
# Start UI
./deploy.sh nginx

Open Source Collaboration

Open Source License

The Twelvet open-source software follows the MIT License Apache 2.0 License。 Permits commercial use, but requires the preservation of the original author and copyright information.

Other terms

  1. Welcome to contribute PR,Make sure to submit to the corresponding branch Code conventions spring-javaformat

    Code style guidelines
    1. Due to spring-javaformat the requirement of enforcing a specific code formatting, any code that is not submitted according to this requirement will not be able to be merged (packaged)
    2. If you are using IntelliJ IDEA for development, please install the auto-formatting plugin. spring-javaformat-intellij-idea-plugin
    3. For other development tools, please refer to their respective documentation or community for instructions on configuring automatic code formatting. spring-javaformat Before committing code, please run the following command in the project root directory (requires developer’s computer to support the mvn command) to format the code.
      mvn spring-javaformat:apply
      
  2. Welcome to contribute issue,Please provide clear explanations of the issue, development environment, and steps to reproduce.

评论

暂无评论