Bootstrap

Gateway整合Sentinel实现对路由的限流规则

整合Sentinel

网关作为内部系统对外的一层屏障,对内起到一定的保护作用,限流便是其中之一。网关层的限流可以简单的针对不同路由进行限流,也可以针对业务的接口进行限流,或者根据接口的特征分组限流。

官方文档

快速整合

  1. 导入依赖

    <!--Gateway的依赖-->
    <dependency>
        <groupId>org.springframework.cloud</groupId>
        <artifactId>spring-cloud-starter-gateway</artifactId>
    </dependency>
    
    <!--nacos注册中心的依赖-->
    <dependency>
        <groupId>com.alibaba.cloud</groupId>
        <artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId>
    </dependency>
    
    <!--sentinelH整合gateway的依赖-->
    <dependency>
        <groupId>com.alibaba.cloud</groupId>
        <artifactId>spring-cloud-alibaba-sentinel-gateway</artifactId>
    </dependency>
    
    <!--sentinel的依赖-->
    <dependency>
        <groupId>com.alibaba.cloud</groupId>
        <artifactId>spring-cloud-starter-alibaba-sentinel</artifactId>
    </dependency>
    
  2. 配置sentinel控制台的远程服务地址

    server:
      port: 8088
    spring:
      application:
        name: api-gateway
      cloud:
        # 开始gateway的配置
        gateway:
          routes:
            - id: order_route
              uri: lb://order-service 
              predicates:
                - Path
;