SpringCloudApiGatewayZuul Rate limit流量 控制.md
访问限速,提供local本地策略【开发】和redis限速【生产】
可以按照每个服务、url、用户、全局进行限速配置
https://github.com/marcosbarbero/spring-cloud-starter-zuul-ratelimit
Spring Cloud Zuul RateLimit
Module to enable rate limit per service in Netflix Zuul.
There are five built-in rate limit approaches:
- Authenticated User: Uses the authenticated username or 'anonymous'
- Request Origin: Uses the user origin request
- URL: Uses the request path of the upstream service
- Can be combined with Authenticated User, Request Origin or both
- Authenticated User and Request Origin: Combines the authenticated user and the Request Origin
- Global configuration per service: This one doesn't validate the request Origin or the Authenticated User
- To use this approach just don't set param 'type'
Adding Project Lombok Agent
Usage
This project is available on maven central
Add the dependency on pom.xml
<dependency>
<groupId>com.marcosbarbero.cloud</groupId>
<artifactId>spring-cloud-zuul-ratelimit</artifactId>
<version>1.0.5.RELEASE</version>
</dependency>
Sample configuration
zuul:
ratelimit:
enabled: true #default false
behind-proxy: true #default false
policies:
myServiceId:
limit: 10
refresh-interval: 60 #default value (in seconds)
type: url #optional - user - origin - url
zuul Load Shedding Load Shedding - allocating capacity for each type of request and dropping requests that go over the limit.