/** * 限流 */ @Component public class RateLimiterFilter extends ZuulFilter { //1秒钟100个令牌 private static final RateLimiter RATE_LIMITER = RateLimiter.create(100); @Override public String filterType() { return PRE_TYPE; } @Override public int filterOrder() { return SERVLET_DETECTION_FILTER_ORDER -1; } @Override public boolean shouldFilter() { return true; } @Override public Object run() throws ZuulException { if(!RATE_LIMITER.tryAcquire()){ throw new RateLimitException(); } return null; } }
作者:Work Hard Work Smart
出处:http://www.cnblogs.com/linlf03/
欢迎任何形式的转载,未经作者同意,请保留此段声明!