add
yj
2024-12-05 b9900893177c78fc559223521fe839aa21000017
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
package com.dobbinsoft.fw.support.config.rate;
 
import com.dobbinsoft.fw.support.properties.FwRateLimitProperties;
import com.dobbinsoft.fw.support.rate.RateLimiterRedisSlidingWindow;
import com.dobbinsoft.fw.support.rate.RateLimiter;
import com.dobbinsoft.fw.support.rate.RateLimiterNone;
import com.dobbinsoft.fw.support.rate.RateLimiterRedisCount;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
 
/**
 * ClassName: RateLimiterConfig
 * Description: TODO
 *
 * @author: e-weichaozheng
 * @date: 2021-04-13
 */
@Configuration
public class RateLimiterConfig {
 
    @Autowired
    private FwRateLimitProperties properties;
 
    @Bean
    public RateLimiter rateLimiter() {
        if ("count".equals(properties.getEnable())) {
            return new RateLimiterRedisCount();
        } else if ("sliding".equals(properties.getEnable())) {
            return new RateLimiterRedisSlidingWindow();
        } else {
//            return new RateLimitRedisSlidingWindow();
            return new RateLimiterNone();
        }
    }
 
}