|
@@ -13,47 +13,47 @@ import lombok.NonNull;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
|
|
|
/**
|
|
|
- * 分布式队列处理工具类
|
|
|
+ * Redis队列处理工具类
|
|
|
*
|
|
|
* @author Woody
|
|
|
* @date 2025/4/28
|
|
|
*/
|
|
|
@Slf4j
|
|
|
-public final class Queues {
|
|
|
+public final class RedisQueues {
|
|
|
/**
|
|
|
- * 队列名称/实例映射表
|
|
|
+ * 普通队列名称/实例映射表
|
|
|
*/
|
|
|
@SuppressWarnings("rawtypes")
|
|
|
- private static final Map<String, RedisQueue> REDIS_QUEUE_INSTANCES = Maps.newConcurrentMap();
|
|
|
+ private static final Map<String, NormalRedisQueue> NORMAL_REDIS_QUEUE_INSTANCES = Maps.newConcurrentMap();
|
|
|
|
|
|
/**
|
|
|
- * 延时队列名称/实例映射表
|
|
|
+ * 优先级队列名称/实例映射表
|
|
|
*/
|
|
|
@SuppressWarnings("rawtypes")
|
|
|
- private static final Map<String, DelayRedisQueue> DELAY_REDIS_QUEUE_INSTANCES = Maps.newConcurrentMap();
|
|
|
+ private static final Map<String, PriorityRedisQueue> PRIORITY_REDIS_QUEUE_INSTANCES = Maps.newConcurrentMap();
|
|
|
|
|
|
/**
|
|
|
- * 优先级队列名称/实例映射表
|
|
|
+ * 延时队列名称/实例映射表
|
|
|
*/
|
|
|
@SuppressWarnings("rawtypes")
|
|
|
- private static final Map<String, PriorityRedisQueue> PRIORITY_REDIS_QUEUE_INSTANCES = Maps.newConcurrentMap();
|
|
|
+ private static final Map<String, DelayRedisQueue> DELAY_REDIS_QUEUE_INSTANCES = Maps.newConcurrentMap();
|
|
|
|
|
|
- private Queues() {
|
|
|
+ private RedisQueues() {
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * 获取消息队列
|
|
|
+ * 获取普通消息队列
|
|
|
*
|
|
|
* @param name 队列名称
|
|
|
* @param <E> 消息类型
|
|
|
* @return 队列实例
|
|
|
*/
|
|
|
- public static <E> RedisQueue<E> getRedisQueue(@NonNull String name) {
|
|
|
- return getRedisQueue(name, RedisQueue::new);
|
|
|
+ public static <E> NormalRedisQueue<E> getNormalRedisQueue(@NonNull String name) {
|
|
|
+ return getNormalRedisQueue(name, NormalRedisQueue::new);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * 获取消息队列
|
|
|
+ * 获取普通消息队列
|
|
|
*
|
|
|
* @param name 队列名称
|
|
|
* @param builder 队列构建函数
|
|
@@ -61,25 +61,25 @@ public final class Queues {
|
|
|
* @return 队列实例
|
|
|
*/
|
|
|
@SuppressWarnings("unchecked")
|
|
|
- public static <E> RedisQueue<E> getRedisQueue(@NonNull String name,
|
|
|
- @NonNull Function<String, RedisQueue<E>> builder) {
|
|
|
- RedisQueue<E> queue = REDIS_QUEUE_INSTANCES.get(name);
|
|
|
- return queue == null ? REDIS_QUEUE_INSTANCES.computeIfAbsent(name, builder) : queue;
|
|
|
+ public static <E> NormalRedisQueue<E> getNormalRedisQueue(@NonNull String name,
|
|
|
+ @NonNull Function<String, NormalRedisQueue<E>> builder) {
|
|
|
+ NormalRedisQueue<E> queue = NORMAL_REDIS_QUEUE_INSTANCES.get(name);
|
|
|
+ return queue == null ? NORMAL_REDIS_QUEUE_INSTANCES.computeIfAbsent(name, builder) : queue;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * 获取延时消息队列
|
|
|
+ * 获取优先级消息队列
|
|
|
*
|
|
|
* @param name 队列名称
|
|
|
* @param <E> 消息类型
|
|
|
* @return 队列实例
|
|
|
*/
|
|
|
- public static <E> DelayRedisQueue<E> getDelayRedisQueue(@NonNull String name) {
|
|
|
- return getDelayRedisQueue(name, DelayRedisQueue::new);
|
|
|
+ public static <E> PriorityRedisQueue<E> getPriorityRedisQueue(@NonNull String name) {
|
|
|
+ return getPriorityRedisQueue(name, PriorityRedisQueue::new);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * 获取延时消息队列
|
|
|
+ * 获取优先级消息队列
|
|
|
*
|
|
|
* @param name 队列名称
|
|
|
* @param builder 队列构建函数
|
|
@@ -87,25 +87,25 @@ public final class Queues {
|
|
|
* @return 队列实例
|
|
|
*/
|
|
|
@SuppressWarnings("unchecked")
|
|
|
- public static <E> DelayRedisQueue<E> getDelayRedisQueue(@NonNull String name,
|
|
|
- @NonNull Function<String, DelayRedisQueue<E>> builder) {
|
|
|
- DelayRedisQueue<E> queue = DELAY_REDIS_QUEUE_INSTANCES.get(name);
|
|
|
- return queue == null ? DELAY_REDIS_QUEUE_INSTANCES.computeIfAbsent(name, builder) : queue;
|
|
|
+ public static <E> PriorityRedisQueue<E> getPriorityRedisQueue(@NonNull String name,
|
|
|
+ @NonNull Function<String, PriorityRedisQueue<E>> builder) {
|
|
|
+ PriorityRedisQueue<E> queue = PRIORITY_REDIS_QUEUE_INSTANCES.get(name);
|
|
|
+ return queue == null ? PRIORITY_REDIS_QUEUE_INSTANCES.computeIfAbsent(name, builder) : queue;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * 获取优先级消息队列
|
|
|
+ * 获取延时消息队列
|
|
|
*
|
|
|
* @param name 队列名称
|
|
|
* @param <E> 消息类型
|
|
|
* @return 队列实例
|
|
|
*/
|
|
|
- public static <E> PriorityRedisQueue<E> getPriorityRedisQueue(@NonNull String name) {
|
|
|
- return getPriorityRedisQueue(name, PriorityRedisQueue::new);
|
|
|
+ public static <E> DelayRedisQueue<E> getDelayRedisQueue(@NonNull String name) {
|
|
|
+ return getDelayRedisQueue(name, DelayRedisQueue::new);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * 获取优先级消息队列
|
|
|
+ * 获取延时消息队列
|
|
|
*
|
|
|
* @param name 队列名称
|
|
|
* @param builder 队列构建函数
|
|
@@ -113,10 +113,10 @@ public final class Queues {
|
|
|
* @return 队列实例
|
|
|
*/
|
|
|
@SuppressWarnings("unchecked")
|
|
|
- public static <E> PriorityRedisQueue<E> getPriorityRedisQueue(@NonNull String name,
|
|
|
- @NonNull Function<String, PriorityRedisQueue<E>> builder) {
|
|
|
- PriorityRedisQueue<E> queue = PRIORITY_REDIS_QUEUE_INSTANCES.get(name);
|
|
|
- return queue == null ? PRIORITY_REDIS_QUEUE_INSTANCES.computeIfAbsent(name, builder) : queue;
|
|
|
+ public static <E> DelayRedisQueue<E> getDelayRedisQueue(@NonNull String name,
|
|
|
+ @NonNull Function<String, DelayRedisQueue<E>> builder) {
|
|
|
+ DelayRedisQueue<E> queue = DELAY_REDIS_QUEUE_INSTANCES.get(name);
|
|
|
+ return queue == null ? DELAY_REDIS_QUEUE_INSTANCES.computeIfAbsent(name, builder) : queue;
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -126,7 +126,7 @@ public final class Queues {
|
|
|
* @param consumer 消息消费者
|
|
|
* @param <T> 消息类型
|
|
|
*/
|
|
|
- public static <T> void consume(@NonNull RedisQueue<T> queue, @NonNull Consumer<T> consumer) {
|
|
|
+ public static <T> void consume(@NonNull NormalRedisQueue<T> queue, @NonNull Consumer<T> consumer) {
|
|
|
ThreadUtils.run(() -> {
|
|
|
while (!Thread.currentThread().isInterrupted()) {
|
|
|
// 拉取消息
|