Last active
June 6, 2022 16:52
-
-
Save reevik/2ef57d974ed80343a87977d249888cf1 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@EnableWebMvc | |
@Configuration | |
@EnableCaching | |
public class AppConfig implements WebMvcConfigurer { | |
@Bean | |
public RateLimiter rateLimiter() throws IOException { | |
return new RateLimiter(proxyManager(), bucketConfiguration()); | |
} | |
@Bean(destroyMethod = "shutdown") | |
public ConnectionManager redissonConnectionManager() throws IOException { | |
File resourceURL = ResourceUtils.getFile("classpath:redis.yml"); | |
Config config = Config.fromYAML(resourceURL); | |
return ConfigSupport.createConnectionManager(config); | |
} | |
@Bean | |
public RedissonBasedProxyManager proxyManager() throws IOException { | |
CommandSyncService commandSyncService = | |
new CommandSyncService(redissonConnectionManager()); | |
return new RedissonBasedProxyManager(commandSyncService, | |
ClientSideConfig.getDefault(), | |
Duration.ofMinutes(10)); | |
} | |
@Bean | |
public BucketConfiguration bucketConfiguration() { | |
return BucketConfiguration | |
.builder() | |
.addLimit(Bandwidth.simple(2, Duration.ofSeconds(1)).withInitialTokens(2)) | |
.build(); | |
} | |
} |
jaksonlima
commented
Jun 6, 2022
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment