|
|
@ -7,7 +7,6 @@ import com.epmet.commons.tools.constant.NumConstant; |
|
|
|
import com.epmet.commons.tools.dto.form.mq.EventClassDto; |
|
|
|
import com.epmet.commons.tools.dto.form.mq.MqBaseMsgDTO; |
|
|
|
import com.epmet.commons.tools.dto.form.mq.MqReturnBaseResult; |
|
|
|
import com.epmet.commons.tools.enums.EnvEnum; |
|
|
|
import com.epmet.commons.tools.enums.MqMethodPathEnum; |
|
|
|
import com.epmet.commons.tools.exception.EpmetErrorCode; |
|
|
|
import com.epmet.commons.tools.exception.ValidateException; |
|
|
@ -32,7 +31,7 @@ public class SendMqMsgUtils { |
|
|
|
private static MqConfig mqConfig; |
|
|
|
|
|
|
|
/** |
|
|
|
* desc:发送mq消息 |
|
|
|
* desc:发送mq消息(如果失败重试1次) |
|
|
|
* |
|
|
|
* @return |
|
|
|
*/ |
|
|
@ -40,7 +39,7 @@ public class SendMqMsgUtils { |
|
|
|
if (mqConfig == null) { |
|
|
|
mqConfig = SpringContextUtils.getBean(MqConfig.class); |
|
|
|
} |
|
|
|
log.debug("sendMsg param:{}", JSON.toJSONString(msg)); |
|
|
|
log.info("sendMsg param:{}", JSON.toJSONString(msg)); |
|
|
|
try { |
|
|
|
// TODO
|
|
|
|
ValidatorUtils.validateEntity(msg, DefaultGroup.class); |
|
|
@ -51,8 +50,14 @@ public class SendMqMsgUtils { |
|
|
|
msg.setRequestUrl(mqConfig.getHost().concat(MqMethodPathEnum.SEND_MSG.getCode())); |
|
|
|
msg.setToken(mqConfig.getToken()); |
|
|
|
try { |
|
|
|
Result<String> result = HttpClientManager.getInstance().sendPostByHttps(msg.getRequestUrl(), JSON.toJSONString(msg)); |
|
|
|
log.debug("sendMsg result:{}", JSON.toJSONString(result)); |
|
|
|
int retryTime = 0; |
|
|
|
Result<String> result = null; |
|
|
|
do { |
|
|
|
retryTime++; |
|
|
|
result = HttpClientManager.getInstance().sendPostByHttps(msg.getRequestUrl(), JSON.toJSONString(msg)); |
|
|
|
log.info("sendMsg retryTime:{},result:{}", retryTime, JSON.toJSONString(result)); |
|
|
|
} while ((!result.success()) && retryTime < 2); |
|
|
|
|
|
|
|
if (result.success()) { |
|
|
|
MqReturnBaseResult resultResult = JSON.parseObject(result.getData(), MqReturnBaseResult.class); |
|
|
|
if (resultResult.getErrCode().equals(NumConstant.ZERO)) { |
|
|
@ -68,7 +73,7 @@ public class SendMqMsgUtils { |
|
|
|
resultResult.setInternalMsg(result.getInternalMsg()); |
|
|
|
return resultResult; |
|
|
|
} catch (Exception e) { |
|
|
|
log.debug("sendMsg exception", e); |
|
|
|
log.error("sendMsg exception", e); |
|
|
|
return new Result<String>().error(EpmetErrorCode.SERVER_ERROR.getCode(), EpmetErrorCode.SERVER_ERROR.getMsg()); |
|
|
|
} |
|
|
|
} |
|
|
@ -90,7 +95,7 @@ public class SendMqMsgUtils { |
|
|
|
|
|
|
|
try { |
|
|
|
Result<String> result = HttpClientManager.getInstance().sendPostByHttps(requestUrl, JSON.toJSONString(param)); |
|
|
|
log.debug("getEventClassList result:{}", JSON.toJSONString(result)); |
|
|
|
log.info("getEventClassList result:{}", JSON.toJSONString(result)); |
|
|
|
if (result.success()) { |
|
|
|
MqReturnBaseResult resultResult = JSON.parseObject(result.getData(), MqReturnBaseResult.class); |
|
|
|
if (resultResult.getErrCode().equals(NumConstant.ZERO)) { |
|
|
@ -106,7 +111,7 @@ public class SendMqMsgUtils { |
|
|
|
resultResult.setInternalMsg(result.getInternalMsg()); |
|
|
|
return resultResult; |
|
|
|
} catch (Exception e) { |
|
|
|
log.debug("sendMsg exception", e); |
|
|
|
log.error("sendMsg exception", e); |
|
|
|
return new Result<List<EventClassDto>>().error(EpmetErrorCode.SERVER_ERROR.getCode(), EpmetErrorCode.SERVER_ERROR.getMsg()); |
|
|
|
} |
|
|
|
} |
|
|
|