当前位置:网站首页>幂等性的处理
幂等性的处理
2022-04-23 15:37:00 【dengk2013】
幂等性是啥? 发一次接口调用与发多次相同的接口消息都能得到与预期相符的结果
假如有个接口是提供加工资的接口,如果调用一次加500块钱,如果不控制幂等性的问题,
一直调用接口,那么该员工的工资一直在加
//查询1号员工数据
Employee employee = employeeService.selectById(1);
//更新工资
employee.setSalary(employee.getSalary() + incrSalary);
//执行更新语句
employeeService.update(employee)
有什么问题? 对喽,每重发一次请求1号工资就会+500,幂等性就被破坏了
怎么解决? 传统办法是代码增加前置判断,也就是通过增加一个标志位和加薪时间
if(!员工已调薪 && 加薪时间+6个月<系统当前时间)
{
进行调薪
}
有什么不好? 需要前置判断的地方太多了,一不留神就漏了 这种技术问题不应该成为干扰程序员写业务代码的因素
我们需要一种无侵入的幂等解决方案 构建幂等表是我们的通用解决方案 让兄弟们专心的写CRUD就好啦
优点:后台服务无代码侵入,无需修改业务逻辑
缺点:前台应用要针对幂等进行改造 架构复杂度增加,需要额外部署Nginx、Redis
版权声明
本文为[dengk2013]所创,转载请带上原文链接,感谢
https://blog.csdn.net/u012222011/article/details/124352895
边栏推荐
猜你喜欢
CVPR 2022 优质论文分享
For examination
Detailed explanation of kubernetes (XI) -- label and label selector
Openstack theoretical knowledge
What if the server is poisoned? How does the server prevent virus intrusion?
G007-HWY-CC-ESTOR-03 华为 Dorado V6 存储仿真器搭建
Detailed explanation of MySQL connection query
Differential privacy (background)
Multitimer V2 reconstruction version | an infinitely scalable software timer
Mobile finance (for personal use)
随机推荐
群体智能自主作业智慧农场项目启动及实施方案论证会议
Explanation of redis database (III) redis data type
Educational Codeforces Round 127 A-E题解
Recommended search common evaluation indicators
Elk installation
Use of common pod controller of kubernetes
北京某信护网蓝队面试题目
电脑怎么重装系统后显示器没有信号了
自动化测试框架常见类型▏自动化测试就交给软件测评机构
Mysql database explanation (IX)
Detailed explanation of redirection and request forwarding
如果conda找不到想要安装的库怎么办PackagesNotFoundError: The following packages are not available from current
Sword finger offer (2) -- for Huawei
redis-shake 使用中遇到的错误整理
网站建设与管理的基本概念
What is CNAs certification? What are the software evaluation centers recognized by CNAs?
KNN, kmeans and GMM
计算某字符出现次数
APISIX jwt-auth 插件存在错误响应中泄露信息的风险公告(CVE-2022-29266)
Functions (Part I)