|
@@ -1,13 +1,10 @@
|
|
|
package com.hhwy.qbeqsjy.kafka.service;
|
|
|
|
|
|
-import com.alibaba.fastjson.JSONArray;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
-import com.hhwy.qbeqsjy.common.CommonUtil;
|
|
|
import com.hhwy.qbeqsjy.common.Constants;
|
|
|
import com.hhwy.qbeqsjy.common.TimeTool;
|
|
|
import com.hhwy.qbeqsjy.dao.CtrlDao;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
-import org.apache.commons.lang3.StringUtils;
|
|
|
import org.apache.kafka.clients.consumer.ConsumerRecord;
|
|
|
import org.apache.kafka.clients.consumer.ConsumerRecords;
|
|
|
import org.apache.kafka.clients.consumer.KafkaConsumer;
|
|
@@ -16,12 +13,10 @@ import org.springframework.context.ApplicationListener;
|
|
|
import org.springframework.context.event.ContextRefreshedEvent;
|
|
|
import org.springframework.scheduling.annotation.EnableScheduling;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
-
|
|
|
import javax.annotation.Resource;
|
|
|
import java.io.IOException;
|
|
|
import java.util.ArrayList;
|
|
|
import java.util.Collections;
|
|
|
-import java.util.Date;
|
|
|
import java.util.List;
|
|
|
|
|
|
|
|
@@ -61,19 +56,19 @@ public class ConsumeService implements ApplicationListener<ContextRefreshedEvent
|
|
|
log.info("kafka集群已开启安全模式");
|
|
|
AuthService.securityPrepare();
|
|
|
} catch (IOException e) {
|
|
|
- log.error("kafka集群安全认证失败!异常信息 : {}.", e);
|
|
|
+ log.error("kafka集群安全认证失败,异常信息 : {}.", e);
|
|
|
return;
|
|
|
}
|
|
|
log.info("kafka集群安全认证成功");
|
|
|
}
|
|
|
AuthService consumerAuthService = new AuthService(topic);
|
|
|
- log.info("【QBEQSJYCTRL】 消费者服务已启动");
|
|
|
+ log.info("【QBEQSJYCTRL - 消费者服务】 服务已启动");
|
|
|
process(consumerAuthService.consumer, topic);
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
- * 消费目标topic中预警结果数据
|
|
|
+ * 消费目标topic中的预警结果数据,处理后批量入库
|
|
|
* @param consumer
|
|
|
* @param topic
|
|
|
*/
|
|
@@ -83,29 +78,16 @@ public class ConsumeService implements ApplicationListener<ContextRefreshedEvent
|
|
|
while (true) {
|
|
|
|
|
|
ConsumerRecords<Integer, String> records = consumer.poll(Constants.WAIT_TIME);
|
|
|
-
|
|
|
+
|
|
|
if (records != null && records.count() > 0) {
|
|
|
- Date createTime = new Date();
|
|
|
for (ConsumerRecord<Integer, String> record : records) {
|
|
|
JSONObject message = JSONObject.parseObject(record.value());
|
|
|
|
|
|
-
|
|
|
+
|
|
|
JSONObject oriField = message.getJSONObject("ORIFIELD");
|
|
|
- String baseStationId = oriField.getString("BASE_STATION_ID");
|
|
|
-
|
|
|
- if (StringUtils.isBlank(baseStationId)) {
|
|
|
- continue;
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
- String lon = oriField.getString("LONGITUDE");
|
|
|
- String lat = oriField.getString("LATITUDE");
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
+
|
|
|
+ String warningInfoJSONStr = oriField.toJSONString();
|
|
|
+
|
|
|
JSONObject uniCtrl = message.getJSONObject("UNICTRL");
|
|
|
|
|
|
String clueId = uniCtrl.getString("U_CLUEID");
|
|
@@ -113,17 +95,16 @@ public class ConsumeService implements ApplicationListener<ContextRefreshedEvent
|
|
|
String taskId = clueIdStrArr[Constants.NUM_1];
|
|
|
String clueType = clueIdStrArr[Constants.NUM_2];
|
|
|
String clue = clueIdStrArr[Constants.NUM_3];
|
|
|
- String warningInfoJSONStr = message.toJSONString();
|
|
|
- String resourceId = uniCtrl.getString("U_RESID");
|
|
|
- String captureTime = TimeTool.timeStampToDateString(Long.valueOf(oriField.getString("CAPTURE_TIME")));
|
|
|
- Object[] warningInfo = new Object[]{taskId, clue, clueType, warningInfoJSONStr, createTime};
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ String captureTime = TimeTool.timeStampToDateString(TimeTool.getNowTimeStamp());
|
|
|
+ Object[] warningInfo = new Object[]{taskId, clue, clueType, warningInfoJSONStr, captureTime};
|
|
|
warningInfoList.add(warningInfo);
|
|
|
-
|
|
|
-
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
ctrlDao.batchInsertWarningInfo(warningInfoList);
|
|
|
- log.info("【QBEQSJYCTRL - 消费者】 已消费数据量:{}", warningInfoList.size());
|
|
|
+ log.info("【QBEQSJYCTRL - 消费者服务】 当次消费的数据量:{}", warningInfoList.size());
|
|
|
warningInfoList.clear();
|
|
|
}
|
|
|
}
|