2024-04-26 15:30:30 +08:00
|
|
|
package com.sf.vertx.handle;
|
|
|
|
|
|
|
|
import io.vertx.codegen.annotations.VertxGen;
|
|
|
|
import io.vertx.core.Handler;
|
|
|
|
import io.vertx.core.json.JsonObject;
|
|
|
|
import io.vertx.ext.web.RoutingContext;
|
|
|
|
|
|
|
|
/***
|
|
|
|
* 限流熔断, redis存储
|
|
|
|
* @author xy
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
@VertxGen
|
|
|
|
public interface RateLimitHandler extends Handler<RoutingContext> {
|
|
|
|
|
2024-04-28 21:25:41 +08:00
|
|
|
static RateLimitHandler create(String instance) {
|
2024-04-26 15:30:30 +08:00
|
|
|
switch (instance) {
|
|
|
|
case "redis":
|
|
|
|
RedisRateLimiter redisRateLimiter = new RedisRateLimiter();
|
2024-04-28 21:25:41 +08:00
|
|
|
return new RateLimitHandlerRedisImpl(redisRateLimiter);
|
2024-04-26 15:30:30 +08:00
|
|
|
default:
|
|
|
|
// 本地缓存
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|