其他的不变(见上一两篇)
https://blog.csdn.net/baidu_38845827/article/details/113586679
https://blog.csdn.net/baidu_38845827/article/details/113594621
修改配置文件的RateLimitOptions
{
"ReRoutes": [
{
"UseServiceDiscovery": true,
"DownstreamPathTemplate": "/{url}",
"DownstreamScheme": "http",
//"DownstreamHostAndPorts": [
// {
// "Host": "localhost",
// "Port": 59607
// }
//],
"UpstreamPathTemplate": "/{url}",
"UpstreamHttpMethod": [ "GET", "POST" ],
"LoadBalancerOptions": {
"Type": "RoundRobin"
},
"ServiceName": "hotel_api",
"RateLimitOptions": {
"ClientWhitelist": [ ], //白名单里的客户端 请求不进行限流
"EnableRateLimiting": true, //开启限流
"Period": "1s",
"PeriodTimespan": 1, // 被限制了5s 后 可以再请求
"Limit": 1 //1s内 最多访问 1 次
}
}
],
"GlobalConfiguration": {
"ServiceDiscoveryProvider": {
"Scheme": "http",
"Host": "localhost",
"Port": 8500,
"Type": "Consul"
},
"RateLimitOptions": {
"DisableRateLimitHeaders": false,
"QuotaExceededMessage": "To many ya", //被限制后的提示语
"HttpStatusCode": 999 //被限制后的 返回的状态码
}
}
}
其他代码不变 经测试 没问题
完毕