From 66cc4be5114df959c152231b91d33eaddea097c6 Mon Sep 17 00:00:00 2001 From: xiao-fajia <1665375861@qq.com> Date: Mon, 26 Aug 2024 21:25:59 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BB=A3=E7=A0=81=E8=A1=A5=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../rescue/utils/RedissonDelayQueue.java | 20 +++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/dl-module-rescue/src/main/java/cn/iocoder/yudao/module/rescue/utils/RedissonDelayQueue.java b/dl-module-rescue/src/main/java/cn/iocoder/yudao/module/rescue/utils/RedissonDelayQueue.java index addc677f..0771ed55 100644 --- a/dl-module-rescue/src/main/java/cn/iocoder/yudao/module/rescue/utils/RedissonDelayQueue.java +++ b/dl-module-rescue/src/main/java/cn/iocoder/yudao/module/rescue/utils/RedissonDelayQueue.java @@ -10,6 +10,7 @@ import lombok.extern.slf4j.Slf4j; import org.redisson.api.RBlockingQueue; import org.redisson.api.RDelayedQueue; import org.redisson.api.RMap; +import org.redisson.api.RedissonClient; import org.springframework.stereotype.Component; import javax.annotation.PostConstruct; @@ -30,27 +31,34 @@ import java.util.concurrent.TimeUnit; @RequiredArgsConstructor public class RedissonDelayQueue { - // 注入 Redisson 提供的延迟队列接口 @Resource + private RedissonClient redissonClient; + + // 注入 Redisson 提供的延迟队列接口 private RDelayedQueue delayedQueue; // 注入 Redisson 提供的阻塞队列接口 - @Resource private RBlockingQueue blockingQueue; + // 任务索引,用于快速查找任务 + private RMap taskIndex; + @Resource private ISysAnnouncementService announcementService; - // 任务索引,用于快速查找任务 - @Resource - private RMap taskIndex; - /** * 初始化方法,在 Spring 容器加载后自动执行。 * 创建一个固定大小的线程池来消费阻塞队列中的任务。 */ @PostConstruct public void init() { + + blockingQueue = redissonClient.getBlockingQueue("RESCUE_QUEUE"); + + delayedQueue = redissonClient.getDelayedQueue(blockingQueue); + + taskIndex = redissonClient.getMap("RESCUE_INDEX"); + // 创建一个单线程的线程池 ExecutorService executorService = Executors.newFixedThreadPool(1);