ProductPromotion
Logo

Java

made by https://0x3d.site

GitHub - bucket4j/bucket4j: Java rate limiting library based on token-bucket algorithm.
Java rate limiting library based on token-bucket algorithm. - bucket4j/bucket4j
Visit Site

GitHub - bucket4j/bucket4j: Java rate limiting library based on token-bucket algorithm.

GitHub - bucket4j/bucket4j: Java rate limiting library based on token-bucket algorithm.

Java rate-limiting library based on token-bucket algorithm.

Licence

Get dependency

The Bucket4j is distributed through Maven Central:

Java 17 dependency
<!-- For java 17+ -->
<dependency>
  <groupId>com.bucket4j</groupId>
  <artifactId>bucket4j_jdk17-core</artifactId>
  <version>8.14.0</version>
</dependency>
Java 11 dependency
<!-- For java 11 -->
<dependency>
  <groupId>com.bucket4j</groupId>
  <artifactId>bucket4j_jdk11-core</artifactId>
  <version>8.14.0</version>
</dependency>
Java 8 dependencies

Builds for Java 8 are not distributed through Maven Central. For direct downloading of Bucket4j builds for Java 8 visit this page.

Quick start

import io.github.bucket4j.Bucket;

...
// bucket with capacity 20 tokens and with refilling speed 1 token per each 6 second
private static Bucket bucket = Bucket.builder()
      .addLimit(limit -> limit.capacity(20).refillGreedy(10, Duration.ofMinutes(1)))
      .build();

private void doSomethingProtected() {
   if (bucket.tryConsume(1)) {
      doSomething();    
   } else {
      throw new SomeRateLimitingException();
   }
}

More examples can be found there

Documentation

Bucket4j basic features

  • Absolutely non-compromise precision - Bucket4j does not operate with floats or doubles, all calculation are performed in the integer arithmetic, this feature protects end users from calculation errors involved by rounding.
  • Effective implementation in terms of concurrency:
    • Bucket4j is good scalable for multi-threading case it by defaults uses lock-free implementation.
    • In same time, library provides different concurrency strategies that can be chosen when default lock-free strategy is not desired.
  • Effective API in terms of garbage collector footprint: Bucket4j API tries to use primitive types as much as it is possible in order to avoid boxing and other types of floating garbage.
  • Pluggable listener API that allows to implement monitoring and logging.
  • Rich diagnostic API that allows to investigate internal state.
  • Rich configuration management - configuration of the bucket can be changed on fly

Bucket4j distributed features

In additional to basic features described above, Bucket4j provides ability to implement rate-limiting in cluster of JVMs:

  • Bucket4j out of the box supports any GRID solution which compatible with JCache API (JSR 107) specification.
  • Bucket4j provides the framework that allows to quickly build integration with your own persistent technology like RDMS or a key-value storage.
  • For clustered usage scenarios Bucket4j supports asynchronous API that extremely matters when going to distribute world, because asynchronous API allows avoiding blocking your application threads each time when you need to execute Network request.

Spring boot starter

Bucket4j is not a framework, it is a library, with Bucket4j you need to write a code to achive your goals. For generic use-cases, try to look at powerfull Spring Boot Starter for Bucket4j, that allows you to set access limits on your API effortlessly. Its key advantage lies in the configuration via properties or yaml files, eliminating the need for manual code authoring.

Supported JCache compatible(or similar) back-ends

In addition to local in-memory buckets, the Bucket4j supports clustered usage scenario on top of following back-ends:

Back-end Async supported Flexible per-entry expiration Optimized serialization Thin-client support Documentation link
JCache API (JSR 107) No No No No bucket4j-jcache
Hazelcast Yes Yes Yes No bucket4j-hazelcast
Apache Ignite Yes No n/a Yes bucket4j-ignite
Inifinispan Yes Yes Yes No bucket4j-infinispan
Oracle Coherence Yes Yes Yes No bucket4j-coherence

Redis back-ends

Back-end Async supported Redis cluster supported Documentation link
Redis/Redisson Yes Yes bucket4j-redis/Redisson
Redis/Jedis No Yes bucket4j-redis/Jedis
Redis/Lettuce Yes Yes bucket4j-redis/Lettuce

JDBC back-ends

Back-end Documentation link
MySQL bucket4j-mysql
PostgreSQL bucket4j-postgresql
Oracle bucket4j-oracle
Microsoft SQL Server bucket4j-mssql
MariaDB bucket4j-mariadb
DB2 bucket4j-db2

Local caches support

Sometimes you are having deal with bucket per key scenarios but distributed synchronization is unnecessary, for example where request stickiness is provided by a load balancer, or other use-cases where stickiness can be achieved by the application itself, for example, Kafka consumer. For such scenarios Bucket4j provides support for following list of local caching libraries:

Back-end Documentation link
Caffeine bucket4j-caffeine

Third-party integrations

Back-end Project page
Datomic Database clj-bucket4j-datomic

Bucket4j Backward compatibility policy

Have a question?

Feel free to ask via:

License

Copyright 2015-2024 Vladimir Bukhtoyarov Licensed under the Apache Software License, Version 2.0: http://www.apache.org/licenses/LICENSE-2.0.

More Resources
to explore the angular.

mail [email protected] to add your project or resources here 🔥.

Related Articles
to learn about angular.

FAQ's
to learn more about Angular JS.

mail [email protected] to add more queries here 🔍.

More Sites
to check out once you're finished browsing here.

0x3d
https://www.0x3d.site/
0x3d is designed for aggregating information.
NodeJS
https://nodejs.0x3d.site/
NodeJS Online Directory
Cross Platform
https://cross-platform.0x3d.site/
Cross Platform Online Directory
Open Source
https://open-source.0x3d.site/
Open Source Online Directory
Analytics
https://analytics.0x3d.site/
Analytics Online Directory
JavaScript
https://javascript.0x3d.site/
JavaScript Online Directory
GoLang
https://golang.0x3d.site/
GoLang Online Directory
Python
https://python.0x3d.site/
Python Online Directory
Swift
https://swift.0x3d.site/
Swift Online Directory
Rust
https://rust.0x3d.site/
Rust Online Directory
Scala
https://scala.0x3d.site/
Scala Online Directory
Ruby
https://ruby.0x3d.site/
Ruby Online Directory
Clojure
https://clojure.0x3d.site/
Clojure Online Directory
Elixir
https://elixir.0x3d.site/
Elixir Online Directory
Elm
https://elm.0x3d.site/
Elm Online Directory
Lua
https://lua.0x3d.site/
Lua Online Directory
C Programming
https://c-programming.0x3d.site/
C Programming Online Directory
C++ Programming
https://cpp-programming.0x3d.site/
C++ Programming Online Directory
R Programming
https://r-programming.0x3d.site/
R Programming Online Directory
Perl
https://perl.0x3d.site/
Perl Online Directory
Java
https://java.0x3d.site/
Java Online Directory
Kotlin
https://kotlin.0x3d.site/
Kotlin Online Directory
PHP
https://php.0x3d.site/
PHP Online Directory
React JS
https://react.0x3d.site/
React JS Online Directory
Angular
https://angular.0x3d.site/
Angular JS Online Directory