Skip to content

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主要组件
Hoxton2.2.x ~ 2.3.xEureka, Zuul, Hystrix (已停维)
2020.02.4.x ~ 2.5.x移除 Netflix 组件
2021.02.6.xNacos, Gateway, Sentinel
2022.03.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   │
                     └─────────────┘