5.28 消息队列改造支付逻辑
This commit is contained in:
parent
8fe67b5ebd
commit
1ce438395f
@ -68,6 +68,11 @@
|
||||
<groupId>com.alibaba.cloud</groupId>
|
||||
<artifactId>spring-cloud-starter-alibaba-sentinel</artifactId>
|
||||
</dependency>
|
||||
<!--消息发送-->
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-amqp</artifactId>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
<build>
|
||||
<finalName>${project.artifactId}</finalName>
|
||||
|
@ -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<PayOrderMapper, PayOrder> 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<PayOrderMapper, PayOrder> 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) {
|
||||
|
@ -11,4 +11,5 @@ hm:
|
||||
db:
|
||||
database: hm-pay
|
||||
|
||||
|
||||
# keytool -genkeypair -alias hmall -keyalg RSA -keypass hmall123 -keystore hmall.jks -storepass hmall123
|
@ -12,4 +12,5 @@ spring:
|
||||
- dataId: shared_jdbc.yaml # 共享mybatis配置
|
||||
- dataId: shared_log.yaml # 共享日志配置
|
||||
- dataId: shared_swagger.yaml # 共享日志配置
|
||||
- dataId: shared_sentinel.yaml #共享sentinel控制台
|
||||
- dataId: shared_sentinel.yaml #共享sentinel控制台
|
||||
- dataId: shared_mq.yaml #共享mq
|
@ -73,6 +73,11 @@
|
||||
<groupId>com.alibaba.cloud</groupId>
|
||||
<artifactId>spring-cloud-starter-alibaba-seata</artifactId>
|
||||
</dependency>
|
||||
<!--消息发送-->
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-amqp</artifactId>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
<build>
|
||||
<finalName>${project.artifactId}</finalName>
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
@ -13,4 +13,5 @@ spring:
|
||||
- dataId: shared_log.yaml # 共享日志配置
|
||||
- dataId: shared_swagger.yaml # 共享日志配置
|
||||
- dataId: shared_sentinel.yaml #共享sentinel控制台
|
||||
- dataId: shared_seeta.yaml
|
||||
- dataId: shared_seeta.yaml
|
||||
- dataId: shared_mq.yaml #共享mq
|
Loading…
x
Reference in New Issue
Block a user