Skip to content

huangtingliu/springCloud

Repository files navigation

spring cloud 学习

版本

  • spring-cloud Hoxton.SR8
  • spring-boot 2.3.3.RELEASE

spring cloud 子项目

  • 注册中心 nacos、eureka
  • 网关 spring gateway
  • 断路器 Sentinel、hystrix、Resilience4J
  • 远程调用 openfeign
  • 未完待续...

nacos注册中心

demo项目

  • nacos-service-provider (提供服务项目)
  • nacos-service-consumer (调用服务项目)
  • gateway (用到sentinel+nacos) nacos官方文档

步骤

<dependency>
    <groupId>com.alibaba.cloud</groupId>
    <artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId>
</dependency>

注意:父项目引入

<dependencyManagement>
    <dependencies>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-dependencies</artifactId>
            <version>${spring.cloud.version}</version>
            <type>pom</type>
            <scope>import</scope>
        </dependency>
        <dependency>
            <groupId>com.alibaba.cloud</groupId>
            <artifactId>spring-cloud-alibaba-dependencies</artifactId>
            <version>${spring.cloud.alibaba.version}</version>
            <type>pom</type>
            <scope>import</scope>
        </dependency>
    </dependencies>
</dependencyManagement>
server.port=8081
spring.application.name=nacos-provider
spring.cloud.nacos.discovery.server-addr=127.0.0.1:8848
management.endpoints.web.exposure.include=*

Sentinel断路器

demo项目

  • gateway (网关项目,使用sentinel配合nacos扩展数据源配置限流规则)

Sentinel 控制台

java -Dserver.port=8080 -Dcsp.sentinel.dashboard.server=localhost:8080 -Dproject.name=sentinel-dashboard -jar xxx.jar 
spring:
  cloud:
    sentinel: 
      transport:
        port: 8719
        dashboard: localhost:8080  #启动本项目后需要请求一次才能向sentinel控制台注册

Spring Cloud Gateway 支持

<dependency>
    <groupId>com.alibaba.cloud</groupId>
    <artifactId>spring-cloud-starter-alibaba-sentinel</artifactId>
</dependency>

<dependency>
    <groupId>com.alibaba.cloud</groupId>
    <artifactId>spring-cloud-alibaba-sentinel-gateway</artifactId>
</dependency>

<dependency>
    <groupId>org.springframework.cloud</groupId>
    <artifactId>spring-cloud-starter-gateway</artifactId>
</dependency>

datasource 数据源扩展

实现效果:nacos发布配置后限流效果自动生效
demo可查看gateway项目application-sentinel.yml配置文件:

spring:
  cloud:
    sentinel: 
      datasource: 
        ds2:
          nacos: 
            server-addr: 192.168.67.129:8848
            data-id: sentinel
            group-id: Sentinel:Demo
            data-type: json
            rule-type: flow

OpenFeign 支持

  • 项目(openfeign项目请求userService和orderService项目)
  • 文档

RestTemplate 支持

About

基于spring boot的微服务架构

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published