11
This commit is contained in:
1 parent
675d5552d4
commit
3a416e2686
1 file changed
+12
-9
+12
-9
@@ -10,7 +10,7 @@ import org.springframework.boot.ApplicationRunner;
|
||||
import org.springframework.data.redis.core.StringRedisTemplate;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.time.Duration;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
|
||||
@@ -65,15 +65,18 @@ public class ShangyouCallbackQueueWorker implements ApplicationRunner {
|
||||
while (running.get()) {
|
||||
try {
|
||||
// BRPOP 多 key:先高优(订单状态)再普通;阻塞期间新到的高优也会被优先弹出
|
||||
List<String> popped = redisTemplate.opsForList().rightPop(
|
||||
List.of(ShangyouHotelApi.REDIS_CALLBACK_QUEUE_HIGH,
|
||||
ShangyouHotelApi.REDIS_CALLBACK_QUEUE),
|
||||
Duration.ofSeconds(5));
|
||||
if (popped == null || popped.size() < 2 || popped.get(1) == null) {
|
||||
continue;
|
||||
// ListOperations 没有多 key 阻塞弹出,走底层连接命令 bRPop(秒, keys...),返回 [key, value]
|
||||
String taskId = redisTemplate.execute(connection -> {
|
||||
List<byte[]> popped = connection.listCommands().bRPop(5,
|
||||
ShangyouHotelApi.REDIS_CALLBACK_QUEUE_HIGH.getBytes(StandardCharsets.UTF_8),
|
||||
ShangyouHotelApi.REDIS_CALLBACK_QUEUE.getBytes(StandardCharsets.UTF_8));
|
||||
return popped == null || popped.size() < 2 ? null
|
||||
: new String(popped.get(1), StandardCharsets.UTF_8);
|
||||
});
|
||||
if (taskId != null) {
|
||||
taskId = taskId.trim();
|
||||
}
|
||||
String taskId = popped.get(1).trim();
|
||||
if (taskId.isBlank() || "null".equalsIgnoreCase(taskId)) {
|
||||
if (taskId == null || taskId.isBlank() || "null".equalsIgnoreCase(taskId)) {
|
||||
continue;
|
||||
}
|
||||
Long id;
|
||||
|
||||
Reference in new issue
Block a user