Category : bucket4j

Order This article mainly demonstrates several examples of bucket4j maven <dependency> <groupId>com.github.vladimir-bukhtoyarov</groupId> <artifactId>bucket4j-core</artifactId> <version>4.0.1</version> </dependency> rate limit @Test public void testRateLimit(){ // define the limit 1 time per 10 minute Bandwidth limit = Bandwidth.simple(1, Duration.ofMinutes(10)); // construct the bucket Bucket bucket = Bucket4j.builder().addLimit(limit).build(); IntStream.rangeClosed(1,5) .forEach(i -> { executor.submit(() -> { if(bucket.tryConsume(1)){ LOGGER.info(“acquired”); }else{ LOGGER.info(“blocked”); } ..

Read more

Order This article mainly studies how to use bucket4j-spring-boot-starter for current limiting. maven <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-actuator</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-cache</artifactId> </dependency> <dependency> <groupId>com.github.ben-manes.caffeine</groupId> <artifactId>caffeine</artifactId> </dependency> <dependency> <groupId>javax.cache</groupId> <artifactId>cache-api</artifactId> <version>1.1.0</version> </dependency> <dependency> <groupId>com.github.ben-manes.caffeine</groupId> <artifactId>jcache</artifactId> <version>2.6.2</version> </dependency> <dependency> <groupId>com.giffing.bucket4j.spring.boot.starter</groupId> <artifactId>bucket4j-spring-boot-starter</artifactId> <version>0.1.3</version> </dependency> <dependency> <groupId>com.github.vladimir-bukhtoyarov</groupId> <artifactId>bucket4j-core</artifactId> <version>4.0.0</version> </dependency> <dependency> <groupId>com.github.vladimir-bukhtoyarov</groupId> <artifactId>bucket4j-jcache</artifactId> <version>4.0.0</version> </dependency> Configuration ..

Read more