# springcloudlearn **Repository Path**: liu_zi_ming/springcloudlearn ## Basic Information - **Project Name**: springcloudlearn - **Description**: Ghost Apogee 是一个基于 Spring Boot 3 和 Spring Cloud Alibaba 2023.x 构建的现代化云原生微服务学习实验室。它演示了一个完整的微服务架构,涵盖了服务发现、分布式事务、熔断限流和链路追踪等核心功能。 - **Primary Language**: Unknown - **License**: Not specified - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2026-01-09 - **Last Updated**: 2026-01-10 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # Ghost Apogee (Spring Cloud Alibaba 学习实验室) **Ghost Apogee** 是一个基于 **Spring Boot 3** 和 **Spring Cloud Alibaba 2023.x** 构建的现代化云原生微服务学习实验室。它演示了一个完整的微服务架构,涵盖了服务发现、分布式事务、熔断限流和链路追踪等核心功能。 [English Documentation](README.md) | [中文文档](README_CN.md) ## 🏗 架构图 ```mermaid graph TD User([用户请求]) --> Gateway[网关服务 :8080] subgraph 基础设施 Nacos[(Nacos 注册与配置中心)] MySQL[(MySQL 5.7)] Seata[(Seata Server 分布式事务)] Zipkin[(Zipkin Server 链路追踪)] end subgraph 微服务 Gateway --> Order[订单服务 :8082] Gateway --> UserSvc[用户服务 :8081] Order -->|Feign Client| UserSvc Order -.->|分布式事务| Seata UserSvc -.->|分布式事务| Seata Order -->|上报 Trace| Zipkin UserSvc -->|上报 Trace| Zipkin Gateway -->|上报 Trace| Zipkin end Order --> MySQL UserSvc --> MySQL Seata --> MySQL ``` ## 🛠 技术栈 | 组件 | 技术选型 | 版本 | | :--- | :--- | :--- | | **开发框架** | Spring Boot | 3.2.x | | **云原生** | Spring Cloud Alibaba | 2023.0.1.0 | | **注册/配置** | Nacos | 2.3.x | | **网关** | Spring Cloud Gateway | 4.1.x | | **远程调用** | OpenFeign | 4.1.x | | **熔断限流** | Sentinel | 1.8.x | | **分布式事务** | Seata (AT 模式) | 2.0.0 | | **链路追踪** | Micrometer + Zipkin | Latest | | **数据库** | MySQL | 5.7 | | **ORM** | MyBatis-Plus | 3.5.5 | ## 🚀 快速开始 ### 1. 前置要求 * **JDK 17+** (Spring Boot 3 必需) * **Docker Desktop** (或 Docker Compose) * **Maven 3.8+** ### 2. 启动基础设施 使用 Docker Compose 一键启动所有中间件 (MySQL, Nacos, Seata, Zipkin): ```bash cd dev-ops docker-compose up -d ``` > **请等待约 1 分钟** 让服务初始化完成。 > * Nacos 控制台: http://localhost:8848/nacos (无需登录) > * Seata 控制台: http://localhost:7091 > * Zipkin 控制台: http://localhost:9411 ### 3. 编译与运行 请按以下顺序编译并启动微服务: 1. **Gateway Service** (`com.example.gateway.GatewayApplication`) 2. **User Service** (`com.example.user.UserApplication`) 3. **Order Service** (`com.example.order.OrderApplication`) ### 4. 功能验证 #### 分布式事务测试 (Seata) **场景**: 创建订单并扣减用户余额。 * **请求**: `GET http://localhost:8080/order-service/orders/create?userId=1&productId=101&amount=10` * **成功**: 返回 `Order Created Successfully`。数据库中 `t_order` 新增记录,`t_user` 余额扣减。 * **回滚**: 设置 `amount` > 用户余额 (例如 99999)。全局事务将回滚,不会生成垃圾订单数据。 #### 链路追踪测试 (Zipkin) 1. 发送几个请求。 2. 打开 [Zipkin UI](http://localhost:9411)。 3. 点击 **Run Query**,即可看到 `gateway -> order -> user` 的完整调用链路图。 ## 📂 模块结构 * `gateway-service`: API 网关,负责路由转发和负载均衡。 * `user-service`: 用户服务,处理用户余额等逻辑。 * `order-service`: 订单服务,上游业务服务。 * `dev-ops`: Docker 基础设施配置文件。 * `sql`: 数据库初始化脚本。 ## 📝 开源协议 MIT