-
Notifications
You must be signed in to change notification settings - Fork 279
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
Get actual count of tokens in a Bucket #31
Comments
Yes, it is possible. Before answering, I need to know your usecase, please describe it a little bit. Do you use local or distributed(JCache) bucket? What you plan to do with information about remaining tokens? |
I'm using distributed buckets to rate the limit for API calls. And I would like to set header fields like X-Rate-Limit-Remaining with the remaining tokens. |
There is tricky way which I use for unit testing: Bucket bucket = null;
BucketState snapshot = bucket.createSnapshot();
long availableTokens = snapshot.getAvailableTokens(bucket.getConfiguration().getBandwidths()); But it is not designed to be used for production, and especially will be a performance penalty for distributed case, because createSnapshot performs network request. Your usecase looks reasonable for me, I will add new tryConsume variant, which returns both consumption result and remaining tokens, just wait for a week. |
Great to hear this! Thanks for your great support! |
This issue is tightly related with #35, need to implement both together. |
…ut remaining tokens and time to close deficit
Implemented. "2.1" will be released soon. Example of usage can be found in the bottom of this page. |
Great work! Thanks |
version 2.1.0 has been released |
This is more a question than a issue. Hopefully anyone can help me!
Is it possible to determine the amount of token in a bucket at runtime?
I' ve read the docs but I don't see any possibility to do so?
After
bucket.tryConsume(1)
I need the amount of tokens left in the bucket!The text was updated successfully, but these errors were encountered: