handle out of time

This commit is contained in:
Cauchy
2023-10-10 16:24:03 +08:00
parent 6ab08f7a29
commit f3df8b326b
14 changed files with 636 additions and 495 deletions

View File

@@ -0,0 +1,59 @@
package com.peanut.config;
/**
* @Description: 常量类
* @Author: Cauchy
* @CreateTime: 2023/10/10
*/
public class Constants {
/**
* 订单状态 - 待支付
*/
public static final String ORDER_STATUS_TO_BE_PAID = "0";
/**
* 订单状态 - 待发货
*/
public static final String ORDER_STATUS_TO_BE_SHIPPED = "1";
/**
* 订单状态 - 已发货
*/
public static final String ORDER_STATUS_SHIPPED = "2";
/**
* 订单状态 - 已发货
*/
public static final String ORDER_STATUS_FINISHED = "3";
/**
* 订单状态 - 交易失败
*/
public static final String ORDER_STATUS_FAIL = "4";
/**
* 订单状态 - 订单超时
*/
public static final String ORDER_STATUS_OUT_OF_TIME = "5";
/**
* 支付方式 - 微信支付
*/
public static final String PAYMENT_METHOD_WECHAT_PAY = "1";
/**
* 支付方式 - 支付宝 - 支付宝支付
*/
public static final String PAYMENT_METHOD_ALI_PAY = "2";
/**
* 支付方式 - IOS 内购
*/
public static final String PAYMENT_METHOD_IOS = "3";
/**
* 支付方式 - 虚拟币支付
*/
public static final String PAYMENT_METHOD_VIRTUAL = "4";
/**
* 购买方式 - 直接购买
*/
public static final String BUY_TYPE_REDIRECT = "0";
/**
* 购买方式 - 购物车
*/
public static final String BUY_TYPE_CART = "1";
}

View File

