安装完sentinel之后,就像尝试使用一下限流功能,因为项目使用的是微服务框架,打算直接再gateway中进行限流.
问题1:
配置好的限流不起作用?
1.1请检查一下,gateway的是否引入了sentinel
<dependency>
<groupId>com.alibaba.cloud</groupId>
<artifactId>spring-cloud-starter-alibaba-sentinel</artifactId>
<version>${spring-cloud-alibaba.version}</version>
</dependency>
1.2是否在配置文件正确配置sentinel
# sentinel控制面板进行限流,熔断控制等操作,通过此端口来配置gateway
spring.cloud.sentinel.transport.port=8082
# sentinel控制面板的请求接口
spring.cloud.sentinel.transport.dashboard=localhost:8858
# 取消Sentinel控制台懒加载(懒加载:只有访问该微服务才会在sentinel控制台监控到)
spring.cloud.sentinel.eager=true
1.3 是否在启动时配置了服务为gateway
sentinel 1.8控制台整合gateway无法显示nacos上配置的流控规则 · Issue #2239 · alibaba/Sentinel · GitHub
如果打不开,可以看一下下面的截图

image.png
我这里使用的gateway非alibaba 的,所以 采用了 启动命令加入 -Dcsp.sentinel.app.type=1, 标明为网关服务。至此网关服务配置好了

image.png