Browse Source

缩短参数 去掉url

dev_shibei_match
jianjun 4 years ago
parent
commit
a0b0944429
  1. 1
      epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/dto/form/mq/MqBaseParamDTO.java
  2. 11
      epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/utils/SendMqMsgUtils.java

1
epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/dto/form/mq/MqBaseParamDTO.java

@ -14,5 +14,4 @@ import java.io.Serializable;
public class MqBaseParamDTO implements Serializable { public class MqBaseParamDTO implements Serializable {
private String appId; private String appId;
private String token; private String token;
private String requestUrl;
} }

11
epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/utils/SendMqMsgUtils.java

@ -29,6 +29,8 @@ import java.util.Map;
@Component @Component
public class SendMqMsgUtils { public class SendMqMsgUtils {
private static MqConfig mqConfig; private static MqConfig mqConfig;
private static String requestUrl;
/** /**
* desc:发送mq消息(如果失败重试1次) * desc:发送mq消息(如果失败重试1次)
@ -39,22 +41,23 @@ public class SendMqMsgUtils {
if (mqConfig == null) { if (mqConfig == null) {
mqConfig = SpringContextUtils.getBean(MqConfig.class); mqConfig = SpringContextUtils.getBean(MqConfig.class);
} }
log.info("sendMsg param:{}", JSON.toJSONString(msg)); if (requestUrl == null){
requestUrl = mqConfig.getHost().concat(MqMethodPathEnum.SEND_MSG.getCode());
}
try { try {
ValidatorUtils.validateEntity(msg, DefaultGroup.class); ValidatorUtils.validateEntity(msg, DefaultGroup.class);
} catch (ValidateException e) { } catch (ValidateException e) {
return new Result<String>().error(e.getMsg()); return new Result<String>().error(e.getMsg());
} }
msg.setAppId(mqConfig.getAppId()); msg.setAppId(mqConfig.getAppId());
msg.setRequestUrl(mqConfig.getHost().concat(MqMethodPathEnum.SEND_MSG.getCode()));
msg.setToken(mqConfig.getToken()); msg.setToken(mqConfig.getToken());
try { try {
int retryTime = 0; int retryTime = 0;
Result<String> result = null; Result<String> result = null;
log.info("sendMsg url:{},param:{}", msg.getRequestUrl(), JSON.toJSONString(msg)); log.info("sendMsg url:{},param:{}", requestUrl, JSON.toJSONString(msg));
do { do {
result = HttpClientManager.getInstance().sendPostByHttps(requestUrl, JSON.toJSONString(msg));
retryTime++; retryTime++;
result = HttpClientManager.getInstance().sendPostByHttps(msg.getRequestUrl(), JSON.toJSONString(msg));
log.info("sendMsg retryTime:{},result:{}", retryTime, JSON.toJSONString(result)); log.info("sendMsg retryTime:{},result:{}", retryTime, JSON.toJSONString(result));
} while ((!result.success()) && retryTime < 2); } while ((!result.success()) && retryTime < 2);

Loading…
Cancel
Save