Skip to content

Commit f8ebd2e

Browse files
committed
fix: TxMsg doClear 方法取消参数,方便 xxl-job 执行
1 parent d0ea857 commit f8ebd2e

3 files changed

Lines changed: 17 additions & 8 deletions

File tree

common/plugin/mq/src/main/java/com/github/cadecode/uniboot/common/plugin/mq/handler/AbstractTxMsgHandler.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ public abstract class AbstractTxMsgHandler {
1717

1818
public abstract void doRetry();
1919

20-
public abstract void doClear(Long autoClearInterval);
20+
public abstract void doClear();
2121

2222
public abstract void checkBeforeSend(BaseTxMsg txMsg, MsgOption msgOption);
2323

common/plugin/mq/src/main/java/com/github/cadecode/uniboot/common/plugin/mq/job/TxMsgJobRegister.java

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,17 +29,23 @@ public class TxMsgJobRegister {
2929

3030
@EventListener(ApplicationStartedEvent.class)
3131
public void onApplicationStartedEvent() {
32+
registerRetryJob();
33+
registerAutoClearJob();
34+
}
35+
36+
private void registerRetryJob() {
3237
// 消息定时 retry
33-
log.info("TxMsg task do retry start, {}", txMsgProperties.getEnableRetry());
38+
log.info("TxMsg task retry start, {}", txMsgProperties.getEnableRetry());
3439
if (ObjUtil.equals(txMsgProperties.getEnableRetry(), true)) {
3540
taskScheduler.scheduleWithFixedDelay(txMsgTaskHandler::doRetry, txMsgProperties.getRetryFixDelay());
3641
}
42+
}
3743

44+
private void registerAutoClearJob() {
3845
// 消息定时清理
39-
log.info("TxMsg task do clear start, {}", txMsgProperties.getAutoClear());
40-
if (ObjUtil.equal(txMsgProperties.getAutoClear(), true)) {
41-
taskScheduler.scheduleWithFixedDelay(() -> txMsgTaskHandler.doClear(txMsgProperties.getAutoClearInterval()),
42-
txMsgProperties.getClearFixDelay());
46+
log.info("TxMsg task auto clear start, {}", txMsgProperties.getAutoClear());
47+
if (ObjUtil.equals(txMsgProperties.getAutoClear(), true)) {
48+
taskScheduler.scheduleWithFixedDelay(txMsgTaskHandler::doClear, txMsgProperties.getClearFixDelay());
4349
}
4450
}
4551
}

framework/framework_base/src/main/java/com/github/cadecode/uniboot/framework/base/plugin/handler/MqTxMsgHandler.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import com.github.cadecode.uniboot.common.core.util.AssertUtil;
1111
import com.github.cadecode.uniboot.common.plugin.cache.util.KeyGeneUtil;
1212
import com.github.cadecode.uniboot.common.plugin.cache.util.RedisLockKit;
13+
import com.github.cadecode.uniboot.common.plugin.mq.config.TxMsgProperties;
1314
import com.github.cadecode.uniboot.common.plugin.mq.config.TxMsgProperties.MsgOption;
1415
import com.github.cadecode.uniboot.common.plugin.mq.exception.TxMsgException;
1516
import com.github.cadecode.uniboot.common.plugin.mq.handler.AbstractTxMsgHandler;
@@ -61,6 +62,8 @@ public class MqTxMsgHandler extends AbstractTxMsgHandler {
6162
*/
6263
public static final String DEFAULT_TX_MSG_REPLY_TEXT = "DEFAULT_TX_MSG_REPLY";
6364

65+
private final TxMsgProperties txMsgProperties;
66+
6467
private final RedisLockKit redisLockKit;
6568

6669
private final PlgMqMsgService mqMsgService;
@@ -114,13 +117,13 @@ private boolean updateRetryTime(String txMsgId, int newLeftRetryTimes, Date newN
114117

115118
@XxlJob("MqTxMsgAutoClear")
116119
@Override
117-
public void doClear(Long autoClearInterval) {
120+
public void doClear() {
118121
String lockKey = KeyGeneUtil.lockKey(LOCK_TX_MSG_DO_CLEAR);
119122
try {
120123
redisLockKit.lock(lockKey);
121124
Date currDate = new Date();
122125
// 查找指定时长之前的记录
123-
DateTime lastDate = DateUtil.offset(currDate, DateField.MILLISECOND, -autoClearInterval.intValue());
126+
DateTime lastDate = DateUtil.offset(currDate, DateField.MILLISECOND, -txMsgProperties.getAutoClearInterval().intValue());
124127
List<PlgMqMsg> msgList = mqMsgService.lambdaQuery()
125128
.select(PlgMqMsg::getId)
126129
.le(PlgMqMsg::getCreateTime, lastDate)

0 commit comments

Comments
 (0)