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

网站开发要学什么深圳外贸seo

网站开发要学什么,深圳外贸seo,建设网站怎么判断是电脑还是手机,前海网站建设文章目录 依赖注解aophelperTest 免责声明&#xff1a;本人无意侵权&#xff0c;奈何找不到原文作者&#xff0c;也找不到网址&#xff0c;于是自己记录一下&#xff0c;如果有侵权之嫌&#xff0c;请联系我删除文章 依赖 <!-- https://mvnrepository.com/artifact/com.goo…

文章目录

  • 依赖
  • 注解
  • aop
  • helper
  • Test

免责声明:本人无意侵权,奈何找不到原文作者,也找不到网址,于是自己记录一下,如果有侵权之嫌,请联系我删除文章

依赖

  <!-- https://mvnrepository.com/artifact/com.google.guava/guava --><dependency><groupId>com.google.guava</groupId><artifactId>guava</artifactId><version>32.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 jsonObject=new 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;charset=UTF-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 Map<String,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

@RestController@Tag(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.tj-hxxt.cn/news/28530.html

相关文章:

  • 做婚恋网站的翻译好吗杭州专业seo
  • 十大网文平台搜狗排名优化工具
  • 品牌营销型网站建设平台推广是做什么
  • wordpress 表单 插件seo网站快速排名外包
  • 长沙优化网站分析长沙网站制作推广
  • 做网站获流量百度怎么精准搜关键词
  • 利用php做网站教程什么是软文
  • 菏泽网站建设效果网络域名综合查询
  • 建设网站必备的三大要素域名解析在线查询
  • 建网站广州百度交易平台
  • 南宁网站建设怎么样百度提问
  • 企业网站酷站刷关键词排名seo
  • 网站怎么做链接跳转免费seo在线工具
  • 为企业建网站过时了朝阳区seo技术
  • 上海做网站公司做网站的公司有哪些长沙网站推广公司
  • 做软件网站手机优化管家
  • 用dw个人网站怎么做温州seo结算
  • 学校网站管理与建设知名网络推广
  • 建立一个网站需要多少钱费用游戏推广是什么工作
  • 太原住房和城乡建设部网站深圳今日重大新闻
  • 前端和网站部署做网站的最常用的搜索引擎有哪些
  • 济南建设网站的公司哪家好seo建站收费地震
  • 李沧做网站百度竞价推广开户内容
  • 自己做的网站怎么置顶品牌整合营销方案
  • 网站建设理念网络营销和电子商务区别
  • 有ip怎么用自己的主机做网站热点新闻事件今日最新
  • 如何用word做网站教育培训机构加盟十大排名
  • 做网站公司项目的流程seo专业培训机构
  • 做网站的专业叫什么太原seo霸屏
  • 靠谱的网络建站服务热线产品网络推广深圳