parent
9ffc84f5dc
commit
014eedc4e1
@ -0,0 +1,52 @@
|
||||
package com.shun.order.config;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.amqp.core.*;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
/**
|
||||
* @author 夜灬瞬
|
||||
* @since 2023/6/24 17:31
|
||||
*/
|
||||
@Configuration
|
||||
@Slf4j
|
||||
public class RabbitMQConfig {
|
||||
|
||||
public static final String ORDER_EXCHANGE = "order_exchange";
|
||||
public static final String ORDER_QUEUE = "order_queue";
|
||||
|
||||
public static final String DEAD_EXCHANGE = "dead_exchange";
|
||||
public static final String DEAD_QUEUE = "dead_queue";
|
||||
|
||||
@Bean
|
||||
public Exchange orderExchange(){
|
||||
return ExchangeBuilder.fanoutExchange(ORDER_EXCHANGE).build();
|
||||
}
|
||||
|
||||
@Bean
|
||||
public Queue orderQueue(){
|
||||
return QueueBuilder.durable(ORDER_QUEUE).deadLetterExchange(DEAD_EXCHANGE).build();
|
||||
}
|
||||
|
||||
@Bean
|
||||
public Exchange deadExchange(){
|
||||
return ExchangeBuilder.fanoutExchange(DEAD_EXCHANGE).build();
|
||||
}
|
||||
|
||||
@Bean
|
||||
public Queue deadQueue(){
|
||||
return QueueBuilder.durable(DEAD_QUEUE).build();
|
||||
}
|
||||
|
||||
@Bean
|
||||
public Binding orderBinding(Exchange orderExchange,Queue orderQueue){
|
||||
return BindingBuilder.bind(orderQueue).to(orderExchange).with("").noargs();
|
||||
}
|
||||
|
||||
@Bean
|
||||
public Binding deadBinding(Exchange deadExchange,Queue deadQueue){
|
||||
return BindingBuilder.bind(deadQueue).to(deadExchange).with("").noargs();
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,42 @@
|
||||
package com.shun.order.listener;
|
||||
|
||||
import com.rabbitmq.client.Channel;
|
||||
import com.shun.order.config.RabbitMQConfig;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.amqp.core.Message;
|
||||
import org.springframework.amqp.rabbit.annotation.RabbitListener;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
* 优惠券消费者
|
||||
*
|
||||
* @author 夜灬瞬
|
||||
* @since 2023/6/21 21:43
|
||||
*/
|
||||
@Component
|
||||
@Slf4j
|
||||
public class OrderListener {
|
||||
|
||||
@RabbitListener(queues = {RabbitMQConfig.DEAD_QUEUE})
|
||||
public void consume(String msg, Channel channel, Message message) throws Exception {
|
||||
//1、 调用Service实现订单状态的处理
|
||||
// orderService.delayCancelOrder(id);
|
||||
|
||||
//2、 ack的干活~
|
||||
channel.basicAck(message.getMessageProperties().getDeliveryTag(),false);
|
||||
}
|
||||
|
||||
|
||||
public void delayCancelOrder(String id) {
|
||||
//1、基于id查询订单信息。 for update
|
||||
// int orderState = orderMapper.findOrderStateByIdForUpdate(id);
|
||||
// //2、判断订单状态
|
||||
// if(orderState != 0){
|
||||
// log.info("订单已经支付!!");
|
||||
// return;
|
||||
// }
|
||||
// //3、修改订单状态
|
||||
// log.info("订单未支付,修改订单状态为已取消");
|
||||
// orderMapper.updateOrderStateById(-1,id);
|
||||
}
|
||||
}
|
Loading…
Reference in new issue