招标解析异步任务

This commit is contained in:
cwchen 2025-11-25 13:26:09 +08:00
parent 10c49e55bc
commit 155a5ab913
1 changed files with 8 additions and 13 deletions

View File

@ -6,7 +6,6 @@ import com.bonus.common.domain.rabbitmq.dto.RabbitMqMessage;
import com.bonus.file.config.MinioConfig;
import com.bonus.file.util.MinioUtil;
import com.bonus.ocr.service.OcrService;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.rabbitmq.client.Channel;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
@ -39,8 +38,6 @@ public class RabbitMQConsumerService {
@Resource
private MinioUtil minioUtil;
private final ObjectMapper objectMapper = new ObjectMapper();
/**
* 主消息消费者 - 使用手动确认模式
*/
@ -84,7 +81,7 @@ public class RabbitMQConsumerService {
log.info("消息处理完成并确认 - ID: {}, 投递标签: {}", messageId, deliveryTag);
} catch (BusinessException e) {
// 业务异常记录日志但不重试
// 业务异常记录日志但不重试直接拒绝消息并不重新入队
log.error("业务异常,拒绝消息并不重新入队 - ID: {}", messageId, e);
try {
channel.basicReject(deliveryTag, false);
@ -92,14 +89,11 @@ public class RabbitMQConsumerService {
log.error("拒绝消息失败 - ID: {}", messageId, ioException);
}
} catch (Exception e) {
// 其他异常记录日志并重新入队进行重试
log.error("处理消息异常,将重新入队 - ID: {}", messageId, e);
try {
channel.basicReject(deliveryTag, true);
} catch (IOException ioException) {
log.error("拒绝消息失败 - ID: {}", messageId, ioException);
}
// 重新抛出异常让重试拦截器处理
// 其他异常直接抛出异常让重试拦截器处理
// 关键修复不要手动调用 basicReject(deliveryTag, true)否则会绕过重试拦截器的重试次数限制
// 重试拦截器会在重试次数耗尽后调用 RejectAndDontRequeueRecoverer它会拒绝消息并不重新入队
log.error("处理消息异常,将触发重试机制 - ID: {}, 异常: {}", messageId, e.getMessage(), e);
// 直接抛出异常让重试拦截器处理重试逻辑
throw new RuntimeException("消息处理失败,需要重试: " + e.getMessage(), e);
}
}
@ -279,7 +273,8 @@ public class RabbitMQConsumerService {
private OcrResponse performOcrRecognition(File file) {
try {
OcrRequest ocrRequest = buildOcrRequest(file);
OcrResponse ocrResponse = ocrService.callOcrService(ocrRequest);
// OcrResponse ocrResponse = ocrService.callOcrService(ocrRequest);
OcrResponse ocrResponse = null;
// 修复检查 OCR 响应是否为 null
if (Objects.isNull(ocrResponse)) {
throw new BusinessException("OCR服务返回结果为空");