@@ -11,6 +11,7 @@ import java.util.Map;
/**
* RabbitMq 延时队列实现
*
* @author AnYuan
*/
@@ -41,17 +42,31 @@ public class DelayQueueConfig {
public static final String DEAD_LETTER_QUEUE_ROUTING_KEY = "delay.queue.deadLetter.delay_10s.routingKey";
public static final String DEAD_LETTER_QUEUE = "delay.queue.deadLetter.queue";
/**
* 订单待支付交换机
*/
public static final String ORDER_TO_BE_PAY_EXCHANGE = "order_to_be_pay_exchange";
public static final String ORDER_TO_BE_PAY_ROUTING_KEY = "order_to_be_pay_routingKey";
public static final String ORDER_TO_BE_PAY_QUEUE = "order_to_be_pay_queue";
/**
* 订单取消队列
*/
public static final String ORDER_CANCEL_DEAD_LETTER_EXCHANGE = "order_cancel_dead_letter_exchange";
public static final String ORDER_CANCEL_DEAD_LETTER_ROUTING_KEY = "order_cancel_dead_letter_routingKey";
public static final String ORDER_CANCEL_DEAD_LETTER_QUEUE = "order_cancel_dead_letter_queue";
/**
* 快递队列
*/
public static final String FMS_QUEUE= "fms.queue";
public static final String FMS_QUEUE = "fms.queue";
public static final String FMS_EXCHANGE = "fms.exchange";
public static final String FMS_ROUTING_KEY = "fms.routing.key";
/**
* 声明 死信交换机
*
* @return deadLetterExchange
*/
@Bean
@@ -62,11 +77,12 @@ public class DelayQueueConfig {
/**
* 声明 订单交换机
*
* @return deadLetterExchange
*/
@Bean
public Exchange orderEventExchange() {
return new TopicExchange(ORDER_EVENT_EXCHANGE,true,false);
return new TopicExchange(ORDER_EVENT_EXCHANGE, true, false);
}
@@ -82,7 +98,7 @@ public class DelayQueueConfig {
map.put("x-message-ttl", 60000);
Queue queue = new Queue(ORDER_DELAY_QUEUE, true, false, false,map);
Queue queue = new Queue(ORDER_DELAY_QUEUE, true, false, false, map);
return queue;
}
@@ -97,9 +113,9 @@ public class DelayQueueConfig {
}
/**
* 声明 死信队列 用于接收死信消息
*
* @return deadLetterQueueA
*/
@Bean
@@ -108,7 +124,8 @@ public class DelayQueueConfig {
}
/**
* 将 死信队列 绑定到死信交换机上
* 将 死信队列 绑定到死信交换机上
*
* @return deadLetterBindingA
*/
@Bean
@@ -121,6 +138,7 @@ public class DelayQueueConfig {
/**
* 声明 延时交换机
*
* @return delayExchange
*/
@Bean
@@ -130,6 +148,7 @@ public class DelayQueueConfig {
/**
* 将 延时队列 绑定参数
*
* @return Queue
*/
@Bean
@@ -146,6 +165,7 @@ public class DelayQueueConfig {
/**
* 将 延时队列 绑定到延时交换机上面
*
* @return delayBindingA
*/
@Bean
@@ -158,28 +178,62 @@ public class DelayQueueConfig {
@Bean
public Binding orderCreateOrderBingding(){
return new Binding(ORDER_DELAY_QUEUE, Binding.DestinationType.QUEUE,ORDER_EVENT_EXCHANGE,"order.create.order",null);
public Binding orderCreateOrderBingding() {
return new Binding(ORDER_DELAY_QUEUE, Binding.DestinationType.QUEUE, ORDER_EVENT_EXCHANGE, "order.create.order", null);
}
@Bean
public Binding orderReleaseOrderBingding(){
return new Binding(ORDER_RELEASE_QUEUE, Binding.DestinationType.QUEUE,ORDER_EVENT_EXCHANGE,ORDER_QUEUE_ROUTING_KEY,null);
public Binding orderReleaseOrderBingding() {
return new Binding(ORDER_RELEASE_QUEUE, Binding.DestinationType.QUEUE, ORDER_EVENT_EXCHANGE, ORDER_QUEUE_ROUTING_KEY, null);
}
@Bean
public Queue FMSQueue(){
public Queue FMSQueue() {
return new Queue(FMS_QUEUE);
}
@Bean
TopicExchange FMSExchange() {
return new TopicExchange(FMS_EXCHANGE);
}
Binding bindingExchangeMessage(){
Binding bindingExchangeMessage() {
return BindingBuilder.bind(FMSQueue()).to(FMSExchange()).with(FMS_ROUTING_KEY);
}
@Bean
public DirectExchange orderCancelDeadLetterExchange() {
return new DirectExchange(ORDER_CANCEL_DEAD_LETTER_EXCHANGE);
}
@Bean
public Queue orderCancelDeadLetterQueue() {
return new Queue(ORDER_CANCEL_DEAD_LETTER_QUEUE);
}
@Bean
public DirectExchange orderExchange() {
return new DirectExchange(ORDER_TO_BE_PAY_EXCHANGE);
}
@Bean
public Queue orderQueue() {
Map<String, Object> arguments = new HashMap<>(2);
// 绑定死信交换机
arguments.put("x-dead-letter-exchange", ORDER_CANCEL_DEAD_LETTER_EXCHANGE);
// 绑定我们的路由key
arguments.put("x-dead-letter-routing-key", ORDER_CANCEL_DEAD_LETTER_ROUTING_KEY);
return new Queue(ORDER_TO_BE_PAY_QUEUE, true, false, false, arguments);
}
@Bean
public Binding orderBinding() {
return BindingBuilder.bind(orderQueue()).to(orderExchange()).with(ORDER_TO_BE_PAY_ROUTING_KEY);
}
@Bean
public Binding binding() {
return BindingBuilder.bind(orderCancelDeadLetterQueue()).to(orderCancelDeadLetterExchange()).with(ORDER_CANCEL_DEAD_LETTER_ROUTING_KEY);
}
}