Merge remote-tracking branch 'origin/dev' into hph
# Conflicts: # src/main/java/com/chaozhanggui/system/cashierservice/service/CartService.java
This commit is contained in:
@@ -0,0 +1,26 @@
|
||||
package com.chaozhanggui.system.cashierservice.util;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.chaozhanggui.system.cashierservice.rabbit.RabbitConstants;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.amqp.rabbit.core.RabbitTemplate;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Slf4j
|
||||
@Component
|
||||
public class MQUtils {
|
||||
private final RabbitTemplate rabbitTemplate;
|
||||
|
||||
public MQUtils(RabbitTemplate rabbitTemplate) {
|
||||
this.rabbitTemplate = rabbitTemplate;
|
||||
}
|
||||
|
||||
private <T> void sendMsg(String exchange, String routingKey, T data, String note) {
|
||||
log.info("开始发送{}mq消息, exchange: {}, routingKey: {}, data: {}", note, exchange, routingKey, data);
|
||||
rabbitTemplate.convertAndSend(exchange, routingKey, JSONObject.toJSONString(data));
|
||||
}
|
||||
|
||||
public <T> void sendStockSaleMsg(T data) {
|
||||
sendMsg(RabbitConstants.EXCHANGE_STOCK_RECORD, RabbitConstants.ROUTING_STOCK_RECORD_SALE, data, "商品售出增加库存记录");
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user