当前位置:网站首页>Record the abnormal task status caused by an MQ concurrent consumption
Record the abnormal task status caused by an MQ concurrent consumption
2022-06-21 23:07:00 【sms technonogy】
background :
In the project, there is a task of mass sending SMS ( for example 1 Secondary send 1W Short message ), The system will get the information of each SMS in the task MQ Send SMS concurrently . The default status of the task is Not sent ( Status code :0), You need to send the first text message in this batch of tasks , Change the task status to In sending ( Status code :1), Change the status to at the end of task sending Send complete ( Status code :2).
Code processing logic :
The pseudocode is as follows , adopt redis Record how many messages have been sent by the current task , If it's the first one , Update the task status to being sent , If the number of sent tasks is equal to the total number of tasks , Update the status to send complete
Long sendCount = redisTemplate.opsForValue().increment(taskId);
if(sendCount == 1){
// The update status is sending update task set status = 1 where task_id = #{taskId}
}
if(sendCount >= totalCount){
// The update status is send complete update task set status = 2 where task_id = #{taskId}
}The code says , Two tasks were simply tested , No problem found
problem :
When actually running online , Discover that some tasks are always In sending state , There are no exceptions in the error log , Later, I checked the log and found that there would be problems when the concurrency was high , Suppose this task has 2 Short message , The following conditions will cause the task to be in the sending status all the time :
| step | The first text message | Article 2 SMS | Task status |
| Long sendCount = redisTemplate.opsForValue().increment(taskId); | perform | Not sent | |
| Long sendCount = redisTemplate.opsForValue().increment(taskId); | perform | Not sent | |
| sendCount == 1 | false | Not sent | |
| sendCount >= totalCount | true | Send complete | |
| sendCount == 1 | true | In sending | |
| sendCount >= totalCount | false | Not updated |
namely , The second message is to judge first if(sendCount >= totalCount) by true, Change the task status to Send complete , Judge the first message again if(sendCount == 1) by true, Change task status from Send complete become In sending , But the first text message judge if(sendCount >= totalCount) by false, Will not change the task status to Send complete , So the task status will always be In sending .
Optimize :
Modification is actually very simple , You only need to update the SMS status to being sent , Add a judgment , The task status is not 2 Can only be updated when .
Long sendCount = redisTemplate.opsForValue().increment(taskId);
if(sendCount == 1){
// The update status is sending update task set status = 1 where task_id = #{taskId} and status <> 2
}
if(sendCount >= totalCount){
// The update status is send complete update task set status = 2 where task_id = #{taskId}
}边栏推荐
- WPF tablet
- C # error: the exception of the task is not observed by waiting for the task or accessing the exception attribute of the task. As a result, the finalizer thread re threw an unobserved exception.
- 2022-06-21:golang选择题,以下golang代码输出什么?A:3;B:4;C:100;D:编译失败。 package main import (
- Readjustment of move protocol beta to expand the total prize pool
- uniapp微信授权之 有个别用户 无法正常授权
- Specific methods of using cloud development to realize wechat payment
- uniapp在解决谷歌浏览器跨域问题,在谷歌浏览器运行
- plt修改横纵坐标颜色
- 并查集练习题1:朋友圈
- 1016. 子串能表示从 1 到 N 数字的二进制串
猜你喜欢

Design and implementation of spark offline development framework

使用云开发实现微信支付的具体方法

4. esp8266 displays DHT11 temperature and humidity parameters in real time through OLED

Electronic bidding procurement mall system: optimize traditional procurement business and speed up enterprise digital upgrading

WPF 依赖属性

About LG (n!) Asymptotically compact supremum of

Professional font design editor glyphs 3

Matlab2020a使用App Designer如何导出exe

KVM虚拟机救援模式修改root密码 —— 筑梦之路

在商业智能BI开发过程中,什么问题的挑战性最大?
随机推荐
C# WindowFromPoint在64位程序中无效
UWP Dispatcher用法
uniapp版本更新 热更新及自然更新
UWP 阴影效果
.bmp图片的文件头解析
libra白皮书
MVN deploy bat files for multiple modules
WPF 路由
语音信号处理之多阶MFCC提取(matlab)
postgis 如何用米制单位 buffer
力扣75:颜色分流
啊啊啊啊啊啊啊
Set -set
解决笔记本电脑(i)某个键的字母按不出来
WPF routing
WPF ComboBox设置选项与反显
If you spend 200W to buy traffic, it is better to start at 0 cost and make an independent station with high private domain operation income!
WPF thread manipulation UI problem
danfoss丹佛斯变频器维修VLT5000/VLT6000/VLT8000
An error prone to appear when MATLAB is doing image processing: to improve the operation speed, use the pre declared zero matrix to store image data