当前位置:网站首页>Redis message queue repeated consumption
Redis message queue repeated consumption
2022-06-12 13:06:00 【Li_ XiaoJin】
A recent problem , Make a note of .
The last article said SpringBoot+Redis Implement simple publishing / subscribe
What happened
The short message module in our current project is adopted Redis For message queuing , The reason is that recently, some applications reported that when sending text messages , Occasionally, it is sent twice .
After investigation , It does exist , This is the processing before our research and development. The lock will be deleted after sending a text message , In this way, if the network fluctuates , It will be sent twice .
The details are as follows , We have two examples , Each instance is subscribed to topic, Each consumer will be notified when sending , Each instance acquires the lock , And then send a text message ; It was like this , After the producer sends , Consumers begin to consume The time consumed by the first instance is 18:10:024, Then do business processing , The completion time of sending SMS is 18:10:056( Check the time through the log ), Handled quickly , It can be processed in tens of milliseconds , Then delete the lock . The second example consumes time 18:10:244, At this time, the first instance has been processed , And remove the lock , So when the second instance tries to acquire the lock, it will succeed directly , Then the business processing is carried out , The completion time of resending the second SMS is 18:10:268. Therefore, it will occasionally send twice .
Find the problem and fix it , The main solution is to fail to acquire the lock for the second time .
Here, we modify it to obtain the lock after the business processing is completed , Do not delete locks directly , Instead, let it lapse over time , In this way, other instances will not succeed in obtaining locks during this period , Even if it is handled quickly for the first time , It will not be processed by two consumption .
Here we set the expiration time to 1 minute , Later, it can be adjusted according to the business situation .
summary
This time we also know , When doing business , It is not only necessary to lock and unlock , Also consider various situations ; When processing message queues , Repeated consumption is a common problem , This is an experience .
Copyright: use Creative Commons signature 4.0 International license agreement to license Links:https://lixj.fun/archives/redis The problem of repeated consumption
边栏推荐
- Stm32f1 and stm32cubeide programming examples - device driver -eeprom-at24c256 driver
- Installation of pagoda
- leetcode 47. Permutations II full permutations II (medium)
- JVM 运行时参数
- Known as the next generation monitoring system! See how awesome it is
- 一行代码实现shell if else逻辑
- Chrome debugging tool
- LeetCode滑动窗口刷题总结
- Successful job hopping Ali, advanced learning
- Microsoft Word tutorial, how to insert a header or footer in word?
猜你喜欢

IC chip scheme fs4062b for lithium battery charging with 5V boost to 12.6V

Vant tab bar + pull-up loading + pull-down refresh demo van tabs + van pull refresh + van list demo

torch_geometric message passing network

成功跳槽阿里,进阶学习

It is enough to read this article. Web Chinese development

How to adapt the page size when iframe is embedded in a web page

Freshman girls' nonsense programming is popular! Those who understand programming are tied with Q after reading

"New continent" of mobile application going to sea

Pytorch官方Faster R-CNN源代码解析(一)——特征提取

What is the function tag? Article to understand its role and its best practices
随机推荐
itkMultiResolutionImageRegistrationMethod
ITK multi-stage registration
C语言【23道】经典面试题【下】
Jacobian matrix IK of manipulator
How to adapt the page size when iframe is embedded in a web page
Array -- fancy traversal technique of two-dimensional array
Vant tab bar + pull-up loading + pull-down refresh demo van tabs + van pull refresh + van list demo
Semantic segmentation with pytorch
import torch_geometric 加载一些常见数据集
Index changes of seed points in ITK original image after ROI and downsampling
Mui login database improvement and Ajax asynchronous processing [mui+flask+mongodb+hbuilderx]
Embedded driver design
Binary tree (program)
一行代码实现shell if else逻辑
Binary tree (construction)
Install MySQL database independently on Debian 10
【刷题篇】抽牌获胜的概率
单向环形链表实现约瑟夫环
Experience and learning path of introductory deep learning and machine learning
Pytorch官方Faster R-CNN源代码解析(一)——特征提取