企业网站外包建设,买模板做的网站表单数据在哪里看,公司网站建设费用入账,网站私信界面简介call-limit提供接口限流、防刷的功能#xff0c;插件基于spring开发#xff0c;在应用应用的任何一个逻辑层皆可使用(web、service、dao)#xff0c;插件支持单机应用下的限流和分布式应用的限流(分布式应用限流需要依赖redis)#xff0c;在简单业务场景下插件可为大家…简介call-limit提供接口限流、防刷的功能插件基于spring开发在应用应用的任何一个逻辑层皆可使用(web、service、dao)插件支持单机应用下的限流和分布式应用的限流(分布式应用限流需要依赖redis)在简单业务场景下插件可为大家提供轻量无逻辑侵入的限流、防刷的支持。maven坐标top.xiemingmincall-limit1.0.1-SNAPSHOT目前SNAPSHOT版本只能发布到第三方仓库如需使用请在maven配置中增加第三方repositorysonatype-nexus-snapshotsSonatype Nexus Snapshotshttps://oss.sonatype.org/content/repositories/snapshots/用法在项目中添加插件maven依赖在spring xml配置中配置相关的bean单机场景xmlns:xsihttp://www.w3.org/2001/XMLSchema-instancexmlns:mmhttp://www.xiemingmin.top/schema/mmxsi:schemaLocationhttp://www.springframework.org/schema/beanshttp://www.springframework.org/schema/beans/spring-beans.xsdhttp://www.xiemingmin.top/schema/mmhttp://www.xiemingmin.top/schema/mm.xsd分布式场景xmlns:xsihttp://www.w3.org/2001/XMLSchema-instancexmlns:mmhttp://www.xiemingmin.top/schema/mmxsi:schemaLocationhttp://www.springframework.org/schema/beanshttp://www.springframework.org/schema/beans/spring-beans.xsdhttp://www.xiemingmin.top/schema/mmhttp://www.xiemingmin.top/schema/mm.xsd3.实现用户信息接口(top.xiemingmin.call.limit.intf.UserInfoSupport)返回每个请求线程的用户唯一标识可使用请求的客户端ip插件中会调用次接口判断是否同一用户的请求。ps可将用户信息放入ThreadLocal在此方法中直接取值package com.xiemingmin.service;import org.springframework.stereotype.Service;import top.xiemingmin.call.limit.intf.UserInfoSupport;Servicepublic class UserInfoServiceImpl implements UserInfoSupport {Overridepublic String currentUserKey() {return LoginContext.getUserId();}}4.在需要限流或防刷的方法上添加top.xiemingmin.call.limit.annotation.CallLimit注解参数说明time单位时间内值允许调用1次timeUnit时间单位onLimitException: 触发限流抛出的异常如下配置表示30秒内值允许调用一次GetMapping(/getPerson/{name})CallLimit(time 30, timeUnit TimeUnit.SECONDS)public Result getPerson(PathVariable String name){return personService.findPersonByName(name);}效果第一次调用(成功)调用成功第二次调用(被限制)被限制