diff --git a/hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/mqtt/MqttConfig.java b/hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/mqtt/MqttConfig.java index 860785f..facb306 100644 --- a/hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/mqtt/MqttConfig.java +++ b/hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/mqtt/MqttConfig.java @@ -3,6 +3,7 @@ package com.hnac.hzims.alarm.mqtt; import com.hnac.hzinfo.subscribe.AnalysisSubscribe; import com.hnac.hzinfo.subscribe.DroolsSoeSubscribe; import com.hnac.hzinfo.subscribe.HZ3000SoeSubscribe; +import com.hnac.hzinfo.subscribe.SoeSubscribe; import lombok.extern.slf4j.Slf4j; import org.eclipse.paho.client.mqttv3.MqttAsyncClient; import org.eclipse.paho.client.mqttv3.MqttException; @@ -27,6 +28,8 @@ public class MqttConfig { DroolsMqttConsumer droolsMqttConsumer; @Autowired HZ300MqttConsumer hz300MqttConsumer; + @Autowired + VideoMqttConsumer videoMqttConsumer; @Value("${hzims.mqtt.url}") private String mqtt_fdp_url; @Value("${hzims.mqtt.group}") @@ -61,6 +64,10 @@ public class MqttConfig { HZ3000SoeSubscribe hz3000SoeSubscribe = new HZ3000SoeSubscribe(); MqttAsyncClient hz3000Client = hz3000SoeSubscribe.subscribe(mqttConfig, Collections.singletonList("#"), hz300MqttConsumer); log.info(hz3000Client.toString()); + //视频 + SoeSubscribe subscribe = new SoeSubscribe(); + MqttAsyncClient videoClient = subscribe.subscribe(mqttConfig, Collections.singletonList("#"), videoMqttConsumer); + log.info(videoClient.toString()); }catch (MqttException e){ log.error(e.toString()) ; } diff --git a/hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/mqtt/VideoMqttConsumer.java b/hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/mqtt/VideoMqttConsumer.java new file mode 100644 index 0000000..e42bfa3 --- /dev/null +++ b/hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/mqtt/VideoMqttConsumer.java @@ -0,0 +1,40 @@ +package com.hnac.hzims.alarm.mqtt; + +import com.alibaba.fastjson.JSONObject; +import com.hnac.hzims.alarm.entity.AlarmEntity; +import com.hnac.hzims.alarm.handle.service.VideoAlarmService; +import com.hnac.hzims.alarm.monitor.service.AlarmSaveService; +import com.hnac.hzinfo.subscribe.SubscribeCallBack; +import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import java.util.List; +import java.util.Map; + +/** + * + * @Author: ty + */ + +@Service +@Slf4j +public class VideoMqttConsumer implements SubscribeCallBack { + @Autowired + private VideoAlarmService videoAlarmService; + @Autowired + private AlarmSaveService alarmSaveService; + @Override + public void onMessage(Map data) { + System.out.println("监听到消息"+data.toString()); + String s = JSONObject.toJSONString(data); + //消费代码 + List alarmEntities = videoAlarmService.receiveMessage(s); + //统一数据处理 + try { + alarmSaveService.save(alarmEntities); + }catch (Exception e){ + log.error("HZ3000告警数据处理报错(HZ300Alarm):"+e); + } + } +}