0

I found Guava RateLimiter for implementing limitation for GET/Post requests. I called the class in controller and called the object for some get classes. But nothing happens. I can still request get methods multiple times in a second.

@Controller
public class Controller {

    final RateLimiter rateLimiter = RateLimiter.create(1.0);

@RequestMapping(value = "/user/{customId}", method = RequestMethod.GET, headers = "Accept=application/json")
    @ResponseBody
    public List<User> showUser(@PathVariable("customId") String customId) {
        rateLimiter.acquire();
        return services.findUserByCustomId(customId);
    }

}

Should I do something more, or is there any other solution for rate limiting?

Eniss
  • 975
  • 2
  • 20
  • 40
  • you can create your own rateLimiter by using `Handler Interceptor` and counting requests by checking IP addresses of each request with a counter (if small no of users then do in JVM or use a database to track count of request per specified time for larger traffic). – S Jayesh May 10 '17 at 13:45
  • Have you tried making the `RateLimiter` static? I know the controller should be a singleton if wired by spring. But it may be worth a try. – dpr May 11 '17 at 06:24

0 Answers0