当前位置:网站首页>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
边栏推荐
- itk::SymmetricForcesDemonsRegistrationFilter
- 创新实训(十)高级界面美化
- 【云原生 | Kubernetes篇】Ingress案例实战
- OpenMAX (OMX)框架
- C语言【23道】经典面试题【下】
- Structure matérielle du système embarqué - introduction du Conseil de développement embarqué basé sur arm
- 看完这一篇就够了,web中文开发
- leetcode 47. Permutations II full permutations II (medium)
- Getting to know blob objects
- 成功跳槽阿里,进阶学习
猜你喜欢
随机推荐
Mui login database improvement and Ajax asynchronous processing [mui+flask+mongodb+hbuilderx]
R语言可视化分面图、假设检验、多变量分组t检验、可视化多变量分组分面条形图(faceting bar plot)并添加显著性水平、添加抖动数据点(jitter points)
Structure matérielle du système embarqué - introduction du Conseil de développement embarqué basé sur arm
Further understanding of the network
STM32F1与STM32CubeIDE编程实例-设备驱动-DHT11温度温度传感器驱动
嵌入式系统概述3-嵌入式系统的开发流程和学习基础、方法
import torch_geometric 加载一些常见数据集
itkMultiResolutionImageRegistrationMethod
镜像扫描工具预研
What is the function tag? Article to understand its role and its best practices
unittest框架
Vant tab bar + pull-up loading + pull-down refresh demo van tabs + van pull refresh + van list demo
list和dict的应用
Detect whether the vector has an intersection
Build an embedded system software development environment - build a cross compilation environment
Freshman girls' nonsense programming is popular! Those who understand programming are tied with Q after reading
Install MySQL database independently on Debian 10
【云原生 | Kubernetes篇】深入了解Ingress
Eight misunderstandings are broken one by one (2): poor performance? Fewer applications? You worry a lot about the cloud!
提升管道效率:你需要知道如何识别CI/CD管道中的主要障碍









