开发者

How to limit the quota in jersey for every client

I've already built the web service API by jersey framework. Now I want to limit the quotas for every client. For example: - one client can only make less than 10000 requests in one day. - o开发者_开发知识库ne client can only make less than 10 requests per second. so on and so forth.

Should I store these information in the table of the database? But if I do that, will it cost a lot time to handle these requests because I have to update the table.

I am looking forward to other efficient ways to solve these problem. Because this is my first time to do this kind of job, hope somebody can give me some advise to in these problems. Thanks~!


Without information about how you define a client its difficult to answer this question. However one method would be to filter all incoming requests using a ContainerRequestFilter

Then at that level you can define what a client is, and log all accesses by that client to your Jersey application. Perhaps by incrementing a value in a DataStructure or a value in a database. Then having a cron job flushes that data every 24 hours.

Ideally you would want to store the data in an in-memory data structure, since the data is transient, it won't grow to a large size and will be deleted in a short period of time anyway. However this will become an issue if you ever scale up to multiple machines, or multiple instances on a single machine.

Without more information from you I can't really give any more information

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