|
@@ -17,14 +17,16 @@ import com.aliyun.openservices.ons.api.PropertyKeyConst;
|
|
|
import cn.com.qmth.examcloud.core.basic.service.AdminOperateService;
|
|
|
import cn.com.qmth.examcloud.reports.commons.bean.AdminOperateReport;
|
|
|
import cn.com.qmth.examcloud.reports.commons.enums.Tag;
|
|
|
-import cn.com.qmth.examcloud.reports.commons.enums.Topic;
|
|
|
+import cn.com.qmth.examcloud.reports.commons.util.ReportsUtil;
|
|
|
import cn.com.qmth.examcloud.web.bootstrap.PropertyHolder;
|
|
|
import cn.com.qmth.examcloud.web.support.SpringContextHolder;
|
|
|
|
|
|
public class RocketMqConsumerListener {
|
|
|
+
|
|
|
private static final Logger LOG = LoggerFactory.getLogger(RocketMqConsumerListener.class);
|
|
|
|
|
|
private static AdminOperateService adminOperateService = SpringContextHolder.getBean(AdminOperateService.class);
|
|
|
+
|
|
|
private static Properties properties = new Properties();
|
|
|
|
|
|
static {
|
|
@@ -42,18 +44,19 @@ public class RocketMqConsumerListener {
|
|
|
}
|
|
|
|
|
|
public static void start() {
|
|
|
- adminOperate();
|
|
|
+ adminOperate();
|
|
|
}
|
|
|
|
|
|
private static void adminOperate() {
|
|
|
properties.put(PropertyKeyConst.GROUP_ID, Tag.ADMIN_OPERATE_INFO.getGroup());
|
|
|
Consumer consumer = ONSFactory.createConsumer(properties);
|
|
|
- consumer.subscribe(Topic.REPORT_TOPIC.getCode(), Tag.ADMIN_OPERATE_INFO.getCode(), new MessageListener() {
|
|
|
+ consumer.subscribe(ReportsUtil.getReportTopic(), Tag.ADMIN_OPERATE_INFO.getCode(), new MessageListener() {
|
|
|
+
|
|
|
@Override
|
|
|
public Action consume(Message message, ConsumeContext context) {
|
|
|
try {
|
|
|
String msg = new String(message.getBody(), "utf-8");
|
|
|
- onMessageAdminOperate(msg,message.getMsgID());
|
|
|
+ onMessageAdminOperate(msg, message.getMsgID());
|
|
|
return Action.CommitMessage;
|
|
|
} catch (Exception e) {
|
|
|
LOG.error("consumer failed MsgID:" + message.getMsgID(), e);
|
|
@@ -66,8 +69,8 @@ public class RocketMqConsumerListener {
|
|
|
consumer.start();
|
|
|
}
|
|
|
|
|
|
- private static void onMessageAdminOperate(String message,String msgId) {
|
|
|
- AdminOperateReport r = JSON.parseObject(message, AdminOperateReport.class);
|
|
|
+ private static void onMessageAdminOperate(String message, String msgId) {
|
|
|
+ AdminOperateReport r = JSON.parseObject(message, AdminOperateReport.class);
|
|
|
adminOperateService.saveOperate(r, msgId);
|
|
|
}
|
|
|
}
|