# SpringCloud **Repository Path**: Scout-Lee/spring-cloud ## Basic Information - **Project Name**: SpringCloud - **Description**: No description available - **Primary Language**: Unknown - **License**: MIT - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2025-04-12 - **Last Updated**: 2025-04-12 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # 🌩️ Spring Cloud 微服务治理技术总结 > 🧠 本文档总结了我在学习 Spring Cloud 体系中所涉及到的所有关键技术栈与模块,包含项目结构、核心组件、配置示例及注意事项,适合自我复习与复用。 笔记作者:宋孟林 课程作者:尚硅谷周阳 --- **仓库简介** 此项目主要用于记录SpringCloud 以及SpringCloud Alibaba 的学习过程中的主要代码。 ## 🔧 核心技术栈 | 分类 | 技术 | |--------------|--------------------------| | 微服务注册与发现 | Nacos,Consul | | 服务调用 | **OpenFeign**、RestTemplate | | 服务网关 | **Spring Cloud Gateway** | | 配置中心 | Consul、Nacos | | 熔断与限流 | Resilience4j、Sentinel | | 分布式事务 | **Seata AT 模式** | | 数据访问 | MyBatisPlus、MySQL | | 日志链路追踪 | MicroMeter + Zipkin(可选) | ## 🔄 分布式事务流程(Seata) 1. `@GlobalTransactional` 注解用于事务发起方(如订单服务)。 2. 被调用服务(账户、库存)通过 Seata 数据源代理参与事务。 3. 本地数据库需创建 `undo_log` 表记录数据前镜像。 4. 任一服务失败,全局事务自动回滚,数据一致性保障。 --- ## 🧪 开发与测试命令 ### ☁️ 启动顺序(本地调试) ```bash 1. 启动 nacos(或 consul-server) 2. 启动 seata-server 3. 启动 sentinel 4. 启动 gateway 5. 启动 MicroService ``` ### 🔄 curl 测试接口(下订单) ```bash curl -X POST http://localhost:2001/order/create \ -H "Content-Type: application/json" \ -d '{ "userId": 1, "productId": 1, "count": 2, "money": 100 }' ``` --- ## 📝 undo_log 表结构(MySQL) ```sql CREATE TABLE `undo_log` ( `id` BIGINT(20) NOT NULL AUTO_INCREMENT, `branch_id` BIGINT(20) NOT NULL, `xid` VARCHAR(100) NOT NULL, `context` VARCHAR(128) NOT NULL, `rollback_info` LONGBLOB NOT NULL, `log_status` INT(11) NOT NULL, `log_created` DATETIME NOT NULL, `log_modified` DATETIME NOT NULL, `ext` VARCHAR(100) DEFAULT NULL, PRIMARY KEY (`id`), UNIQUE KEY `ux_undo_log` (`xid`, `branch_id`) ) ENGINE=InnoDB; ```