package cn.reghao.tnb.gateway.limiter;

import org.springframework.cloud.gateway.route.RouteLocator;
import org.springframework.cloud.gateway.route.builder.RouteLocatorBuilder;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author reghao
 * @date 2023-09-14 13:21:48
 */
//@Configuration
public class MyLimiterConfig {
    @Bean
    public RouteLocator routeLocator(RouteLocatorBuilder builder) {
        return builder.routes()
                .route("rate-limiter", r -> r.path("/api/content/**")
                        .filters(filter -> filter.requestRateLimiter().rateLimiter(MyRateLimiter.class, limiter -> limiter.setRequestedTokens(10)).and())
                        .uri("lb://content-service")
                )
                .build();
    }
}
