Skip to content

yookue/rate-limiter-spring-boot-starter

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Rate Limiter Spring Boot Starter

Spring Boot application integrates rate limitation quickly, to prevent too frequent accesses.

Quickstart

  • Import dependencies
    <dependency>
        <groupId>com.yookue.springstarter</groupId>
        <artifactId>rate-limiter-spring-boot-starter</artifactId>
        <version>LATEST</version>
    </dependency>

By default, this starter will auto take effect, you can turn it off by spring.rate-limiter.enabled = false

  • Configure Spring Boot application.yml with prefix spring.rate-limiter (Optional)
spring:
    rate-limiter:
        denied-html-url: '/error/rate-limited'
        denied-rest-url: '/error/rate-limited'
        storage-type: 'redis'
        name-prefix: "${spring.application.name}:limiter:"
        throws-exception: false
  • Annotate your (non-static) method with @RateLimited annotation, done!

The keyType attribute of the annotation, is the limitation ways, supports

  • IP address

  • session

  • username

  • This starter needs to save the limitation data to somewhere, currently is

    • redis

Document

Requirement

  • jdk 17+

License

This project is under the Apache License 2.0

See the NOTICE.txt file for required notices and attributions.

Donation

You like this package? Then donate to Yookue to support the development.

Website