myCard新增mq补单逻辑
This commit is contained in:
@@ -38,4 +38,8 @@ public interface MqConstant {
|
||||
String YI_DUN_TEXT_ANTI_TOPIC = "yidun_text_anti_topic";
|
||||
String YI_DUN_TEXT_ANTI_CONSUME_GROUP = "yidun_text_anti_consume_group";
|
||||
|
||||
String CHANGE_TOPIC = "charge_topic";
|
||||
|
||||
String CHARGE_CONSUME_GROUP = "charge_consume_group";
|
||||
|
||||
}
|
||||
|
@@ -0,0 +1,17 @@
|
||||
package com.accompany.mq.model;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* @author: liaozetao
|
||||
* @date: 2024/1/24 11:24
|
||||
* @description:
|
||||
*/
|
||||
@Data
|
||||
public class ChargeMqMessage extends BaseMqMessage {
|
||||
|
||||
/**
|
||||
* 充值ID
|
||||
*/
|
||||
private String chargeRecordId;
|
||||
}
|
@@ -0,0 +1,67 @@
|
||||
package com.accompany.mq.consumer;
|
||||
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.accompany.business.message.ActivityPackMessage;
|
||||
import com.accompany.business.service.mycard.MyCardBizService;
|
||||
import com.accompany.common.constant.Constant;
|
||||
import com.accompany.common.redis.RedisKey;
|
||||
import com.accompany.mq.constant.MqConstant;
|
||||
import com.accompany.mq.listener.AbstractMessageListener;
|
||||
import com.accompany.mq.model.ChargeMqMessage;
|
||||
import com.accompany.mq.producer.MQMessageProducer;
|
||||
import com.accompany.payment.model.ChargeRecord;
|
||||
import com.accompany.payment.service.ChargeRecordService;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.rocketmq.spring.annotation.ConsumeMode;
|
||||
import org.apache.rocketmq.spring.annotation.RocketMQMessageListener;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
* @author: liaozetao
|
||||
* @date: 2024/1/24 11:30
|
||||
* @description:
|
||||
*/
|
||||
@Slf4j
|
||||
@Component
|
||||
@ConditionalOnProperty(name = "spring.application.name", havingValue = "web")
|
||||
@RocketMQMessageListener(topic = MqConstant.CHANGE_TOPIC, consumerGroup = MqConstant.CHARGE_CONSUME_GROUP, consumeMode = ConsumeMode.ORDERLY)
|
||||
public class MyCardChargeMessageConsumer extends AbstractMessageListener<ChargeMqMessage> {
|
||||
|
||||
@Autowired
|
||||
private ChargeRecordService chargeRecordService;
|
||||
|
||||
@Autowired
|
||||
private MyCardBizService myCardBizService;
|
||||
|
||||
@Autowired
|
||||
private MQMessageProducer mqMessageProducer;
|
||||
|
||||
@Override
|
||||
protected void onMessage(ChargeMqMessage object) throws Exception {
|
||||
String chargeRecordId = object.getChargeRecordId();
|
||||
ChargeRecord chargeRecord = chargeRecordService.getChargeRecordById(chargeRecordId);
|
||||
if (chargeRecord == null) {
|
||||
return;
|
||||
}
|
||||
String channel = chargeRecord.getChannel();
|
||||
if (!Constant.ChargeChannel.my_card.equals(channel)) {
|
||||
return;
|
||||
}
|
||||
log.info("开始执行MyCard mq监控流程 chargeRecordId : {}", chargeRecordId);
|
||||
boolean isSuccess = myCardBizService.updateOrder(chargeRecordId);
|
||||
String countStr = jedisService.hget(RedisKey.charge_record_mq_count.getKey(), chargeRecordId);
|
||||
if (!isSuccess) {
|
||||
if (StrUtil.isNotEmpty(countStr) && Integer.parseInt(countStr) >= 3) {
|
||||
log.error("chargeRecordId : {}重试终止", chargeRecordId);
|
||||
return;
|
||||
}
|
||||
log.info("send retry mq chargeRecordId : {}", chargeRecordId);
|
||||
jedisService.hincr(RedisKey.charge_record_mq_count.getKey(), chargeRecordId);
|
||||
ChargeMqMessage message = new ChargeMqMessage();
|
||||
message.setChargeRecordId(chargeRecordId);
|
||||
mqMessageProducer.send(MqConstant.CHANGE_TOPIC, message, 9);
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user