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

The following examples show how to use org.springframework.cloud.gateway.filter.ratelimit.RedisRateLimiter. 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 File: LocalMemoryLimiter.java    From WeEvent with 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 File: ReservationClientApplication.java    From training with 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 File: ReservationClientApplication.java    From training with 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 File: ServiceConfig.java    From microservice-integration with 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
Source File: GatewayRedisAutoConfiguration.java    From spring-cloud-gateway with Apache License 2.0 5 votes vote down vote up
@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 File: Application.java    From spring-cloud-study with Apache License 2.0 4 votes vote down vote up
@Bean
RedisRateLimiter redisRateLimiter() {
    return new RedisRateLimiter(1, 1);
}
 
Example #7
Source File: TweetClientApplication.java    From reactive-spring-online-training with Apache License 2.0 4 votes vote down vote up
@Bean
RedisRateLimiter redisRateLimiter() {
		return new RedisRateLimiter(3, 4);
}
 
Example #8
Source File: ReservationClientApplication.java    From training with Apache License 2.0 4 votes vote down vote up
@Bean
RedisRateLimiter redisRateLimiter() {
		return new RedisRateLimiter(5, 7);
}
 
Example #9
Source File: ReservationClientApplication.java    From training with Apache License 2.0 4 votes vote down vote up
@Bean
RedisRateLimiter redisRateLimiter() {
	return new RedisRateLimiter(5, 7);
}
 
Example #10
Source File: DemogatewayApplication.java    From spring-cloud-gateway-sample with Apache License 2.0 4 votes vote down vote up
@Bean
RedisRateLimiter redisRateLimiter() {
	return new RedisRateLimiter(1, 2);
}
 
Example #11
Source File: ReservationClientApplication.java    From bootiful-reactive-microservices with Apache License 2.0 4 votes vote down vote up
@Bean
RedisRateLimiter redisRateLimiter() {
	return new RedisRateLimiter(5, 7);
}
 
Example #12
Source File: ReservationClientApplication.java    From bootiful-reactive-microservices with Apache License 2.0 4 votes vote down vote up
@Bean
RedisRateLimiter redisRateLimiter() {
	return new RedisRateLimiter(5, 7);
}
 
Example #13
Source File: ReservationClientApplication.java    From bootiful-reactive-microservices with Apache License 2.0 4 votes vote down vote up
@Bean
RedisRateLimiter rl() {
	return new RedisRateLimiter(5, 7);
}
 
Example #14
Source File: ReservationClientApplication.java    From bootiful-reactive-microservices with Apache License 2.0 4 votes vote down vote up
@Bean
RedisRateLimiter redisRateLimiter() {
		return new RedisRateLimiter(5, 7);
}
 
Example #15
Source File: ReservationClientApplication.java    From bootiful-reactive-microservices with Apache License 2.0 4 votes vote down vote up
@Bean
RedisRateLimiter redisRateLimiter() {
	return new RedisRateLimiter(5, 7);
}
 
Example #16
Source File: RouteConfig.java    From iot-dc3 with Apache License 2.0 2 votes vote down vote up
/**
 * Redis 令牌桶 限流
 *
 * @return RedisRateLimiter
 */
@Bean
RedisRateLimiter redisRateLimiter() {
    return new RedisRateLimiter(100, 2000);
}