|
|
|
@ -18,6 +18,7 @@ import java.util.Set; |
|
|
|
@Slf4j |
|
|
|
@Component |
|
|
|
public class OrderAsyncProducer { |
|
|
|
private static final long CLOUD_PRINT_INITIAL_DELAY_MILLIS = 5 * 1000L; |
|
|
|
|
|
|
|
@Autowired |
|
|
|
private RabbitTemplate rabbitTemplate; |
|
|
|
@ -54,25 +55,20 @@ public class OrderAsyncProducer { |
|
|
|
} |
|
|
|
|
|
|
|
public void sendCloudPrint(String orderId, String printReason) { |
|
|
|
sendCloudPrint(orderId, printReason, 0); |
|
|
|
sendCloudPrintDelay(orderId, printReason, 0, CLOUD_PRINT_INITIAL_DELAY_MILLIS, "云打印初始延迟任务"); |
|
|
|
} |
|
|
|
|
|
|
|
public void sendCloudPrint(String orderId, String printReason, int retryCount) { |
|
|
|
Map<String, Object> msg = new HashMap<>(); |
|
|
|
msg.put("orderId", orderId); |
|
|
|
msg.put("printReason", printReason); |
|
|
|
msg.put("retryCount", retryCount); |
|
|
|
msg.put("timestamp", System.currentTimeMillis()); |
|
|
|
rabbitTemplate.convertAndSend(OrderQueueConfig.ORDER_DIRECT_EXCHANGE, OrderQueueConfig.ASYNC_PRINT_ROUTING, JSON.toJSONString(msg)); |
|
|
|
log.info("【云打印MQ】已发出云打印任务, orderId={}, reason={}, retryCount={}", orderId, printReason, retryCount); |
|
|
|
sendCloudPrintDelay(orderId, printReason, retryCount, 0, "云打印任务"); |
|
|
|
} |
|
|
|
|
|
|
|
public void sendCloudPrintDelayRetry(String orderId, String printReason, int retryCount, long delayMillis) { |
|
|
|
private void sendCloudPrintDelay(String orderId, String printReason, int retryCount, long delayMillis, String logPrefix) { |
|
|
|
Map<String, Object> msg = new HashMap<>(); |
|
|
|
msg.put("orderId", orderId); |
|
|
|
msg.put("printReason", printReason); |
|
|
|
msg.put("retryCount", retryCount); |
|
|
|
msg.put("timestamp", System.currentTimeMillis()); |
|
|
|
if (delayMillis > 0) { |
|
|
|
rabbitTemplate.convertAndSend(OrderQueueConfig.ORDER_DIRECT_EXCHANGE, |
|
|
|
OrderQueueConfig.ASYNC_PRINT_RETRY_DELAY_ROUTING, |
|
|
|
JSON.toJSONString(msg), |
|
|
|
@ -80,8 +76,15 @@ public class OrderAsyncProducer { |
|
|
|
message.getMessageProperties().setExpiration(String.valueOf(delayMillis)); |
|
|
|
return message; |
|
|
|
}); |
|
|
|
log.info("【云打印MQ】已发出云打印延迟重试任务, orderId={}, reason={}, retryCount={}, delayMillis={}", |
|
|
|
orderId, printReason, retryCount, delayMillis); |
|
|
|
} else { |
|
|
|
rabbitTemplate.convertAndSend(OrderQueueConfig.ORDER_DIRECT_EXCHANGE, OrderQueueConfig.ASYNC_PRINT_ROUTING, JSON.toJSONString(msg)); |
|
|
|
} |
|
|
|
log.info("【云打印MQ】已发出{}, orderId={}, reason={}, retryCount={}, delayMillis={}", |
|
|
|
logPrefix, orderId, printReason, retryCount, delayMillis); |
|
|
|
} |
|
|
|
|
|
|
|
public void sendCloudPrintDelayRetry(String orderId, String printReason, int retryCount, long delayMillis) { |
|
|
|
sendCloudPrintDelay(orderId, printReason, retryCount, delayMillis, "云打印延迟重试任务"); |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
|