Add RedisRateLimiter to webfilter package
This commit is contained in:
+16
@@ -0,0 +1,16 @@
|
||||
package com.baeldung.springcloudgateway.webfilters.config;
|
||||
|
||||
import org.springframework.cloud.gateway.filter.ratelimit.KeyResolver;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
import reactor.core.publisher.Mono;
|
||||
|
||||
@Configuration
|
||||
public class RequestRateLimiterResolverConfig {
|
||||
|
||||
@Bean
|
||||
KeyResolver userKeyResolver() {
|
||||
return exchange -> Mono.just("1");
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,12 @@
|
||||
logging:
|
||||
level:
|
||||
org.springframework.cloud.gateway: INFO
|
||||
reactor.netty.http.client: INFO
|
||||
|
||||
spring:
|
||||
redis:
|
||||
host: localhost
|
||||
port: 6379
|
||||
cloud:
|
||||
gateway:
|
||||
routes:
|
||||
@@ -81,13 +89,14 @@ spring:
|
||||
factor: 2
|
||||
basedOnPreviousValue: false
|
||||
|
||||
- id: circuitbreaker_route
|
||||
- id: request_rate_limiter
|
||||
uri: https://httpbin.org
|
||||
predicates:
|
||||
- Path=/status/504
|
||||
- Path=/redis/get/**
|
||||
filters:
|
||||
- name: CircuitBreaker
|
||||
- StripPrefix=1
|
||||
- name: RequestRateLimiter
|
||||
args:
|
||||
name: myCircuitBreaker
|
||||
fallbackUri: forward:/anything
|
||||
- RewritePath=/status/504, /anything
|
||||
redis-rate-limiter.replenishRate: 10
|
||||
redis-rate-limiter.burstCapacity: 5
|
||||
key-resolver: "#{@userKeyResolver}"
|
||||
Reference in New Issue
Block a user