Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for Method level @RateLimiting annoation #250

Closed
MarcGiffing opened this issue Mar 7, 2024 · 1 comment · Fixed by #251
Closed

Support for Method level @RateLimiting annoation #250

MarcGiffing opened this issue Mar 7, 2024 · 1 comment · Fixed by #251
Milestone

Comments

@MarcGiffing
Copy link
Owner

MarcGiffing commented Mar 7, 2024

The idea is to support rate limiting on method level. First you have to provide a configuration separately from the filter configuration. You have to give it a name to reference it in the annotation. You can define the rate-limit part like in the filter.

bucket4j:
  enabled: true
  methods:
  - name: no_admin_limiter
    cache-name: buckets
    rate-limit:
      cache-key: 1
      execute-condition: true
      bandwidths:
        - capacity: 1
          refill-capacity: 1
          time: 30
          unit: seconds
          initial-capacity: 1
          refill-speed: interval

You can override the rate-limit properties. You can also reference the variables in the condition checks.

    @RateLimiting(name = "no_admin_limiter",  executeCondition = "#myParamName neq 'admin'")
      public void execute(String myParamName) {
          log.info("Method with Param {} executed", myParamName);
      }

It's under development. Any suggestions are welcome.

@MarcGiffing MarcGiffing linked a pull request Mar 7, 2024 that will close this issue
@MarcGiffing MarcGiffing added this to the 0.12.0 milestone Mar 11, 2024
MarcGiffing added a commit that referenced this issue Mar 11, 2024
@Colory
Copy link

Colory commented Apr 5, 2024

springboot 3.1.x need this

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants