Spring Cloud Gateway接入Sentinel

简介

本文用作记录Sentinel接入Spring Cloud Alibaba。

搭建Sentinel Dashboard

  • 官方jar包启动

  • docker启动

    1
    docker run --restart=always -d -it --name sentinel-dashboard -p 8858:8858 bladex/sentinel-dashboard

当然我直接在Rancher商城里面直接构建的(嘿嘿

项目引入

  • 添加mvn依赖

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    <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>
  • 添加配置

    1
    2
    3
    4
    5
    6
    spring:
    cloud:
    sentinel:
    transport:
    port: 8719 # sentinel规则接接收客户端口
    dashboard: 192.168.3.50:8858
    • 随便发起一个请求后可以在sentinel dashboard看到对应服务