Please see gitee for the entire project: https://gitee.com/xwb1056481167/spring-cloud
Sentinel installation and project integration: https://blog.csdn.net/www1056481167/article/details/113679945
Modify cloudalibaba-sentinel-service8401 project
1、jar包
<!-- alibaba sentinel -->
<dependency>
<groupId>com.alibaba.csp</groupId>
<artifactId>sentinel-datasource-nacos</artifactId>
</dependency>
<!-- alibaba nacos -->
<dependency>
<groupId>com.alibaba.cloud</groupId>
<artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId>
</dependency>
<!-- alibaba nacos sentinel -->
<dependency>
<groupId>com.alibaba.cloud</groupId>
<artifactId>spring-cloud-starter-alibaba-sentinel</artifactId>
</dependency>
2 、 application.yml
spring:
cloud:
sentinel:
# 将sentinel的配置数据保存到nacos中
datasource:
ds1: #数据源1
nacos:
server-addr: localhost:8848
dataId: cloudalibaba-sentinel-service
groupId: DEFAULT_GROUP
data-type: json
rule-type: flow
3. Add a file in the nacos console
[
{
"resource":"/rateLimit/byUrl",
"limitApp":"default",
"grade":1,
"count":1,
"strategy":0,
"controlBehavior":0,
"clusterMode":false
}
]
Description:
resource: resource name
limitApp: source application
grade: threshold type 0, thread number 1, QPS
count: stand-alone threshold
strategy: flow control mode, 0 means direct connection 1 means association 2 means link
controlBehavior: flow control effect, 0 fast Failure 1.
Means Warm Up, 2. Means waiting in line. ClusterMode: Whether the cluster is true, cluster is false, not cluster
Nacos configures the service name cloudalibaba-sentinel-service
The configuration is complete, and the /rateLimit/byUrl interface is accessed according to the rules, and the verification is successful