DeviceAddressProducer.java
1.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
package com.glsx.smart.config;
import com.alibaba.fastjson.JSON;
import com.glsx.smart.constant.Constants;
import com.glsx.smart.pojo.DeviceMessage;
import lombok.extern.slf4j.Slf4j;
import org.springframework.kafka.core.KafkaTemplate;
import org.springframework.stereotype.Component;
import javax.annotation.Resource;
/**
* @author think.wang
* @version 1.0.0
* @Title DeviceAddressProducer
* @Package com.glsx.smart.config
* @Description 设备围栏数据kafka推送
* @date 2021/4/11
*/
@Slf4j
@Component
public class DeviceAddressProducer {
@Resource
private KafkaTemplate kafkaTemplate;
/**
* 推送设备经纬度数据
* @param deviceId
* @param lngAndLat
* @param type 1新增 2更新 3删除
*/
public void pushUserDeviceData(String deviceId, String lngAndLat, Integer type) {
//kafka 发送消息数据封装
DeviceMessage message = new DeviceMessage();
message.setDeviceId(deviceId);
message.setLngAndLat(lngAndLat);
message.setType(type);
log.info("推送kafka topic【{}】的数据:{}", Constants.DEVICE_DATA_TOPIC, message.toString());
//推送kafka
kafkaTemplate.send(Constants.DEVICE_DATA_TOPIC, JSON.toJSONString(message));
}
}