|
@@ -16,6 +16,7 @@ import org.apache.rocketmq.client.producer.SendCallback;
|
|
import org.apache.rocketmq.client.producer.SendResult;
|
|
import org.apache.rocketmq.client.producer.SendResult;
|
|
import org.apache.rocketmq.common.message.MessageConst;
|
|
import org.apache.rocketmq.common.message.MessageConst;
|
|
import org.apache.rocketmq.spring.core.RocketMQTemplate;
|
|
import org.apache.rocketmq.spring.core.RocketMQTemplate;
|
|
|
|
+import org.apache.rocketmq.spring.support.RocketMQHeaders;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.messaging.support.MessageBuilder;
|
|
import org.springframework.messaging.support.MessageBuilder;
|
|
import org.springframework.scheduling.annotation.Async;
|
|
import org.springframework.scheduling.annotation.Async;
|
|
@@ -49,7 +50,6 @@ public class AsyncCourseWatchFinishService {
|
|
|
|
|
|
// 主题映射配置
|
|
// 主题映射配置
|
|
private static final String TOPIC = "course-finish-notes";
|
|
private static final String TOPIC = "course-finish-notes";
|
|
- private static final Integer DEFAULT_SERVER_NUM = 99;
|
|
|
|
|
|
|
|
@PostConstruct
|
|
@PostConstruct
|
|
public void init() {
|
|
public void init() {
|
|
@@ -163,14 +163,6 @@ public class AsyncCourseWatchFinishService {
|
|
return ValidationResult.valid(watchLog, qwUserByRedis, qwCompany);
|
|
return ValidationResult.valid(watchLog, qwUserByRedis, qwCompany);
|
|
}
|
|
}
|
|
|
|
|
|
- /**
|
|
|
|
- * 获取目标Tag(替换原来的获取Topic方法)
|
|
|
|
- */
|
|
|
|
- private String getTargetTag(QwCompany qwCompany) {
|
|
|
|
- Integer companyServerNum = Optional.ofNullable(qwCompany.getCompanyServerNum())
|
|
|
|
- .orElse(DEFAULT_SERVER_NUM);
|
|
|
|
- return "TAG_" + companyServerNum; // 生成对应的Tag
|
|
|
|
- }
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
* 带流控处理的消息发送
|
|
* 带流控处理的消息发送
|
|
@@ -184,22 +176,10 @@ public class AsyncCourseWatchFinishService {
|
|
return;
|
|
return;
|
|
}
|
|
}
|
|
|
|
|
|
- // 获取Tag
|
|
|
|
- String tag = getTargetTag(validationResult.getQwCompany());
|
|
|
|
- String messageBody = JSON.toJSONString(finishLog);
|
|
|
|
-
|
|
|
|
- // 构建带Tag的消息
|
|
|
|
- org.springframework.messaging.Message<String> message = MessageBuilder
|
|
|
|
- .withPayload(messageBody)
|
|
|
|
- .setHeader(MessageConst.PROPERTY_TAGS, tag)
|
|
|
|
- .build();
|
|
|
|
-
|
|
|
|
- rocketMQTemplate.asyncSend(TOPIC, message, new SendCallback() {
|
|
|
|
|
|
+ rocketMQTemplate.asyncSend(TOPIC, JSON.toJSONString(finishLog), new SendCallback() {
|
|
@Override
|
|
@Override
|
|
public void onSuccess(SendResult sendResult) {
|
|
public void onSuccess(SendResult sendResult) {
|
|
-// log.info("推送完课打备注成功1:{},{}",JSON.toJSONString(finishLog),sendResult.getMsgId());
|
|
|
|
- log.info("推送完课打备注成功1: tag={},finishLog={}, msgId={}",
|
|
|
|
- tag,JSON.toJSONString(finishLog), sendResult.getMsgId());
|
|
|
|
|
|
+ log.info("推送完课打备注成功1:{},{}",JSON.toJSONString(finishLog),sendResult.getMsgId());
|
|
}
|
|
}
|
|
|
|
|
|
@Override
|
|
@Override
|
|
@@ -207,12 +187,10 @@ public class AsyncCourseWatchFinishService {
|
|
if (isFlowControlException(e)) {
|
|
if (isFlowControlException(e)) {
|
|
// 流控异常处理
|
|
// 流控异常处理
|
|
handleFlowControlRetry(TOPIC, finishLog, validationResult, retryCount, e);
|
|
handleFlowControlRetry(TOPIC, finishLog, validationResult, retryCount, e);
|
|
- log.error("推送完课打备注失败1流控异常:tag={},finishLog={},e={}",tag,JSON.toJSONString(finishLog),e.getMessage());
|
|
|
|
|
|
+ log.error("推送完课打备注失败1流控异常:finishLog={},e={}",JSON.toJSONString(finishLog),e.getMessage());
|
|
} else {
|
|
} else {
|
|
// 其他异常
|
|
// 其他异常
|
|
-// log.error("推送完课打备注失败1:{},{}",JSON.toJSONString(finishLog),e.getMessage());
|
|
|
|
- log.error("推送完课打备注失败: tag={}, finishLog={}, error={}",
|
|
|
|
- tag, JSON.toJSONString(finishLog), e.getMessage());
|
|
|
|
|
|
+ log.error("推送完课打备注失败1:{},{}",JSON.toJSONString(finishLog),e.getMessage());
|
|
}
|
|
}
|
|
}
|
|
}
|
|
});
|
|
});
|