@ConfigurationProperties(value="spring.cloud.gateway.redis-rate-limiter") public class RedisRateLimiter extends AbstractRateLimiter<RedisRateLimiter.Config> implements org.springframework.context.ApplicationContextAware
Modifier and Type | Class and Description |
---|---|
static class |
RedisRateLimiter.Config |
RateLimiter.Response
Modifier and Type | Field and Description |
---|---|
static String |
BURST_CAPACITY_HEADER
Burst Capacity header name.
|
static String |
CONFIGURATION_PROPERTY_NAME
Redis Rate Limiter property name.
|
static String |
REDIS_SCRIPT_NAME
Redis Script name.
|
static String |
REMAINING_HEADER
Remaining Rate Limit header name.
|
static String |
REPLENISH_RATE_HEADER
Replenish Rate Limit header name.
|
static String |
REQUESTED_TOKENS_HEADER
Requested Tokens header name.
|
Constructor and Description |
---|
RedisRateLimiter(int defaultReplenishRate,
int defaultBurstCapacity)
This creates an instance with default static configuration, useful in Java DSL.
|
RedisRateLimiter(int defaultReplenishRate,
int defaultBurstCapacity,
int defaultRequestedTokens)
This creates an instance with default static configuration, useful in Java DSL.
|
RedisRateLimiter(org.springframework.data.redis.core.ReactiveStringRedisTemplate redisTemplate,
org.springframework.data.redis.core.script.RedisScript<List<Long>> script,
ConfigurationService configurationService) |
Modifier and Type | Method and Description |
---|---|
String |
getBurstCapacityHeader() |
Map<String,String> |
getHeaders(RedisRateLimiter.Config config,
Long tokensLeft) |
String |
getRemainingHeader() |
String |
getReplenishRateHeader() |
String |
getRequestedTokensHeader() |
reactor.core.publisher.Mono<RateLimiter.Response> |
isAllowed(String routeId,
String id)
This uses a basic token bucket algorithm and relies on the fact that Redis scripts
execute atomically.
|
boolean |
isIncludeHeaders() |
void |
setApplicationContext(org.springframework.context.ApplicationContext context)
Used when setting default configuration in constructor.
|
void |
setBurstCapacityHeader(String burstCapacityHeader) |
void |
setIncludeHeaders(boolean includeHeaders) |
void |
setRemainingHeader(String remainingHeader) |
void |
setReplenishRateHeader(String replenishRateHeader) |
void |
setRequestedTokensHeader(String requestedTokensHeader) |
getConfigurationPropertyName, onApplicationEvent, setConfigurationService, toString
getConfig
getConfigClass, newConfig
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
getConfig
getConfigClass, newConfig
public static final String CONFIGURATION_PROPERTY_NAME
public static final String REDIS_SCRIPT_NAME
public static final String REMAINING_HEADER
public static final String REPLENISH_RATE_HEADER
public static final String BURST_CAPACITY_HEADER
public static final String REQUESTED_TOKENS_HEADER
public RedisRateLimiter(org.springframework.data.redis.core.ReactiveStringRedisTemplate redisTemplate, org.springframework.data.redis.core.script.RedisScript<List<Long>> script, ConfigurationService configurationService)
public RedisRateLimiter(int defaultReplenishRate, int defaultBurstCapacity)
defaultReplenishRate
- how many tokens per second in token-bucket algorithm.defaultBurstCapacity
- how many tokens the bucket can hold in token-bucket
algorithm.public RedisRateLimiter(int defaultReplenishRate, int defaultBurstCapacity, int defaultRequestedTokens)
defaultReplenishRate
- how many tokens per second in token-bucket algorithm.defaultBurstCapacity
- how many tokens the bucket can hold in token-bucket
algorithm.defaultRequestedTokens
- how many tokens are requested per request.public boolean isIncludeHeaders()
public void setIncludeHeaders(boolean includeHeaders)
public String getRemainingHeader()
public void setRemainingHeader(String remainingHeader)
public String getReplenishRateHeader()
public void setReplenishRateHeader(String replenishRateHeader)
public String getBurstCapacityHeader()
public void setBurstCapacityHeader(String burstCapacityHeader)
public String getRequestedTokensHeader()
public void setRequestedTokensHeader(String requestedTokensHeader)
public void setApplicationContext(org.springframework.context.ApplicationContext context) throws org.springframework.beans.BeansException
setApplicationContext
in interface org.springframework.context.ApplicationContextAware
context
- the ApplicationContext object to be used by this objectorg.springframework.beans.BeansException
- if thrown by application context methodspublic reactor.core.publisher.Mono<RateLimiter.Response> isAllowed(String routeId, String id)
isAllowed
in interface RateLimiter<RedisRateLimiter.Config>
@NotNull public Map<String,String> getHeaders(RedisRateLimiter.Config config, Long tokensLeft)
Copyright © 2020 Pivotal Software, Inc.. All rights reserved.