定时任务超v过期
课程过期
This commit is contained in:
@@ -3,6 +3,7 @@ package com.peanut.config;
|
||||
import com.google.common.collect.Maps;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.amqp.core.*;
|
||||
import org.springframework.beans.factory.annotation.Qualifier;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
@@ -43,19 +44,24 @@ public class DelayQueueConfig {
|
||||
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";
|
||||
|
||||
|
||||
//超V过期队列+死信
|
||||
public static final String USERVIP_QUEUE = "uservip_queue";
|
||||
public static final String USERVIP_EXCHANGE = "uservip_exchange";
|
||||
public static final String USERVIP_ROUTING_KEY = "uservip_routingKey";
|
||||
public static final String USERVIP_DEAD_LETTER_QUEUE = "uservip_dead_letter_queue";
|
||||
public static final String USERVIP_DEAD_LETTER_EXCHANGE = "uservip_dead_letter_exchange";
|
||||
public static final String USERVIP_DEAD_LETTER_ROUTING_KEY = "uservip_dead_letter_routingKey";
|
||||
|
||||
/**
|
||||
* 快递队列
|
||||
*/
|
||||
@@ -64,55 +70,6 @@ public class DelayQueueConfig {
|
||||
public static final String FMS_ROUTING_KEY = "fms.routing.key";
|
||||
|
||||
|
||||
/**
|
||||
* 声明 死信交换机
|
||||
*
|
||||
* @return deadLetterExchange
|
||||
*/
|
||||
@Bean
|
||||
public DirectExchange deadLetterExchange() {
|
||||
return new DirectExchange(DEAD_LETTER_EXCHANGE);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 声明 订单交换机
|
||||
*
|
||||
* @return deadLetterExchange
|
||||
*/
|
||||
@Bean
|
||||
public Exchange orderEventExchange() {
|
||||
return new TopicExchange(ORDER_EVENT_EXCHANGE, true, false);
|
||||
}
|
||||
|
||||
|
||||
@Bean
|
||||
public Queue orderDelayQueue() {
|
||||
|
||||
HashMap<String, Object> map = new HashMap<>();
|
||||
|
||||
// 队列绑定DLX参数(关键一步)
|
||||
map.put("x-dead-letter-exchange", ORDER_EVENT_EXCHANGE);
|
||||
// 队列绑定 死信RoutingKey参数
|
||||
map.put("x-dead-letter-routing-key", ORDER_QUEUE_ROUTING_KEY);
|
||||
|
||||
map.put("x-message-ttl", 60000);
|
||||
|
||||
Queue queue = new Queue(ORDER_DELAY_QUEUE, true, false, false, map);
|
||||
|
||||
return queue;
|
||||
}
|
||||
|
||||
|
||||
@Bean
|
||||
public Queue orderReleaseOrderQueue() {
|
||||
|
||||
Queue queue = new Queue(ORDER_RELEASE_QUEUE, true, false, false);
|
||||
|
||||
return queue;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 声明 死信队列 用于接收死信消息
|
||||
*
|
||||
@@ -123,6 +80,16 @@ public class DelayQueueConfig {
|
||||
return new Queue(DEAD_LETTER_QUEUE);
|
||||
}
|
||||
|
||||
/**
|
||||
* 声明 死信交换机
|
||||
*
|
||||
* @return deadLetterExchange
|
||||
*/
|
||||
@Bean
|
||||
public DirectExchange deadLetterExchange() {
|
||||
return new DirectExchange(DEAD_LETTER_EXCHANGE);
|
||||
}
|
||||
|
||||
/**
|
||||
* 将 死信队列 绑定到死信交换机上
|
||||
*
|
||||
@@ -136,16 +103,6 @@ public class DelayQueueConfig {
|
||||
.with(DEAD_LETTER_QUEUE_ROUTING_KEY);
|
||||
}
|
||||
|
||||
/**
|
||||
* 声明 延时交换机
|
||||
*
|
||||
* @return delayExchange
|
||||
*/
|
||||
@Bean
|
||||
public DirectExchange directExchange() {
|
||||
return new DirectExchange(DELAY_EXCHANGE);
|
||||
}
|
||||
|
||||
/**
|
||||
* 将 延时队列 绑定参数
|
||||
*
|
||||
@@ -163,6 +120,16 @@ public class DelayQueueConfig {
|
||||
return QueueBuilder.durable(DELAY_QUEUE).withArguments(maps).build();
|
||||
}
|
||||
|
||||
/**
|
||||
* 声明 延时交换机
|
||||
*
|
||||
* @return delayExchange
|
||||
*/
|
||||
@Bean
|
||||
public DirectExchange directExchange() {
|
||||
return new DirectExchange(DELAY_EXCHANGE);
|
||||
}
|
||||
|
||||
/**
|
||||
* 将 延时队列 绑定到延时交换机上面
|
||||
*
|
||||
@@ -176,6 +143,40 @@ public class DelayQueueConfig {
|
||||
.with(DELAY_QUEUE_ROUTING_KEY);
|
||||
}
|
||||
|
||||
@Bean
|
||||
public Queue orderDelayQueue() {
|
||||
|
||||
HashMap<String, Object> map = new HashMap<>();
|
||||
|
||||
// 队列绑定DLX参数(关键一步)
|
||||
map.put("x-dead-letter-exchange", ORDER_EVENT_EXCHANGE);
|
||||
// 队列绑定 死信RoutingKey参数
|
||||
map.put("x-dead-letter-routing-key", ORDER_QUEUE_ROUTING_KEY);
|
||||
|
||||
map.put("x-message-ttl", 60000);
|
||||
|
||||
Queue queue = new Queue(ORDER_DELAY_QUEUE, true, false, false, map);
|
||||
|
||||
return queue;
|
||||
}
|
||||
|
||||
@Bean
|
||||
public Queue orderReleaseOrderQueue() {
|
||||
|
||||
Queue queue = new Queue(ORDER_RELEASE_QUEUE, true, false, false);
|
||||
|
||||
return queue;
|
||||
}
|
||||
|
||||
/**
|
||||
* 声明 订单交换机
|
||||
*
|
||||
* @return deadLetterExchange
|
||||
*/
|
||||
@Bean
|
||||
public Exchange orderEventExchange() {
|
||||
return new TopicExchange(ORDER_EVENT_EXCHANGE, true, false);
|
||||
}
|
||||
|
||||
@Bean
|
||||
public Binding orderCreateOrderBingding() {
|
||||
@@ -187,6 +188,80 @@ public class DelayQueueConfig {
|
||||
return new Binding(ORDER_RELEASE_QUEUE, Binding.DestinationType.QUEUE, ORDER_EVENT_EXCHANGE, ORDER_QUEUE_ROUTING_KEY, null);
|
||||
}
|
||||
|
||||
//订单队列+过期死信
|
||||
@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 DirectExchange orderExchange() {
|
||||
return new DirectExchange(ORDER_TO_BE_PAY_EXCHANGE);
|
||||
}
|
||||
@Bean
|
||||
public Binding orderBinding() {
|
||||
return BindingBuilder
|
||||
.bind(orderQueue())
|
||||
.to(orderExchange())
|
||||
.with(ORDER_TO_BE_PAY_ROUTING_KEY);
|
||||
}
|
||||
@Bean
|
||||
public Queue orderCancelDeadLetterQueue() {
|
||||
return new Queue(ORDER_CANCEL_DEAD_LETTER_QUEUE);
|
||||
}
|
||||
@Bean
|
||||
public DirectExchange orderCancelDeadLetterExchange() {
|
||||
return new DirectExchange(ORDER_CANCEL_DEAD_LETTER_EXCHANGE);
|
||||
}
|
||||
@Bean
|
||||
public Binding binding() {
|
||||
return BindingBuilder
|
||||
.bind(orderCancelDeadLetterQueue())
|
||||
.to(orderCancelDeadLetterExchange())
|
||||
.with(ORDER_CANCEL_DEAD_LETTER_ROUTING_KEY);
|
||||
}
|
||||
|
||||
//超V过期队列+死信
|
||||
@Bean
|
||||
public Queue uservipQueue() {
|
||||
Map<String, Object> arguments = new HashMap<>(2);
|
||||
// 绑定死信交换机
|
||||
arguments.put("x-dead-letter-exchange", USERVIP_DEAD_LETTER_EXCHANGE);
|
||||
// 绑定我们的路由key
|
||||
arguments.put("x-dead-letter-routing-key", USERVIP_DEAD_LETTER_ROUTING_KEY);
|
||||
return new Queue(USERVIP_QUEUE, true, false, false, arguments);
|
||||
}
|
||||
@Bean
|
||||
public CustomExchange uservipExchange() {
|
||||
Map<String, Object> args = new HashMap<>();
|
||||
args.put("x-delayed-type", "direct");
|
||||
return new CustomExchange(USERVIP_EXCHANGE, "x-delayed-message", true, false, args);
|
||||
}
|
||||
@Bean
|
||||
public Binding uservipBinding(@Qualifier("uservipQueue") Queue delayedQueue,
|
||||
@Qualifier("uservipExchange") Exchange delayedExchange) {
|
||||
return BindingBuilder.bind(delayedQueue).to(delayedExchange).with(USERVIP_ROUTING_KEY).noargs();
|
||||
}
|
||||
@Bean
|
||||
public Queue uservipDeadLetterQueue() {
|
||||
return new Queue(USERVIP_DEAD_LETTER_QUEUE);
|
||||
}
|
||||
@Bean
|
||||
public DirectExchange uservipDeadLetterExchange() {
|
||||
return new DirectExchange(USERVIP_DEAD_LETTER_EXCHANGE);
|
||||
}
|
||||
@Bean
|
||||
public Binding uservipDeadBinding() {
|
||||
return BindingBuilder
|
||||
.bind(uservipDeadLetterQueue())
|
||||
.to(uservipDeadLetterExchange())
|
||||
.with(USERVIP_DEAD_LETTER_ROUTING_KEY);
|
||||
}
|
||||
|
||||
|
||||
@Bean
|
||||
public Queue FMSQueue() {
|
||||
@@ -199,41 +274,9 @@ public class DelayQueueConfig {
|
||||
}
|
||||
|
||||
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);
|
||||
return BindingBuilder
|
||||
.bind(FMSQueue())
|
||||
.to(FMSExchange())
|
||||
.with(FMS_ROUTING_KEY);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user