Compare commits
No commits in common. 'main' and 'b320470aa84e09d419b0b7edb99fc6994f99c80e' have entirely different histories.
main
...
b320470aa8
@ -1,57 +0,0 @@
|
||||
package com.shun.business.config;
|
||||
|
||||
import org.springframework.amqp.core.*;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
|
||||
/**
|
||||
* @author 夜灬瞬
|
||||
* @since 2023/6/21 21:08
|
||||
*/
|
||||
@Configuration
|
||||
public class RabbitMQConfig {
|
||||
|
||||
/**
|
||||
* 下单服务的交换机
|
||||
*/
|
||||
public static final String PLACE_ORDER_EXCHANGE = "place_order_exchange";
|
||||
|
||||
/**
|
||||
* 三个服务的Queue
|
||||
*/
|
||||
public static final String COUPON_QUEUE = "coupon_queue";
|
||||
public static final String USER_POINTS_QUEUE = "user_points_queue";
|
||||
public static final String BUSINESS_QUEUE = "business_queue";
|
||||
|
||||
@Bean
|
||||
public Exchange placeOrderExchange(){
|
||||
return ExchangeBuilder.fanoutExchange(PLACE_ORDER_EXCHANGE).build();
|
||||
}
|
||||
|
||||
@Bean
|
||||
public Queue couponQueue(){
|
||||
return QueueBuilder.durable(COUPON_QUEUE).build();
|
||||
}
|
||||
@Bean
|
||||
public Queue userPointsQueue(){
|
||||
return QueueBuilder.durable(USER_POINTS_QUEUE).build();
|
||||
}
|
||||
@Bean
|
||||
public Queue businessQueue(){
|
||||
return QueueBuilder.durable(BUSINESS_QUEUE).build();
|
||||
}
|
||||
|
||||
@Bean
|
||||
public Binding couponBinding(Exchange placeOrderExchange, Queue couponQueue){
|
||||
return BindingBuilder.bind(couponQueue).to(placeOrderExchange).with("").noargs();
|
||||
}
|
||||
@Bean
|
||||
public Binding userPointsBinding(Exchange placeOrderExchange,Queue userPointsQueue){
|
||||
return BindingBuilder.bind(userPointsQueue).to(placeOrderExchange).with("").noargs();
|
||||
}
|
||||
@Bean
|
||||
public Binding businessBinding(Exchange placeOrderExchange,Queue businessQueue){
|
||||
return BindingBuilder.bind(businessQueue).to(placeOrderExchange).with("").noargs();
|
||||
}
|
||||
}
|
@ -1,28 +0,0 @@
|
||||
package com.shun.business.listener;
|
||||
|
||||
import com.rabbitmq.client.Channel;
|
||||
import com.shun.business.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 BusinessListener {
|
||||
|
||||
@RabbitListener(queues = {RabbitMQConfig.BUSINESS_QUEUE})
|
||||
public void consume(String msg, Channel channel, Message message) throws Exception {
|
||||
// 预扣除优惠券
|
||||
Thread.sleep(400);
|
||||
log.info("优惠券预扣除成功! msg:{}",msg);
|
||||
// 手动ACK
|
||||
channel.basicAck(message.getMessageProperties().getDeliveryTag(), false);
|
||||
}
|
||||
}
|
@ -1,56 +0,0 @@
|
||||
package com.shun.coupon.config;
|
||||
|
||||
import org.springframework.amqp.core.*;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
/**
|
||||
* @author 夜灬瞬
|
||||
* @since 2023/6/21 21:08
|
||||
*/
|
||||
@Configuration
|
||||
public class RabbitMQConfig {
|
||||
|
||||
/**
|
||||
* 下单服务的交换机
|
||||
*/
|
||||
public static final String PLACE_ORDER_EXCHANGE = "place_order_exchange";
|
||||
|
||||
/**
|
||||
* 三个服务的Queue
|
||||
*/
|
||||
public static final String COUPON_QUEUE = "coupon_queue";
|
||||
public static final String USER_POINTS_QUEUE = "user_points_queue";
|
||||
public static final String BUSINESS_QUEUE = "business_queue";
|
||||
|
||||
@Bean
|
||||
public Exchange placeOrderExchange(){
|
||||
return ExchangeBuilder.fanoutExchange(PLACE_ORDER_EXCHANGE).build();
|
||||
}
|
||||
|
||||
@Bean
|
||||
public Queue couponQueue(){
|
||||
return QueueBuilder.durable(COUPON_QUEUE).build();
|
||||
}
|
||||
@Bean
|
||||
public Queue userPointsQueue(){
|
||||
return QueueBuilder.durable(USER_POINTS_QUEUE).build();
|
||||
}
|
||||
@Bean
|
||||
public Queue businessQueue(){
|
||||
return QueueBuilder.durable(BUSINESS_QUEUE).build();
|
||||
}
|
||||
|
||||
@Bean
|
||||
public Binding couponBinding(Exchange placeOrderExchange,Queue couponQueue){
|
||||
return BindingBuilder.bind(couponQueue).to(placeOrderExchange).with("").noargs();
|
||||
}
|
||||
@Bean
|
||||
public Binding userPointsBinding(Exchange placeOrderExchange,Queue userPointsQueue){
|
||||
return BindingBuilder.bind(userPointsQueue).to(placeOrderExchange).with("").noargs();
|
||||
}
|
||||
@Bean
|
||||
public Binding businessBinding(Exchange placeOrderExchange,Queue businessQueue){
|
||||
return BindingBuilder.bind(businessQueue).to(placeOrderExchange).with("").noargs();
|
||||
}
|
||||
}
|
@ -1,29 +0,0 @@
|
||||
package com.shun.coupon.listener;
|
||||
|
||||
import com.rabbitmq.client.AMQP;
|
||||
import com.rabbitmq.client.Channel;
|
||||
import com.shun.coupon.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 CouponListener {
|
||||
|
||||
@RabbitListener(queues = {RabbitMQConfig.COUPON_QUEUE})
|
||||
public void consume(String msg, Channel channel, Message message) throws Exception {
|
||||
// 预扣除优惠券
|
||||
Thread.sleep(400);
|
||||
log.info("优惠券预扣除成功! msg:{}",msg);
|
||||
// 手动ACK
|
||||
channel.basicAck(message.getMessageProperties().getDeliveryTag(), false);
|
||||
}
|
||||
}
|
@ -1,57 +0,0 @@
|
||||
package com.shun.integral.config;
|
||||
|
||||
import org.springframework.amqp.core.*;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
|
||||
/**
|
||||
* @author 夜灬瞬
|
||||
* @since 2023/6/21 21:08
|
||||
*/
|
||||
@Configuration
|
||||
public class RabbitMQConfig {
|
||||
|
||||
/**
|
||||
* 下单服务的交换机
|
||||
*/
|
||||
public static final String PLACE_ORDER_EXCHANGE = "place_order_exchange";
|
||||
|
||||
/**
|
||||
* 三个服务的Queue
|
||||
*/
|
||||
public static final String COUPON_QUEUE = "coupon_queue";
|
||||
public static final String USER_POINTS_QUEUE = "user_points_queue";
|
||||
public static final String BUSINESS_QUEUE = "business_queue";
|
||||
|
||||
@Bean
|
||||
public Exchange placeOrderExchange(){
|
||||
return ExchangeBuilder.fanoutExchange(PLACE_ORDER_EXCHANGE).build();
|
||||
}
|
||||
|
||||
@Bean
|
||||
public Queue couponQueue(){
|
||||
return QueueBuilder.durable(COUPON_QUEUE).build();
|
||||
}
|
||||
@Bean
|
||||
public Queue userPointsQueue(){
|
||||
return QueueBuilder.durable(USER_POINTS_QUEUE).build();
|
||||
}
|
||||
@Bean
|
||||
public Queue businessQueue(){
|
||||
return QueueBuilder.durable(BUSINESS_QUEUE).build();
|
||||
}
|
||||
|
||||
@Bean
|
||||
public Binding couponBinding(Exchange placeOrderExchange, Queue couponQueue){
|
||||
return BindingBuilder.bind(couponQueue).to(placeOrderExchange).with("").noargs();
|
||||
}
|
||||
@Bean
|
||||
public Binding userPointsBinding(Exchange placeOrderExchange,Queue userPointsQueue){
|
||||
return BindingBuilder.bind(userPointsQueue).to(placeOrderExchange).with("").noargs();
|
||||
}
|
||||
@Bean
|
||||
public Binding businessBinding(Exchange placeOrderExchange,Queue businessQueue){
|
||||
return BindingBuilder.bind(businessQueue).to(placeOrderExchange).with("").noargs();
|
||||
}
|
||||
}
|
@ -1,28 +0,0 @@
|
||||
package com.shun.integral.listener;
|
||||
|
||||
import com.rabbitmq.client.Channel;
|
||||
import com.shun.integral.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 IntegralListener {
|
||||
|
||||
@RabbitListener(queues = {RabbitMQConfig.USER_POINTS_QUEUE})
|
||||
public void consume(String msg, Channel channel, Message message) throws Exception {
|
||||
// 预扣除优惠券
|
||||
Thread.sleep(400);
|
||||
log.info("优惠券预扣除成功! msg:{}",msg);
|
||||
// 手动ACK
|
||||
channel.basicAck(message.getMessageProperties().getDeliveryTag(), false);
|
||||
}
|
||||
}
|
@ -1,52 +0,0 @@
|
||||
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();
|
||||
}
|
||||
|
||||
}
|
@ -1,42 +0,0 @@
|
||||
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);
|
||||
}
|
||||
}
|
@ -1,56 +0,0 @@
|
||||
package com.shun.placeOrder.config;
|
||||
|
||||
import org.springframework.amqp.core.*;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
/**
|
||||
* @author 夜灬瞬
|
||||
* @since 2023/6/21 21:08
|
||||
*/
|
||||
@Configuration
|
||||
public class RabbitMQConfig {
|
||||
|
||||
/**
|
||||
* 下单服务的交换机
|
||||
*/
|
||||
public static final String PLACE_ORDER_EXCHANGE = "place_order_exchange";
|
||||
|
||||
/**
|
||||
* 三个服务的Queue
|
||||
*/
|
||||
public static final String COUPON_QUEUE = "coupon_queue";
|
||||
public static final String USER_POINTS_QUEUE = "user_points_queue";
|
||||
public static final String BUSINESS_QUEUE = "business_queue";
|
||||
|
||||
@Bean
|
||||
public Exchange placeOrderExchange(){
|
||||
return ExchangeBuilder.fanoutExchange(PLACE_ORDER_EXCHANGE).build();
|
||||
}
|
||||
|
||||
@Bean
|
||||
public Queue couponQueue(){
|
||||
return QueueBuilder.durable(COUPON_QUEUE).build();
|
||||
}
|
||||
@Bean
|
||||
public Queue userPointsQueue(){
|
||||
return QueueBuilder.durable(USER_POINTS_QUEUE).build();
|
||||
}
|
||||
@Bean
|
||||
public Queue businessQueue(){
|
||||
return QueueBuilder.durable(BUSINESS_QUEUE).build();
|
||||
}
|
||||
|
||||
@Bean
|
||||
public Binding couponBinding(Exchange placeOrderExchange,Queue couponQueue){
|
||||
return BindingBuilder.bind(couponQueue).to(placeOrderExchange).with("").noargs();
|
||||
}
|
||||
@Bean
|
||||
public Binding userPointsBinding(Exchange placeOrderExchange,Queue userPointsQueue){
|
||||
return BindingBuilder.bind(userPointsQueue).to(placeOrderExchange).with("").noargs();
|
||||
}
|
||||
@Bean
|
||||
public Binding businessBinding(Exchange placeOrderExchange,Queue businessQueue){
|
||||
return BindingBuilder.bind(businessQueue).to(placeOrderExchange).with("").noargs();
|
||||
}
|
||||
}
|
@ -1,25 +0,0 @@
|
||||
package com.shun.placeOrder.util;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 全局 cache
|
||||
* @author 夜灬瞬
|
||||
* @since 2023/6/24 15:07
|
||||
*/
|
||||
public class GlobalCache {
|
||||
private static final Map<String,Object> MAP = new HashMap<>();
|
||||
|
||||
public static void set(String key,Object value){
|
||||
MAP.put(key,value);
|
||||
}
|
||||
|
||||
public static Object get(String key){
|
||||
return MAP.get(key);
|
||||
}
|
||||
|
||||
public static void remove(String key){
|
||||
MAP.remove(key);
|
||||
}
|
||||
}
|
@ -1,18 +0,0 @@
|
||||
package com.shun.placeOrder.util;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 模拟数据库
|
||||
* @author 夜灬瞬
|
||||
* @since 2023/6/24 15:25
|
||||
*/
|
||||
@Slf4j
|
||||
public class Mock {
|
||||
|
||||
public static void save(Object value) {
|
||||
log.info("保存");
|
||||
}
|
||||
}
|
@ -1,3 +1 @@
|
||||
RabbitMQ 模拟电商
|
||||
支付 订单 商家 积分 库存 优惠券
|
||||
基本逻辑
|
||||
RabbitMQ 模拟电商
|
Loading…
Reference in new issue