Java Code Examples for org.springframework.cloud.gateway.filter.ratelimit.RedisRateLimiter

The following examples show how to use org.springframework.cloud.gateway.filter.ratelimit.RedisRateLimiter. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: WeEvent   Source File: LocalMemoryLimiter.java    License: Apache License 2.0 5 votes vote down vote up
@NotNull
public Map<String, String> getHeaders(Config config, long tokensLeft) {
    Map<String, String> headers = new HashMap<>();
    headers.put(RedisRateLimiter.REMAINING_HEADER, String.valueOf(tokensLeft));
    headers.put(RedisRateLimiter.REPLENISH_RATE_HEADER,
            String.valueOf(config.getReplenishRate()));
    headers.put(RedisRateLimiter.BURST_CAPACITY_HEADER,
            String.valueOf(config.getBurstCapacity()));
    return headers;
}
 
Example 2
Source Project: training   Source File: ReservationClientApplication.java    License: Apache License 2.0 5 votes vote down vote up
@Bean
RouteLocator gateway(RouteLocatorBuilder rlb,
																					RedisRateLimiter rl) {
		return rlb
			.routes()
			.route(rs -> rs
				.path("/proxy")
				.filters(fs -> fs
					.requestRateLimiter(c -> c.setRateLimiter(rl))
					.setPath("/reservations"))
				.uri("lb://reservation-service/"))
			.build();
}
 
Example 3
Source Project: training   Source File: ReservationClientApplication.java    License: Apache License 2.0 5 votes vote down vote up
@Bean
RouteLocator gateway(RouteLocatorBuilder rlb,
                     RedisRateLimiter rl) {
	return rlb
			.routes()
			.route(rs -> rs
					.path("/proxy")
					.filters(fs -> fs
							.requestRateLimiter(c -> c.setRateLimiter(rl))
							.setPath("/reservations"))
					.uri("lb://reservation-service/"))
			.build();
}
 
Example 4
Source Project: microservice-integration   Source File: ServiceConfig.java    License: MIT License 5 votes vote down vote up
@Bean(name = "customRateLimiter")
@Primary
public RedisRateLimiter myRateLimiter(GatewayLimitProperties gatewayLimitProperties) {
    GatewayLimitProperties.RedisRate redisRate = gatewayLimitProperties.getRedisRate();
    if (Objects.isNull(redisRate)) {
        throw new ServerException(ErrorCodes.PROPERTY_NOT_INITIAL);
    }
    return new RedisRateLimiter(redisRate.getReplenishRate(), redisRate.getBurstCapacity());
}
 
Example 5
@Bean
@ConditionalOnMissingBean
public RedisRateLimiter redisRateLimiter(ReactiveStringRedisTemplate redisTemplate,
		@Qualifier(RedisRateLimiter.REDIS_SCRIPT_NAME) RedisScript<List<Long>> redisScript,
		ConfigurationService configurationService) {
	return new RedisRateLimiter(redisTemplate, redisScript, configurationService);
}
 
Example 6
Source Project: spring-cloud-study   Source File: Application.java    License: Apache License 2.0 4 votes vote down vote up
@Bean
RedisRateLimiter redisRateLimiter() {
    return new RedisRateLimiter(1, 1);
}
 
Example 7
@Bean
RedisRateLimiter redisRateLimiter() {
		return new RedisRateLimiter(3, 4);
}
 
Example 8
Source Project: training   Source File: ReservationClientApplication.java    License: Apache License 2.0 4 votes vote down vote up
@Bean
RedisRateLimiter redisRateLimiter() {
		return new RedisRateLimiter(5, 7);
}
 
Example 9
Source Project: training   Source File: ReservationClientApplication.java    License: Apache License 2.0 4 votes vote down vote up
@Bean
RedisRateLimiter redisRateLimiter() {
	return new RedisRateLimiter(5, 7);
}
 
Example 10
@Bean
RedisRateLimiter redisRateLimiter() {
	return new RedisRateLimiter(1, 2);
}
 
Example 11
@Bean
RedisRateLimiter redisRateLimiter() {
	return new RedisRateLimiter(5, 7);
}
 
Example 12
@Bean
RedisRateLimiter redisRateLimiter() {
	return new RedisRateLimiter(5, 7);
}
 
Example 13
@Bean
RedisRateLimiter rl() {
	return new RedisRateLimiter(5, 7);
}
 
Example 14
@Bean
RedisRateLimiter redisRateLimiter() {
		return new RedisRateLimiter(5, 7);
}
 
Example 15
@Bean
RedisRateLimiter redisRateLimiter() {
	return new RedisRateLimiter(5, 7);
}
 
Example 16
Source Project: iot-dc3   Source File: RouteConfig.java    License: Apache License 2.0 2 votes vote down vote up
/**
 * Redis 令牌桶 限流
 *
 * @return RedisRateLimiter
 */
@Bean
RedisRateLimiter redisRateLimiter() {
    return new RedisRateLimiter(100, 2000);
}