当前位置: 首页 > news >正文

深圳营销型网站建设设计公司做网站高校视频

深圳营销型网站建设设计公司,做网站高校视频,大疆网站建设,兖州网站建设文章目录 依赖注解aophelperTest 免责声明#xff1a;本人无意侵权#xff0c;奈何找不到原文作者#xff0c;也找不到网址#xff0c;于是自己记录一下#xff0c;如果有侵权之嫌#xff0c;请联系我删除文章 依赖 !-- https://mvnrepository.com/artifact/com.goo… 文章目录 依赖注解aophelperTest 免责声明本人无意侵权奈何找不到原文作者也找不到网址于是自己记录一下如果有侵权之嫌请联系我删除文章 依赖 !-- https://mvnrepository.com/artifact/com.google.guava/guava --dependencygroupIdcom.google.guava/groupIdartifactIdguava/artifactIdversion32.1.3-jre/version/dependency注解 import java.lang.annotation.ElementType; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; import java.lang.annotation.Target;Target(value ElementType.METHOD) Retention(value RetentionPolicy.RUNTIME) public interface RateConfigAnno {String limitType();double limitCount() default 5d; }aop import cn.hutool.core.thread.ThreadUtil; import com.alibaba.fastjson2.JSONObject; import com.google.common.util.concurrent.RateLimiter; import com.tjbchtyw.tjflowcontrol.annocation.RateConfigAnno; import com.tjbchtyw.tjflowcontrol.helper.RateLimitHelper; import jakarta.servlet.ServletOutputStream; import jakarta.servlet.http.HttpServletResponse; import org.aspectj.lang.JoinPoint; import org.aspectj.lang.annotation.Aspect; import org.aspectj.lang.annotation.Before; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.stereotype.Component; import org.springframework.web.context.request.RequestContextHolder; import org.springframework.web.context.request.ServletRequestAttributes;import java.io.IOException; import java.lang.reflect.Method; import java.nio.charset.StandardCharsets; import java.util.Objects;Aspect Component public class GuavaLimitAop {private static final Logger logger LoggerFactory.getLogger(GuavaLimitAop.class);Before(annotation(com.tjbchtyw.tjflowcontrol.annocation.RateConfigAnno))public void limit(JoinPoint joinPoint) {//1、获取当前的调用方法Method currentMethod getCurrentMethod(joinPoint);if (Objects.isNull(currentMethod)) {return;}//2、从方法注解定义上获取限流的类型String limitType currentMethod.getAnnotation(RateConfigAnno.class).limitType();double limitCount currentMethod.getAnnotation(RateConfigAnno.class).limitCount();//使用guava的令牌桶算法获取一个令牌获取不到先等待RateLimiter rateLimiter RateLimitHelper.getRateLimiter(limitType, limitCount);// boolean b true;boolean pass rateLimiter.tryAcquire();if (pass) {System.out.println(获取到令牌);}else {//重试 仅测试用 有优化方案可以放在评论区for (int i 0; i 5; i) {ThreadUtil.safeSleep(1000);System.out.println(第 (i 1) 次获取令牌);if(rateLimiter.tryAcquire()) break;if(i 4){System.out.println(在第 (i 1) 次后未获取到令牌 开始限流);HttpServletResponse resp ((ServletRequestAttributes)RequestContextHolder.getRequestAttributes()).getResponse();JSONObject jsonObjectnew JSONObject();jsonObject.put(success,false);jsonObject.put(msg,限流中);try {output(resp, jsonObject.toJSONString());}catch (Exception e){logger.error(error,e:{},e);}}}}}private Method getCurrentMethod(JoinPoint joinPoint) {Method[] methods joinPoint.getTarget().getClass().getMethods();Method target null;for (Method method : methods) {if (method.getName().equals(joinPoint.getSignature().getName())) {target method;break;}}return target;}public void output(HttpServletResponse response, String msg) throws IOException {response.setContentType(application/json;charsetUTF-8);ServletOutputStream outputStream null;try {outputStream response.getOutputStream();outputStream.write(msg.getBytes(StandardCharsets.UTF_8));} catch (IOException e) {e.printStackTrace();} finally {outputStream.flush();outputStream.close();}} }helper import com.google.common.util.concurrent.RateLimiter;import java.util.HashMap; import java.util.Map;public class RateLimitHelper {private RateLimitHelper(){}private static final MapString,RateLimiter rateMap new HashMap();public static RateLimiter getRateLimiter(String limitType, double limitCount ){RateLimiter rateLimiter rateMap.get(limitType);if(rateLimiter null){rateLimiter RateLimiter.create(limitCount);rateMap.put(limitType,rateLimiter);}return rateLimiter;}}Test RestControllerTag(name 测试Controller, description 这是描述)RequestMapping(/pred-api)public class FlowController {AutowiredFlowContext flowContext;PostMapping(/pdf/test)//Count 限制次数RateConfigAnno(limitType makePdf,limitCount 15)Operation(summary 限流接口)public String flowCont(Parameter(name pdfParam, description 参数对象,type标识执行不同的策略) RequestBody Param Param) {return test;}}
http://www.hkea.cn/news/14273276/

相关文章:

  • 网站建设服务代理商建筑人才网官网平台
  • 西安seo网站排名wordpress 招聘模板
  • 做ppt模仿网站wordpress游戏资讯
  • 工程网站开发定制做网站开发
  • 教材资源网站建设怎么seo关键词优化排名
  • 网站建设市场调研行业网站如何推广
  • php class 做网站什么网站免费可以做app
  • 江西省美丽乡村建设公布网站哪里有做效果图的
  • 杭州汇咖网站建设有限公司怎么样佛山企业如何建网站
  • 西安社动网站建设岳池县网站建设
  • 网站中的知识 视频从哪里来的有哪些做短租的网站好
  • 做淘宝客为什么要建网站网站建设基本流程备案
  • 电商网站如何生成app前端网页模板
  • 有自己的网站如何做淘宝客彩票网站怎么做的
  • 上传网站图片不显示vue可以做pc端网站
  • 怎么用阿里的域名 做网站thinkphp做的商城网站分销平台
  • 网页模板快速建站工具做静态网站d
  • 公司网站首页设计构想WordPress输入密码可见
  • 建设银行首页 网站中国企业500强招聘
  • 北京家居网站建设金沙网站怎么做代理
  • 网站改版建设方案平度网站建设ld4
  • 创建网站收费在东莞建公司网站
  • 做网站的动态图片wordpress主题屏蔽更新
  • 河源手机网站制作做网站前需要做什么准备
  • 全国建筑网站微信引流推广 方法
  • 晋江企业网站制作建站是什么专业
  • 小鱼在线网站建设学校网站建设哪家好
  • 游戏秒玩网站免费推广网址
  • js写的网站怎么做seo短链接制作
  • 《美食天下》网站的建设甘肃网站建设项目