潘志宝
2024-10-15 856d69ce678173e0a8e165bcb0135037d20b48ee
提交 | 用户 | 时间
e7c126 1 package com.iailab.framework.ratelimiter.config;
H 2
3 import com.iailab.framework.ratelimiter.core.aop.RateLimiterAspect;
4 import com.iailab.framework.ratelimiter.core.keyresolver.RateLimiterKeyResolver;
5 import com.iailab.framework.ratelimiter.core.keyresolver.impl.*;
6 import com.iailab.framework.ratelimiter.core.redis.RateLimiterRedisDAO;
7 import com.iailab.framework.redis.config.IailabRedisAutoConfiguration;
8 import org.redisson.api.RedissonClient;
9 import org.springframework.boot.autoconfigure.AutoConfiguration;
10 import org.springframework.context.annotation.Bean;
11
12 import java.util.List;
13
14 @AutoConfiguration(after = IailabRedisAutoConfiguration.class)
15 public class IailabRateLimiterConfiguration {
16
17     @Bean
18     public RateLimiterAspect rateLimiterAspect(List<RateLimiterKeyResolver> keyResolvers, RateLimiterRedisDAO rateLimiterRedisDAO) {
19         return new RateLimiterAspect(keyResolvers, rateLimiterRedisDAO);
20     }
21
22     @Bean
23     @SuppressWarnings("SpringJavaInjectionPointsAutowiringInspection")
24     public RateLimiterRedisDAO rateLimiterRedisDAO(RedissonClient redissonClient) {
25         return new RateLimiterRedisDAO(redissonClient);
26     }
27
28     // ========== 各种 RateLimiterRedisDAO Bean ==========
29
30     @Bean
31     public DefaultRateLimiterKeyResolver defaultRateLimiterKeyResolver() {
32         return new DefaultRateLimiterKeyResolver();
33     }
34
35     @Bean
36     public UserRateLimiterKeyResolver userRateLimiterKeyResolver() {
37         return new UserRateLimiterKeyResolver();
38     }
39
40     @Bean
41     public ClientIpRateLimiterKeyResolver clientIpRateLimiterKeyResolver() {
42         return new ClientIpRateLimiterKeyResolver();
43     }
44
45     @Bean
46     public ServerNodeRateLimiterKeyResolver serverNodeRateLimiterKeyResolver() {
47         return new ServerNodeRateLimiterKeyResolver();
48     }
49
50     @Bean
51     public ExpressionRateLimiterKeyResolver expressionRateLimiterKeyResolver() {
52         return new ExpressionRateLimiterKeyResolver();
53     }
54
55 }