优化级联平台GPS订阅

This commit is contained in:
lin
2022-01-08 17:35:00 +08:00
parent ddb36e54bd
commit abb60593cb
9 changed files with 100 additions and 5 deletions

View File

@@ -0,0 +1,39 @@
package com.genersoft.iot.vmp.service;
import com.genersoft.iot.vmp.service.bean.GPSMsgInfo;
import com.genersoft.iot.vmp.storager.IRedisCatchStorage;
import com.genersoft.iot.vmp.storager.IVideoManagerStorager;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import java.util.List;
/**
* 定时查找redis中的GPS推送消息并保存到对应的流中
*/
@Component
public class StreamGPSSubscribeTask {
@Autowired
private IRedisCatchStorage redisCatchStorage;
@Autowired
private IVideoManagerStorager storager;
@Scheduled(fixedRate = 30 * 1000) //每30秒执行一次
public void execute(){
List<GPSMsgInfo> gpsMsgInfo = redisCatchStorage.getAllGpsMsgInfo();
if (gpsMsgInfo.size() > 0) {
storager.updateStreamGPS(gpsMsgInfo);
for (GPSMsgInfo msgInfo : gpsMsgInfo) {
msgInfo.setStored(true);
redisCatchStorage.updateGpsMsgInfo(msgInfo);
}
}
}
}

View File

@@ -37,6 +37,8 @@ public class GPSMsgInfo {
*/
private String altitude;
private boolean stored;
public String getId() {
return id;
@@ -93,4 +95,12 @@ public class GPSMsgInfo {
public void setAltitude(String altitude) {
this.altitude = altitude;
}
public boolean isStored() {
return stored;
}
public void setStored(boolean stored) {
this.stored = stored;
}
}

View File

@@ -17,7 +17,6 @@ public class RedisGPSMsgListener implements MessageListener {
@Override
public void onMessage(Message message, byte[] bytes) {
GPSMsgInfo gpsMsgInfo = JSON.parseObject(message.getBody(), GPSMsgInfo.class);
System.out.println(JSON.toJSON(gpsMsgInfo));
redisCatchStorage.updateGpsMsgInfo(gpsMsgInfo);
}
}