|
@@ -3,6 +3,7 @@ package com.qmth.teachcloud.task.config;
|
|
|
import com.alibaba.fastjson.JSON;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
import com.google.gson.Gson;
|
|
|
+import com.qmth.boot.redis.uid.RedisMachineService;
|
|
|
import com.qmth.distributed.print.business.templete.execute.AsyncCreatePdfTempleteService;
|
|
|
import com.qmth.teachcloud.common.bean.dto.MqDto;
|
|
|
import com.qmth.teachcloud.common.contant.SystemConstant;
|
|
@@ -22,9 +23,7 @@ import org.springframework.stereotype.Component;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
import java.time.Duration;
|
|
|
-import java.util.HashMap;
|
|
|
-import java.util.Map;
|
|
|
-import java.util.Objects;
|
|
|
+import java.util.*;
|
|
|
import java.util.concurrent.atomic.AtomicInteger;
|
|
|
|
|
|
/**
|
|
@@ -47,11 +46,19 @@ public class RedisMessageListener implements MessageListener {
|
|
|
@Resource
|
|
|
AsyncCreatePdfTempleteService asyncCreatePdfTempleteService;
|
|
|
|
|
|
+ @Resource
|
|
|
+ RedisMachineService redisMachineService;
|
|
|
+
|
|
|
@Override
|
|
|
public void onMessage(Message message, byte[] bytes) {
|
|
|
-// log.info("SystemConstant.REDIS_MQ_LOCK start:{}", SystemConstant.REDIS_MQ_LOCK);
|
|
|
- if (SystemConstant.REDIS_MQ_LOCK) {
|
|
|
- return;
|
|
|
+ if (Objects.nonNull(redisUtil.get(SystemConstant.CURRENT_TASK_MACHINE_ID))) {
|
|
|
+ Set<Integer> set = (Set<Integer>) redisUtil.getKeyPatterns(SystemConstant.TASK_MACHINE_ID_LIKE);
|
|
|
+ if (Objects.nonNull(set) && set.size() > 1) {
|
|
|
+ int currentMachineId = (int) redisUtil.get(SystemConstant.CURRENT_TASK_MACHINE_ID);
|
|
|
+ if (currentMachineId == redisMachineService.getMachineId()) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
MqDto mqDto = null;
|
|
|
AtomicInteger integer = new AtomicInteger(0);
|
|
@@ -82,7 +89,7 @@ public class RedisMessageListener implements MessageListener {
|
|
|
finalMap.computeIfAbsent(k, v1 -> finalV);
|
|
|
});
|
|
|
asyncCreatePdfTempleteService.createPdf(finalMap, null);
|
|
|
- SystemConstant.REDIS_MQ_LOCK = true;
|
|
|
+ redisUtil.set(SystemConstant.CURRENT_TASK_MACHINE_ID, redisMachineService.getMachineId());
|
|
|
redisUtil.delete(SystemConstant.MQ_TOPIC_BUFFER_LIST, mqDto.getId());
|
|
|
break;
|
|
|
} else {
|
|
@@ -109,7 +116,6 @@ public class RedisMessageListener implements MessageListener {
|
|
|
|| mqDto.getAck().intValue() == SystemConstant.POSION_ACK_TYPE)) {
|
|
|
redisUtil.releaseLock(SystemConstant.REDIS_LOCK_MQ_PREFIX + mqDto.getId());
|
|
|
}
|
|
|
-// log.info("SystemConstant.REDIS_MQ_LOCK end:{}", SystemConstant.REDIS_MQ_LOCK);
|
|
|
}
|
|
|
}
|
|
|
}
|