一.概述
sentinel提供了限流的功能,本章节讲解如何使用sentinel对我们开发的接口进行限流.
二.sentinel限流
1.server-user服务,加入了spring.cloud.sentinel和management的相关配置.
(1)management.endpoints.web.exposure.include这个配置属于springboot Actuator,众所周知,这个包的主要作用是服务健康监控,提供了大量的接口,很多监控服务的组件比如nacos都是以调用这个包提供的一些接口实现的,该配置的作用允许sentinel调用springboot Actuator提供的一些接口,做到完善的监控功能.
(2)spring.cloud.sentinel相关配置已经在代码的注释中给出.
server:
port: 1001 #服务端口
spring:
application:
name: server-user #服务名称
cloud:
nacos:
discovery:
server-addr: 47.96.131.185:8848
config:
server-addr: 47.96.131.185:8848 #nacos config配置中心ip和端口
file-extension: yaml #文件扩展名格式,针对于默认的{spring.application.name}-${profile}.${file-extension:properties}配置
enabled: true #开启或关闭配置中心
shared-dataids: mysql-user.yaml #自定义的配置文件dataid,以逗号分隔