|
|
@@ -149,22 +149,30 @@ public class IotWebsocketMsgServiceImpl extends ServiceImpl<IotWebsocketMsgMappe
|
|
|
@Async(ThreadPoolConfig.HOST_EXECUTOR)
|
|
|
@Transactional(rollbackFor = Exception.class, propagation = Propagation.REQUIRES_NEW)
|
|
|
public void sendFailMsg(WebsocketResult res, String msgId) {
|
|
|
-
|
|
|
final IotWebsocketMsg websocketMsg = getById(msgId);
|
|
|
if (websocketMsg == null) {
|
|
|
return;
|
|
|
}
|
|
|
final LocalDateTime now = LocalDateTime.now();
|
|
|
- final LocalDateTime firTime = websocketMsg.getFireTime() == null ? now : websocketMsg.getFireTime();
|
|
|
+ //final LocalDateTime firTime = websocketMsg.getFireTime() == null ? now : websocketMsg.getFireTime();
|
|
|
final Integer curRetryTimes = websocketMsg.getCurRetryTimes();
|
|
|
if (curRetryTimes == 0) {
|
|
|
- //收到消息处理完成后第一次发送,但是发送失败了
|
|
|
+ //走到这里说明收到了主机发送的消息,且回复消息失败了,开始重试消息
|
|
|
websocketMsg.setReadySendTime(now);
|
|
|
websocketMsg.setReplyContent(JacksonUtils.toJSONString(res));
|
|
|
websocketMsg.setStatus(MessageStatusEnum.RETRYING.getCode());
|
|
|
}
|
|
|
- //websocketMsg.setFireTime(now.plusMinutes(websocketMsg.getRetryInterval()));
|
|
|
- websocketMsg.setFireTime((firTime).plusSeconds(30));
|
|
|
+ if (websocketMsg.getCurRetryTimes() >= websocketMsg.getMaxRetryTimes()) {
|
|
|
+ websocketMsg.setStatus(MessageStatusEnum.RETRY_FAIL.getCode());
|
|
|
+ websocketMsg.setUpdateTime(now);
|
|
|
+ updateById(websocketMsg);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ //设置重试的触发时间与重试次数
|
|
|
+ //websocketMsg.setFireTime((firTime).plusSeconds(30));
|
|
|
+ websocketMsg.setFireTime(now.plusMinutes(websocketMsg.getRetryInterval()));
|
|
|
+ websocketMsg.setCurRetryTimes(curRetryTimes + 1);
|
|
|
websocketMsg.setUpdateTime(now);
|
|
|
updateById(websocketMsg);
|
|
|
RedisDelayedQueueUtil.addDelayQueue(msgId, websocketMsg.getFireTime(), RedisDelayQueueEnum.WEBSOCKET_MSG_RETRY.getCode());
|
|
|
@@ -184,10 +192,8 @@ public class IotWebsocketMsgServiceImpl extends ServiceImpl<IotWebsocketMsgMappe
|
|
|
final Integer maxRetryTimes = msg.getMaxRetryTimes();
|
|
|
final Integer curRetryTimes = msg.getCurRetryTimes();
|
|
|
|
|
|
- if (curRetryTimes < maxRetryTimes) {
|
|
|
+ if (curRetryTimes <= maxRetryTimes) {
|
|
|
//第一次重试, 把消息放到队列中
|
|
|
- msg.setCurRetryTimes(curRetryTimes + 1);
|
|
|
- updateById(msg);
|
|
|
TransactionSynchronizationManager.registerSynchronization(new TransactionSynchronizationAdapter() {
|
|
|
@Override
|
|
|
public void afterCommit() {
|