diff --git a/README.adoc b/README.adoc index 095fbd26..5535d2911 100644 --- a/README.adoc +++ b/README.adoc @@ -137,6 +137,7 @@ bucket4j.filters[0].metrics.tags[2].key=USERNAME bucket4j.filters[0].metrics.tags[2].expression=@securityService.username() != null ? @securityService.username() : 'anonym' bucket4j.filters[0].strategy=first # [first, all] if multiple rate limits configured the 'first' strategy stops the processing after the first matching bucket4j.filters[0].rate-limits[0].expression=getRemoteAddr() +bucket4j.filters[0].rate-limits[0].num-tokens=1 # The number of tokens to consume bucket4j.filters[0].rate-limits[0].execute-condition=1==1 # an optional SpEl expression to decide to execute the rate limit or not bucket4j.filters[0].rate-limits[0].skip-condition=1==1 # an optional SpEl expression to skip the rate limit bucket4j.filters[0].rate-limits[0].bandwidths[0].capacity=10 diff --git a/bucket4j-spring-boot-starter-context/src/main/java/com/giffing/bucket4j/spring/boot/starter/context/properties/RateLimit.java b/bucket4j-spring-boot-starter-context/src/main/java/com/giffing/bucket4j/spring/boot/starter/context/properties/RateLimit.java index 12619b41..260da78e 100644 --- a/bucket4j-spring-boot-starter-context/src/main/java/com/giffing/bucket4j/spring/boot/starter/context/properties/RateLimit.java +++ b/bucket4j-spring-boot-starter-context/src/main/java/com/giffing/bucket4j/spring/boot/starter/context/properties/RateLimit.java @@ -18,12 +18,15 @@ public class RateLimit { */ private String skipCondition; - /** + /** * SPEL expression to dynamic evaluate filter key */ private String expression = "1"; - private Integer cost = 1; + /** + * The number of tokens that should be consumed + */ + private Integer numTokens = 1; private List bandwidths = new ArrayList<>(); diff --git a/bucket4j-spring-boot-starter/src/main/java/com/giffing/bucket4j/spring/boot/starter/config/Bucket4JBaseConfiguration.java b/bucket4j-spring-boot-starter/src/main/java/com/giffing/bucket4j/spring/boot/starter/config/Bucket4JBaseConfiguration.java index dbae5f94..70c05f70 100644 --- a/bucket4j-spring-boot-starter/src/main/java/com/giffing/bucket4j/spring/boot/starter/config/Bucket4JBaseConfiguration.java +++ b/bucket4j-spring-boot-starter/src/main/java/com/giffing/bucket4j/spring/boot/starter/config/Bucket4JBaseConfiguration.java @@ -105,7 +105,7 @@ public FilterConfiguration buildFilterConfig( filterConfig.getMetrics().getTypes(), metricTagResults); - return proxyWrapper.tryConsumeAndReturnRemaining(key, rl.getCost(), bucketConfiguration, metricBucketListener); + return proxyWrapper.tryConsumeAndReturnRemaining(key, rl.getNumTokens(), bucketConfiguration, metricBucketListener); } return null;