商品库存回收消息测试

This commit is contained in:
jieyuu 2024-09-02 21:11:46 +08:00
parent 7a79145dc2
commit bd12554d42
3 changed files with 18 additions and 8 deletions

View File

@ -16,7 +16,7 @@ public class InterceptorConfig implements WebMvcConfigurer {
registry registry
.addInterceptor(new LoginInterceptor()) .addInterceptor(new LoginInterceptor())
//拦截的路径 //拦截的路径
.addPathPatterns("/api/coupon/*/**","/api/coupon_record/v1/*/**") .addPathPatterns("/api/coupon/*/**","/api/coupon_record/*/**")
//放行的路径 //放行的路径
.excludePathPatterns("/api/coupon/*/page_coupon","/api/coupon/*/new_user_coupon"); .excludePathPatterns("/api/coupon/*/page_coupon","/api/coupon/*/new_user_coupon");

View File

@ -27,7 +27,7 @@ public class ProductStockMQListener {
@RabbitHandler @RabbitHandler
public void releaseProductStock(ProductMessage productMessage, Message message, Channel channel) throws IOException { public void releaseProductStock(ProductMessage productMessage, Message message, Channel channel) throws IOException {
log.info("监听到消息:releaseProductStock", productMessage); log.info("监听到消息:releaseProductStock消息内容:{}", productMessage);
long msgTag = message.getMessageProperties().getDeliveryTag(); long msgTag = message.getMessageProperties().getDeliveryTag();
boolean flag = productService.releaseProductStock(productMessage); boolean flag = productService.releaseProductStock(productMessage);
// 防止同时解锁多任务并发进入 // 防止同时解锁多任务并发进入
@ -51,10 +51,10 @@ public class ProductStockMQListener {
} }
// @RabbitHandler @RabbitHandler
// public void releaseCouponRecord2(String msg, Message message, Channel channel) throws IOException { public void releaseCouponRecord2(String msg, Message message, Channel channel) throws IOException {
// log.info(msg); log.info(msg);
// channel.basicAck(message.getMessageProperties().getDeliveryTag(), true); channel.basicAck(message.getMessageProperties().getDeliveryTag(), true);
//
// } }
} }

View File

@ -2,6 +2,8 @@ package net.jieyuu.biz;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import net.jieyuu.ProductApplication; import net.jieyuu.ProductApplication;
import net.jieyuu.model.CouponRecordMessage;
import net.jieyuu.model.ProductMessage;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
import org.springframework.amqp.rabbit.core.RabbitTemplate; import org.springframework.amqp.rabbit.core.RabbitTemplate;
@ -23,4 +25,12 @@ public class DemoApplicationTests {
} }
@Test
public void testCouponRecordRelease() {
ProductMessage message = new ProductMessage();
message.setOutTradeNo("123456abc");
message.setTaskId(1l);
rabbitTemplate.convertAndSend("stock.event.exchange", "stock.release.delay.routing.key", message);
}
} }