2026-06-30 24681c81c09022f584a57006f2534b5f74723414
yudao-framework/yudao-spring-boot-starter-mq/src/main/java/cn/iocoder/yudao/framework/mq/redis/core/job/RedisPendingMessageResendJob.java
@@ -23,7 +23,9 @@
@AllArgsConstructor
public class RedisPendingMessageResendJob {
    private static final String LOCK_KEY = "redis:stream:pending-message-resend:lock";
    public static final String DEFAULT_RESEND_LOCK_KEY = "redis:stream:pending-message-resend:lock";
    public static final String IOT_RESEND_LOCK_KEY = "redis:stream:pending-message-resend:lock:iot";
    /**
     * 消息超时时间,默认 5 分钟
@@ -36,22 +38,26 @@
    private final List<AbstractRedisStreamMessageListener<?>> listeners;
    private final RedisMQTemplate redisTemplate;
    private final RedissonClient redissonClient;
    private final String resendLockKey;
    /**
     * 一分钟执行一次,这里选择每分钟的 35 秒执行,是为了避免整点任务过多的问题
     */
    @Scheduled(cron = "35 * * * * ?")
    public void messageResend() {
        RLock lock = redissonClient.getLock(LOCK_KEY);
        // 尝试加锁
        RLock lock = redissonClient.getLock(resendLockKey);
        if (lock.tryLock()) {
            try {
                execute();
            } catch (Exception ex) {
                log.error("[messageResend][执行异常]", ex);
                log.error("[messageResend][执行异常][lockKey={}]", resendLockKey, ex);
            } finally {
                lock.unlock();
                if (lock.isHeldByCurrentThread()) {
                    lock.unlock();
                }
            }
        } else {
            log.debug("[messageResend][未获取到锁,跳过本轮][lockKey={}]", resendLockKey);
        }
    }