|
@@ -3,7 +3,6 @@ package cn.com.qmth.examcloud.reports.commons.util;
|
|
|
import cn.com.qmth.examcloud.commons.exception.StatusException;
|
|
|
import cn.com.qmth.examcloud.commons.util.ThreadLocalUtil;
|
|
|
import cn.com.qmth.examcloud.reports.commons.bean.BaseReport;
|
|
|
-import cn.com.qmth.examcloud.reports.commons.enums.MqType;
|
|
|
import cn.com.qmth.examcloud.web.bootstrap.PropertyHolder;
|
|
|
import cn.com.qmth.examcloud.web.support.IpUtil;
|
|
|
import cn.com.qmth.examcloud.web.support.ServletUtil;
|
|
@@ -29,29 +28,27 @@ public class ReportsUtil {
|
|
|
|
|
|
private static Producer producer;
|
|
|
|
|
|
- private static String mqType = PropertyHolder.getString("$report.mq-type", "rocketmq");
|
|
|
-
|
|
|
- private static Boolean reportEnable = PropertyHolder.getBoolean("$report.enable", false);
|
|
|
+ private static Boolean reportEnable = PropertyHolder.getBoolean("examcloud.rocketmq.enable", false);
|
|
|
|
|
|
static {
|
|
|
if (reportEnable) {
|
|
|
- if (MqType.ROCKETMQ.getCode().equals(mqType)) {
|
|
|
- Properties properties = new Properties();
|
|
|
- // AccessKeyId 阿里云身份验证,在阿里云服务器管理控制台创建。
|
|
|
- properties.put(PropertyKeyConst.AccessKey, PropertyHolder.getString("$rocketmq-accesskey"));
|
|
|
- // AccessKeySecret 阿里云身份验证,在阿里云服务器管理控制台创建。
|
|
|
- properties.put(PropertyKeyConst.SecretKey, PropertyHolder.getString("$rocketmq-secretkey"));
|
|
|
- // 设置发送超时时间,单位毫秒。
|
|
|
- properties.setProperty(PropertyKeyConst.SendMsgTimeoutMillis, "3000");
|
|
|
- // 设置 TCP 接入域名,进入控制台的实例详情页面的 TCP 协议客户端接入点区域查看。
|
|
|
- properties.put(PropertyKeyConst.NAMESRV_ADDR, PropertyHolder.getString("$rocketmq-namesrv-addr"));
|
|
|
-
|
|
|
- producer = ONSFactory.createProducer(properties);
|
|
|
- // 在发送消息前,必须调用 start 方法来启动 Producer,只需调用一次即可。
|
|
|
- producer.start();
|
|
|
- } else {
|
|
|
- LOG.error("value of property[$report.mq-type] is wrong!");
|
|
|
- }
|
|
|
+ Properties properties = new Properties();
|
|
|
+ // AccessKeyId 阿里云身份验证,在阿里云服务器管理控制台创建。
|
|
|
+ properties.put(PropertyKeyConst.AccessKey, PropertyHolder.getString("examcloud.rocketmq.accesskey"));
|
|
|
+ // AccessKeySecret 阿里云身份验证,在阿里云服务器管理控制台创建。
|
|
|
+ properties.put(PropertyKeyConst.SecretKey, PropertyHolder.getString("examcloud.rocketmq.secretkey"));
|
|
|
+ // 设置发送超时时间,单位毫秒。
|
|
|
+ properties.setProperty(PropertyKeyConst.SendMsgTimeoutMillis, "3000");
|
|
|
+ // 设置 TCP 接入域名,进入控制台的实例详情页面的 TCP 协议客户端接入点区域查看。
|
|
|
+ properties.put(PropertyKeyConst.NAMESRV_ADDR, PropertyHolder.getString("examcloud.rocketmq.namesrv_addr"));
|
|
|
+
|
|
|
+ // 生产组名称
|
|
|
+ properties.put(PropertyKeyConst.GROUP_ID, PropertyHolder.getString("examcloud.rocketmq.producer_group"));
|
|
|
+
|
|
|
+ producer = ONSFactory.createProducer(properties);
|
|
|
+ // 在发送消息前,必须调用 start 方法来启动 Producer,只需调用一次即可。
|
|
|
+ producer.start();
|
|
|
+ LOG.warn("Rocketmq Producer started...");
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -105,9 +102,7 @@ public class ReportsUtil {
|
|
|
}
|
|
|
|
|
|
public static void sendReport(Boolean onException) {
|
|
|
- if (MqType.ROCKETMQ.getCode().equals(mqType)) {
|
|
|
- sendReportRocket(onException);
|
|
|
- }
|
|
|
+ sendReportRocket(onException);
|
|
|
}
|
|
|
|
|
|
private static void setReportCommonData(BaseReport report) {
|
|
@@ -124,10 +119,11 @@ public class ReportsUtil {
|
|
|
}
|
|
|
|
|
|
public static String getReportTopic() {
|
|
|
- String topic = PropertyHolder.getString("$report.mq-topic");
|
|
|
+ String topic = PropertyHolder.getString("examcloud.rocketmq.topic");
|
|
|
if (StringUtils.isBlank(topic)) {
|
|
|
- throw new StatusException("$report.mq-topic 未配置");
|
|
|
+ throw new StatusException("examcloud.rocketmq.topic 未配置");
|
|
|
}
|
|
|
return topic;
|
|
|
}
|
|
|
+
|
|
|
}
|