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?