|
@@ -14,6 +14,7 @@ import com.fdkankan.modeling.service.IBuildLogService;
|
|
import com.fdkankan.rabbitmq.bean.BuildSceneCallMessage;
|
|
import com.fdkankan.rabbitmq.bean.BuildSceneCallMessage;
|
|
import com.fdkankan.rabbitmq.bean.BuildSceneResultMqMessage;
|
|
import com.fdkankan.rabbitmq.bean.BuildSceneResultMqMessage;
|
|
import com.fdkankan.rabbitmq.util.RabbitMqProducer;
|
|
import com.fdkankan.rabbitmq.util.RabbitMqProducer;
|
|
|
|
+import com.fdkankan.redis.util.RedisLockUtil;
|
|
import com.fdkankan.redis.util.RedisUtil;
|
|
import com.fdkankan.redis.util.RedisUtil;
|
|
import com.rabbitmq.client.Channel;
|
|
import com.rabbitmq.client.Channel;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
@@ -57,6 +58,9 @@ public class RabbitMqListener {
|
|
private RedisUtil redisUtil;
|
|
private RedisUtil redisUtil;
|
|
|
|
|
|
@Autowired
|
|
@Autowired
|
|
|
|
+ private RedisLockUtil redisLockUtil;
|
|
|
|
+
|
|
|
|
+ @Autowired
|
|
private RabbitMqProducer rabbitMqProducer;
|
|
private RabbitMqProducer rabbitMqProducer;
|
|
|
|
|
|
@Autowired
|
|
@Autowired
|
|
@@ -232,7 +236,10 @@ public class RabbitMqListener {
|
|
buildStatus = buildSceneResult.getBuildStatus();
|
|
buildStatus = buildSceneResult.getBuildStatus();
|
|
log.info("服务{} 计算结束:{},计算状态:{}", SysConstants.hostName, buildLog.getSceneNum(),buildStatus.message());
|
|
log.info("服务{} 计算结束:{},计算状态:{}", SysConstants.hostName, buildLog.getSceneNum(),buildStatus.message());
|
|
//释放锁
|
|
//释放锁
|
|
- redisUtil.decr(SysConstants.SCENE_BUILDING + buildLog.getSceneNum(),1);
|
|
|
|
|
|
+ Long decr = redisUtil.decr(SysConstants.SCENE_BUILDING + buildLog.getSceneNum(), 1);
|
|
|
|
+ if (decr.compareTo(1L) < 0) {
|
|
|
|
+ redisUtil.del(SysConstants.SCENE_BUILDING + buildLog.getSceneNum());
|
|
|
|
+ }
|
|
buildLog.setUpdateTime(new Date());
|
|
buildLog.setUpdateTime(new Date());
|
|
buildLogService.updateById(buildLog);
|
|
buildLogService.updateById(buildLog);
|
|
} catch (Exception e) {
|
|
} catch (Exception e) {
|
|
@@ -262,11 +269,9 @@ public class RabbitMqListener {
|
|
|
|
|
|
if(!ObjectUtils.isEmpty(buildLog.getMessageId())){
|
|
if(!ObjectUtils.isEmpty(buildLog.getMessageId())){
|
|
// 设置消息id幂等性,防止消息重复消费
|
|
// 设置消息id幂等性,防止消息重复消费
|
|
- Long messageIdCount = redisUtil.incr(SysConstants.SCENE_BUILDING + buildLog.getMessageId(), 1);
|
|
|
|
- if (messageIdCount.compareTo(1L) == 0) {
|
|
|
|
- redisUtil.expire(key, SysConstants.modelTimeOut);
|
|
|
|
- } else {
|
|
|
|
- log.error("服务:{},消息重复消费:{},重复消费次数:{}", SysConstants.hostName, buildLog.getMessageId(), messageIdCount);
|
|
|
|
|
|
+ boolean lock = redisLockUtil.lock(SysConstants.SCENE_BUILDING + buildLog.getMessageId(), SysConstants.modelTimeOut * 3600);
|
|
|
|
+ if (!lock) {
|
|
|
|
+ log.error("服务:{},消息重复消费:{}", SysConstants.hostName, buildLog.getMessageId());
|
|
throw new BuildException(ModelingBuildStatus.REPEAT);
|
|
throw new BuildException(ModelingBuildStatus.REPEAT);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
@@ -275,7 +280,7 @@ public class RabbitMqListener {
|
|
log.error("服务:{},重复构建:{},构建次数:{}", SysConstants.hostName, buildLog.getSceneNum(),building);
|
|
log.error("服务:{},重复构建:{},构建次数:{}", SysConstants.hostName, buildLog.getSceneNum(),building);
|
|
throw new BuildException(ModelingBuildStatus.REPEAT);
|
|
throw new BuildException(ModelingBuildStatus.REPEAT);
|
|
} else {
|
|
} else {
|
|
- redisUtil.expire(key, SysConstants.modelTimeOut);
|
|
|
|
|
|
+ redisUtil.expire(key, Integer.toUnsignedLong(SysConstants.modelTimeOut * 3600));
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|