diff --git a/pay-service/pom.xml b/pay-service/pom.xml
index 57769d2..f4aa90b 100644
--- a/pay-service/pom.xml
+++ b/pay-service/pom.xml
@@ -68,6 +68,11 @@
com.alibaba.cloud
spring-cloud-starter-alibaba-sentinel
+
+
+ org.springframework.boot
+ spring-boot-starter-amqp
+
${project.artifactId}
diff --git a/pay-service/src/main/java/com/hmall/pay/service/impl/PayOrderServiceImpl.java b/pay-service/src/main/java/com/hmall/pay/service/impl/PayOrderServiceImpl.java
index cd3f6b6..5c6af44 100644
--- a/pay-service/src/main/java/com/hmall/pay/service/impl/PayOrderServiceImpl.java
+++ b/pay-service/src/main/java/com/hmall/pay/service/impl/PayOrderServiceImpl.java
@@ -18,6 +18,8 @@ import com.hmall.pay.service.IPayOrderService;
import com.hmall.service.IOrderService;
import com.hmall.service.IUserService;
import lombok.RequiredArgsConstructor;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
@@ -33,12 +35,15 @@ import java.time.LocalDateTime;
*/
@Service
@RequiredArgsConstructor
+@Slf4j
public class PayOrderServiceImpl extends ServiceImpl implements IPayOrderService {
private final UserClient userClient;
private final TradeClient tradeClient;
+ private final RabbitTemplate rabbitTemplate;
+
@Override
public String applyPayOrder(PayApplyDTO applyDTO) {
// 1.幂等性校验
@@ -65,7 +70,12 @@ public class PayOrderServiceImpl extends ServiceImpl i
throw new BizIllegalException("交易已支付或关闭!");
}
// 5.修改订单状态
- tradeClient.markOrderPaySuccess(po.getBizOrderNo());
+ // tradeClient.markOrderPaySuccess(po.getBizOrderNo());
+ try {
+ rabbitTemplate.convertAndSend("pay.direct", "pay.success", po.getBizOrderNo());
+ } catch (Exception e) {
+ log.error("支付成功的消息发送失败,支付单id:{}, 交易单id:{}", po.getId(), po.getBizOrderNo(), e);
+ }
}
public boolean markPayOrderSuccess(Long id, LocalDateTime successTime) {
diff --git a/pay-service/src/main/resources/application.yaml b/pay-service/src/main/resources/application.yaml
index 6fae47d..3caaab5 100644
--- a/pay-service/src/main/resources/application.yaml
+++ b/pay-service/src/main/resources/application.yaml
@@ -11,4 +11,5 @@ hm:
db:
database: hm-pay
+
# keytool -genkeypair -alias hmall -keyalg RSA -keypass hmall123 -keystore hmall.jks -storepass hmall123
\ No newline at end of file
diff --git a/pay-service/src/main/resources/bootstrap.yaml b/pay-service/src/main/resources/bootstrap.yaml
index 9636ce3..472f43e 100644
--- a/pay-service/src/main/resources/bootstrap.yaml
+++ b/pay-service/src/main/resources/bootstrap.yaml
@@ -12,4 +12,5 @@ spring:
- dataId: shared_jdbc.yaml # 共享mybatis配置
- dataId: shared_log.yaml # 共享日志配置
- dataId: shared_swagger.yaml # 共享日志配置
- - dataId: shared_sentinel.yaml #共享sentinel控制台
\ No newline at end of file
+ - dataId: shared_sentinel.yaml #共享sentinel控制台
+ - dataId: shared_mq.yaml #共享mq
\ No newline at end of file
diff --git a/trade-service/pom.xml b/trade-service/pom.xml
index 8d96119..43bd815 100644
--- a/trade-service/pom.xml
+++ b/trade-service/pom.xml
@@ -73,6 +73,11 @@
com.alibaba.cloud
spring-cloud-starter-alibaba-seata
+
+
+ org.springframework.boot
+ spring-boot-starter-amqp
+
${project.artifactId}
diff --git a/trade-service/src/main/java/com/hmall/trade/listener/PayStatusListener.java b/trade-service/src/main/java/com/hmall/trade/listener/PayStatusListener.java
new file mode 100644
index 0000000..fe2ce8d
--- /dev/null
+++ b/trade-service/src/main/java/com/hmall/trade/listener/PayStatusListener.java
@@ -0,0 +1,28 @@
+package com.hmall.trade.listener;
+
+import com.hmall.trade.service.IOrderService;
+import lombok.RequiredArgsConstructor;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.amqp.rabbit.annotation.Exchange;
+import org.springframework.amqp.rabbit.annotation.Queue;
+import org.springframework.amqp.rabbit.annotation.QueueBinding;
+import org.springframework.amqp.rabbit.annotation.RabbitListener;
+import org.springframework.stereotype.Component;
+
+@Component
+@RequiredArgsConstructor
+@Slf4j
+public class PayStatusListener {
+
+ private final IOrderService orderService;
+
+ @RabbitListener(bindings = @QueueBinding(
+ value = @Queue(name = "trade.pay.success.queue", durable = "true"),
+ exchange = @Exchange(name = "pay.direct"),
+ key = "pay.success"
+ ))
+ public void listenPaySuccess(Long orderId){
+ log.info("MQtest:orderId:"+orderId);
+ orderService.markOrderPaySuccess(orderId);
+ }
+}
\ No newline at end of file
diff --git a/trade-service/src/main/resources/bootstrap.yaml b/trade-service/src/main/resources/bootstrap.yaml
index 39833b5..b1dc89b 100644
--- a/trade-service/src/main/resources/bootstrap.yaml
+++ b/trade-service/src/main/resources/bootstrap.yaml
@@ -13,4 +13,5 @@ spring:
- dataId: shared_log.yaml # 共享日志配置
- dataId: shared_swagger.yaml # 共享日志配置
- dataId: shared_sentinel.yaml #共享sentinel控制台
- - dataId: shared_seeta.yaml
\ No newline at end of file
+ - dataId: shared_seeta.yaml
+ - dataId: shared_mq.yaml #共享mq
\ No newline at end of file