当前位置:网站首页>Treatment of idempotency
Treatment of idempotency
2022-04-23 15:39:00 【dengk2013】
What is idempotency ? Sending an interface call and sending the same interface message multiple times can get the result that is consistent with the expectation
If there is an interface that provides salary increase , If you call add... Once 500 Yuan , If you don't control the problem of idempotency ,
Keep calling the interface , Then the employee's salary has been increasing
// Inquire about 1 Employee No
Employee employee = employeeService.selectById(1);
// Update salary
employee.setSalary(employee.getSalary() + incrSalary);
// Execute UPDATE statement
employeeService.update(employee)
What's the problem? ? Right , Every time you resend a request 1 No. salary will +500, Idempotency is destroyed
How to solve ? The traditional method is to add pre judgment to the code , That is, by adding a flag and salary increase time
if(! The employee has been paid && Raise time +6 Months < Current system time )
{
Carry out salary adjustment
}
What's wrong with ? There are too many areas for pre judgment , If you don't pay attention, you'll miss This technical problem should not be a factor that interferes with programmers writing business code
We need a non intrusive idempotent solution Building idempotent tables is our general solution Let the brothers concentrate on writing CRUD That's it
advantage : The background service has no code intrusion , No need to modify business logic
shortcoming : The foreground application should be transformed for idempotence Increased architecture complexity , Additional deployment is required Nginx、Redis
版权声明
本文为[dengk2013]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204231537380036.html
边栏推荐
- KNN, kmeans and GMM
- Go语言数组,指针,结构体
- [backtrader source code analysis 18] Yahoo Py code comments and analysis (boring, interested in the code, you can refer to)
- Go语言切片,范围,集合
- 通过 PDO ODBC 将 PHP 连接到 MySQL
- Connect PHP to MySQL via PDO ODBC
- Mysql database explanation (IX)
- IronPDF for .NET 2022.4.5455
- 群体智能自主作业智慧农场项目启动及实施方案论证会议
- 山寨版归并【上】
猜你喜欢
Detailed explanation of redirection and request forwarding
导入地址表分析(根据库文件名求出:导入函数数量、函数序号、函数名称)
2022年中国数字科技专题分析
Cookie&Session
[leetcode daily question] install fence
大型互联网为什么禁止ip直连
推荐搜索 常用评价指标
Special analysis of China's digital technology in 2022
mysql乐观锁解决并发冲突
Wechat applet customer service access to send and receive messages
随机推荐
网站压测工具Apache-ab,webbench,Apache-Jemeter
为啥禁用外键约束
[leetcode daily question] install fence
G007-HWY-CC-ESTOR-03 华为 Dorado V6 存储仿真器搭建
计算某字符出现次数
【递归之数的拆分】n分k,限定范围的拆分
携号转网最大赢家是中国电信,为何人们嫌弃中国移动和中国联通?
Connectez PHP à MySQL via aodbc
PHP classes and objects
Pytorch中named_parameters、named_children、named_modules函数
Recommended search common evaluation indicators
通過 PDO ODBC 將 PHP 連接到 MySQL
服务器中毒了怎么办?服务器怎么防止病毒入侵?
移动金融(自用)
Connect PHP to MySQL via PDO ODBC
Basic concepts of website construction and management
utils.DeprecatedIn35 因升级可能取消,该如何办
时序模型:长短期记忆网络(LSTM)
KNN, kmeans and GMM
自主作业智慧农场创新论坛