Spring Cloud 微服务概述
TIP
Spring Cloud 是一系列框架的集合,为分布式系统提供了服务发现、配置管理、负载均衡、熔断器等一站式解决方案。
Spring Cloud 核心组件
服务注册与发现 → Nacos / Eureka
配置中心 → Nacos Config / Spring Cloud Config
API 网关 → Spring Cloud Gateway / Zuul
负载均衡 → OpenFeign + LoadBalancer
熔断降级 → Sentinel / Hystrix
链路追踪 → Sleuth + Zipkin版本演进
| 版本 | 对应 SpringBoot | 主要组件 |
|---|---|---|
| Hoxton | 2.2.x ~ 2.3.x | Eureka, Zuul, Hystrix (已停维) |
| 2020.0 | 2.4.x ~ 2.5.x | 移除 Netflix 组件 |
| 2021.0 | 2.6.x | Nacos, Gateway, Sentinel |
| 2022.0 | 3.0.x | 最新版本 |
技术选型趋势
yaml
# 当前主流技术栈(2024+)
注册中心: Nacos # 替代 Eureka
配置中心: Nacos # 替代 Spring Cloud Config
API 网关: Spring Cloud Gateway # 替代 Zuul
负载均衡: Spring Cloud LoadBalancer # 替代 Ribbon
熔断降级: Sentinel # 替代 Hystrix微服务架构示例
┌─────────────┐
│ Nacos │
│ 注册中心 │
└──────┬──────┘
│
┌────────────┴────────────┐
│ Gateway API 网关 │
└────────────┬────────────┘
│
┌──────────────────┼──────────────────┐
▼ ▼ ▼
┌──────────┐ ┌──────────┐ ┌──────────┐
│ User │ │ Order │ │ Product │
│ Service │ │ Service │ │ Service │
└──────────┘ └──────────┘ └──────────┘
│ │ │
└──────────────────┼──────────────────┘
▼
┌─────────────┐
│ MySQL │
│ Sentinel │
└─────────────┘