mirror of https://github.com/ZhongFuCheng3y/austin
commit
55e778f798
@ -0,0 +1,22 @@
|
||||
package com.java3y.austin.handler.flowcontrol.annotations;
|
||||
|
||||
import com.java3y.austin.handler.enums.RateLimitStrategy;
|
||||
import java.lang.annotation.Documented;
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
/**
|
||||
* 单机限流注解
|
||||
* Created by TOM
|
||||
* On 2022/7/21 17:03
|
||||
*/
|
||||
@Target({ElementType.TYPE})
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Documented
|
||||
@Service
|
||||
public @interface LocalRateLimit {
|
||||
RateLimitStrategy rateLimitStrategy() default RateLimitStrategy.REQUEST_RATE_LIMIT;
|
||||
}
|
@ -0,0 +1,28 @@
|
||||
package com.java3y.austin.handler.flowcontrol.impl;
|
||||
|
||||
import com.google.common.util.concurrent.RateLimiter;
|
||||
import com.java3y.austin.common.domain.TaskInfo;
|
||||
import com.java3y.austin.handler.enums.RateLimitStrategy;
|
||||
import com.java3y.austin.handler.flowcontrol.FlowControlParam;
|
||||
import com.java3y.austin.handler.flowcontrol.FlowControlService;
|
||||
import com.java3y.austin.handler.flowcontrol.annotations.LocalRateLimit;
|
||||
|
||||
/**
|
||||
* Created by TOM
|
||||
* On 2022/7/21 17:05
|
||||
*/
|
||||
@LocalRateLimit(rateLimitStrategy = RateLimitStrategy.REQUEST_RATE_LIMIT)
|
||||
public class RequestRateLimitService implements FlowControlService {
|
||||
|
||||
/**
|
||||
* 根据渠道进行流量控制
|
||||
*
|
||||
* @param taskInfo
|
||||
* @param flowControlParam
|
||||
*/
|
||||
@Override
|
||||
public Double flowControl(TaskInfo taskInfo, FlowControlParam flowControlParam) {
|
||||
RateLimiter rateLimiter = flowControlParam.getRateLimiter();
|
||||
return rateLimiter.acquire(1);
|
||||
}
|
||||
}
|
@ -0,0 +1,28 @@
|
||||
package com.java3y.austin.handler.flowcontrol.impl;
|
||||
|
||||
import com.google.common.util.concurrent.RateLimiter;
|
||||
import com.java3y.austin.common.domain.TaskInfo;
|
||||
import com.java3y.austin.handler.enums.RateLimitStrategy;
|
||||
import com.java3y.austin.handler.flowcontrol.FlowControlParam;
|
||||
import com.java3y.austin.handler.flowcontrol.FlowControlService;
|
||||
import com.java3y.austin.handler.flowcontrol.annotations.LocalRateLimit;
|
||||
|
||||
/**
|
||||
* Created by TOM
|
||||
* On 2022/7/21 17:14
|
||||
*/
|
||||
@LocalRateLimit(rateLimitStrategy = RateLimitStrategy.SEND_USER_NUM_RATE_LIMIT)
|
||||
public class SendUserNumRateLimitService implements FlowControlService {
|
||||
|
||||
/**
|
||||
* 根据渠道进行流量控制
|
||||
*
|
||||
* @param taskInfo
|
||||
* @param flowControlParam
|
||||
*/
|
||||
@Override
|
||||
public Double flowControl(TaskInfo taskInfo, FlowControlParam flowControlParam) {
|
||||
RateLimiter rateLimiter = flowControlParam.getRateLimiter();
|
||||
return rateLimiter.acquire(taskInfo.getReceiver().size());
|
||||
}
|
||||
}
|
Loading…
Reference in new issue