package com.tievd.jyz.kafka;
|
|
import com.alibaba.fastjson.JSON;
|
import com.alibaba.fastjson.JSONObject;
|
import com.tievd.jyz.dto.CaptureVehicleDTO;
|
import com.tievd.jyz.handler.CameraIdentifyHandler;
|
import lombok.extern.slf4j.Slf4j;
|
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.kafka.annotation.KafkaListener;
|
import org.springframework.kafka.support.Acknowledgment;
|
import org.springframework.stereotype.Component;
|
|
/**
|
* 进出口高速摄像头抓拍数据监听(使用大数据GA1400数据中台中转)
|
* @author Wang
|
*/
|
@Slf4j
|
@Component
|
public class MqKafkaListener {
|
|
public static final String KAFKA_TOPIC_SEMI_VEHICLE = "semi-vehicle";
|
|
@Autowired
|
CameraIdentifyHandler cameraIdentifyHandler;
|
|
/**
|
* 订阅车辆抓拍数据
|
* @param message
|
* @param ack 手动提交
|
*/
|
@KafkaListener(topics = KAFKA_TOPIC_SEMI_VEHICLE)
|
public void deviceRegister(final String message, Acknowledgment ack) {
|
try{
|
log.info("接收到车辆抓拍数据:" + message);
|
CaptureVehicleDTO captureVehicleDTO = JSON.toJavaObject(JSONObject.parseObject(message), CaptureVehicleDTO.class);
|
log.info("captureVehicleDTO:" + captureVehicleDTO);
|
//TODO
|
cameraIdentifyHandler.handle(captureVehicleDTO);
|
}catch (Exception ex){
|
log.error(ex.getMessage(),ex);
|
}finally {
|
ack.acknowledge();
|
}
|
}
|
}
|