diff --git a/multi/multi__gatewayfilter_factories.html b/multi/multi__gatewayfilter_factories.html index 95bf69a0..df9e6bbe 100644 --- a/multi/multi__gatewayfilter_factories.html +++ b/multi/multi__gatewayfilter_factories.html @@ -72,7 +72,7 @@ The Hystrix GatewayFilter allows you to introduce circuit breakers to your gatew uri: http://example.org filters: - PreserveHostHeader
-
This will prefix /mypath to the path of all matching requests. So a request to /hello, would be sent to /mypath/hello.
The RequestRateLimiter GatewayFilter Factory takes three parameters: replenishRate, burstCapacity & keyResolverName.
replenishRate is how many requests per second do you want a user to be allowed to do.
burstCapacity TODO: document burst capacity
keyResolver is a bean that implements the KeyResolver interface. In configuration, reference the bean by name using SpEL. #{@myKeyResolver} is a SpEL expression referencing a bean with the name myKeyResolver.
KeyResolver.java. +
This will prefix /mypath to the path of all matching requests. So a request to /hello, would be sent to /mypath/hello.
The RequestRateLimiter GatewayFilter Factory takes three parameters: replenishRate, burstCapacity & keyResolverName.
replenishRate is how many requests per second do you want a user to be allowed to do, without any dropped requests.
burstCapacity is the maximum number of requests a user is allowed to do in a single second.
A steady rate is accomplished by setting the same value in replenishRate and burstCapacity. Temporary bursts can be allowed by setting burstCapacity higher than replenishRate. In this case, the rate limiter needs to be allowed some time between bursts (according to replenishRate), as 2 consecutive bursts will result in dropped requests (HTTP 429 - Too Many Requests).
keyResolver is a bean that implements the KeyResolver interface. In configuration, reference the bean by name using SpEL. #{@myKeyResolver} is a SpEL expression referencing a bean with the name myKeyResolver.
KeyResolver.java.
public interface KeyResolver { Mono<String> resolve(ServerWebExchange exchange); }
@@ -84,13 +84,29 @@ The Hystrix GatewayFilter allows you to introduce circuit breakers to your gatew - id: requestratelimiter_route uri: http://example.org filters: - - RequestRateLimiter=10, 20, #{@userKeyResolver}
+ - name: RequestRateLimiter + args: + redis-rate-limiter.replenishRate: 10 + redis-rate-limiter.burstCapacity: 20 + key-resolver: "#{@userKeyResolver}"
Config.java.
@Bean KeyResolver userKeyResolver() { return exchange -> Mono.just(exchange.getRequest().getQueryParams().getFirst("user")); }
-
This defines a request rate limit of 10 per user. The KeyResolver is a simple one that gets the user request parameter (note: this is not recommended for production).
The RedirectTo GatewayFilter Factory takes a status and a url parameter. The status should be a 300 series redirect http code, such as 301. The url should be a valid url. This will be the value of the Location header.
application.yml. +
This defines a request rate limit of 10 per user. A burst of 20 is allowed, but the next second only 10 requests will be available. The KeyResolver is a simple one that gets the user request parameter (note: this is not recommended for production).
A rate limiter can also be defined as a bean implementing the RateLimiter interface. In configuration, reference the bean by name using SpEL. #{@myRateLimiter} is a SpEL expression referencing a bean with the name myRateLimiter.
application.yml. +
spring: + cloud: + gateway: + routes: + - id: requestratelimiter_route + uri: http://example.org + filters: + - name: RequestRateLimiter + args: + rate-limiter: "#{@myRateLimiter}" + key-resolver: "#{@userKeyResolver}"
+
The RedirectTo GatewayFilter Factory takes a status and a url parameter. The status should be a 300 series redirect http code, such as 301. The url should be a valid url. This will be the value of the Location header.
application.yml.
spring: cloud: gateway: diff --git a/single/spring-cloud-gateway.html b/single/spring-cloud-gateway.html index ab8b6026..b013a24e 100644 --- a/single/spring-cloud-gateway.html +++ b/single/spring-cloud-gateway.html @@ -189,7 +189,7 @@ The Hystrix GatewayFilter allows you to introduce circuit breakers to your gatew uri: http://example.org filters: - PreserveHostHeader
-
This will prefix /mypath to the path of all matching requests. So a request to /hello, would be sent to /mypath/hello.
The RequestRateLimiter GatewayFilter Factory takes three parameters: replenishRate, burstCapacity & keyResolverName.
replenishRate is how many requests per second do you want a user to be allowed to do.
burstCapacity TODO: document burst capacity
keyResolver is a bean that implements the KeyResolver interface. In configuration, reference the bean by name using SpEL. #{@myKeyResolver} is a SpEL expression referencing a bean with the name myKeyResolver.
KeyResolver.java. +
This will prefix /mypath to the path of all matching requests. So a request to /hello, would be sent to /mypath/hello.
The RequestRateLimiter GatewayFilter Factory takes three parameters: replenishRate, burstCapacity & keyResolverName.
replenishRate is how many requests per second do you want a user to be allowed to do, without any dropped requests.
burstCapacity is the maximum number of requests a user is allowed to do in a single second.
A steady rate is accomplished by setting the same value in replenishRate and burstCapacity. Temporary bursts can be allowed by setting burstCapacity higher than replenishRate. In this case, the rate limiter needs to be allowed some time between bursts (according to replenishRate), as 2 consecutive bursts will result in dropped requests (HTTP 429 - Too Many Requests).
keyResolver is a bean that implements the KeyResolver interface. In configuration, reference the bean by name using SpEL. #{@myKeyResolver} is a SpEL expression referencing a bean with the name myKeyResolver.
KeyResolver.java.
public interface KeyResolver { Mono<String> resolve(ServerWebExchange exchange); }
@@ -201,13 +201,29 @@ The Hystrix GatewayFilter allows you to introduce circuit breakers to your gatew - id: requestratelimiter_route uri: http://example.org filters: - - RequestRateLimiter=10, 20, #{@userKeyResolver}
+ - name: RequestRateLimiter + args: + redis-rate-limiter.replenishRate: 10 + redis-rate-limiter.burstCapacity: 20 + key-resolver: "#{@userKeyResolver}"
Config.java.
@Bean KeyResolver userKeyResolver() { return exchange -> Mono.just(exchange.getRequest().getQueryParams().getFirst("user")); }
-
This defines a request rate limit of 10 per user. The KeyResolver is a simple one that gets the user request parameter (note: this is not recommended for production).
The RedirectTo GatewayFilter Factory takes a status and a url parameter. The status should be a 300 series redirect http code, such as 301. The url should be a valid url. This will be the value of the Location header.
application.yml. +
This defines a request rate limit of 10 per user. A burst of 20 is allowed, but the next second only 10 requests will be available. The KeyResolver is a simple one that gets the user request parameter (note: this is not recommended for production).
A rate limiter can also be defined as a bean implementing the RateLimiter interface. In configuration, reference the bean by name using SpEL. #{@myRateLimiter} is a SpEL expression referencing a bean with the name myRateLimiter.
application.yml. +
spring: + cloud: + gateway: + routes: + - id: requestratelimiter_route + uri: http://example.org + filters: + - name: RequestRateLimiter + args: + rate-limiter: "#{@myRateLimiter}" + key-resolver: "#{@userKeyResolver}"
+
The RedirectTo GatewayFilter Factory takes a status and a url parameter. The status should be a 300 series redirect http code, such as 301. The url should be a valid url. This will be the value of the Location header.
application.yml.
spring: cloud: gateway: diff --git a/spring-cloud-gateway.xml b/spring-cloud-gateway.xml index 741916af..8c079928 100644 --- a/spring-cloud-gateway.xml +++ b/spring-cloud-gateway.xml @@ -460,8 +460,9 @@ The Hystrix GatewayFilter allows you to introduce circuit breakers to your gatewRequestRateLimiter GatewayFilter Factory The RequestRateLimiter GatewayFilter Factory takes three parameters: -replenishRate ,burstCapacity &keyResolverName .- replenishRate is how many requests per second do you want a user to be allowed to do.+ burstCapacity TODO: document burst capacity+ replenishRate is how many requests per second do you want a user to be allowed to do, without any dropped requests.+ burstCapacity is the maximum number of requests a user is allowed to do in a single second.A steady rate is accomplished by setting the same value in replenishRate andburstCapacity . Temporary bursts can be allowed by settingburstCapacity higher thanreplenishRate . In this case, the rate limiter needs to be allowed some time between bursts (according toreplenishRate ), as 2 consecutive bursts will result in dropped requests (HTTP 429 - Too Many Requests ).keyResolver is a bean that implements theKeyResolver interface. In configuration, reference the bean by name using SpEL.#{@myKeyResolver} is a SpEL expression referencing a bean with the namemyKeyResolver .KeyResolver.java @@ -483,7 +484,11 @@ The Hystrix GatewayFilter allows you to introduce circuit breakers to your gatew - id: requestratelimiter_route uri: http://example.org filters: - - RequestRateLimiter=10, 20, #{@userKeyResolver} + - name: RequestRateLimiter + args: + redis-rate-limiter.replenishRate: 10 + redis-rate-limiter.burstCapacity: 20 + key-resolver: "#{@userKeyResolver}"@@ -495,7 +500,24 @@ KeyResolver userKeyResolver() { } -This defines a request rate limit of 10 per user. The +KeyResolver is a simple one that gets theuser request parameter (note: this is not recommended for production).This defines a request rate limit of 10 per user. A burst of 20 is allowed, but the next second only 10 requests will be available. The +KeyResolver is a simple one that gets theuser request parameter (note: this is not recommended for production).A rate limiter can also be defined as a bean implementing the +RateLimiter interface. In configuration, reference the bean by name using SpEL.#{@myRateLimiter} is a SpEL expression referencing a bean with the namemyRateLimiter .+ application.yml ++ +spring: + cloud: + gateway: + routes: + - id: requestratelimiter_route + uri: http://example.org + filters: + - name: RequestRateLimiter + args: + rate-limiter: "#{@myRateLimiter}" + key-resolver: "#{@userKeyResolver}" +RedirectTo GatewayFilter Factory