|
|
@ -1,38 +1,27 @@ |
|
|
package cn.iocoder.yudao.module.mqtt.kafka; |
|
|
package cn.iocoder.yudao.module.mqtt.kafka; |
|
|
|
|
|
|
|
|
import cn.iocoder.yudao.module.mqtt.processor.BatchDeviceMessageProcessor; |
|
|
import cn.iocoder.yudao.module.mqtt.processor.BatchDeviceMessageProcessor; |
|
|
import cn.iocoder.yudao.module.mqtt.processor.DeviceMessageProcessor; |
|
|
|
|
|
import cn.iocoder.yudao.module.mqtt.processor.HandAlarmMessageProcess; |
|
|
|
|
|
|
|
|
import cn.iocoder.yudao.module.mqtt.processor.HandAlarmMessageProcessor; |
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
import org.apache.kafka.clients.consumer.ConsumerRecord; |
|
|
import org.apache.kafka.clients.consumer.ConsumerRecord; |
|
|
import org.springframework.beans.factory.annotation.Qualifier; |
|
|
|
|
|
import org.springframework.core.task.TaskExecutor; |
|
|
|
|
|
import org.springframework.kafka.annotation.KafkaListener; |
|
|
import org.springframework.kafka.annotation.KafkaListener; |
|
|
import org.springframework.kafka.core.KafkaTemplate; |
|
|
|
|
|
import org.springframework.kafka.support.Acknowledgment; |
|
|
|
|
|
import org.springframework.kafka.support.KafkaHeaders; |
|
|
|
|
|
import org.springframework.messaging.handler.annotation.Header; |
|
|
|
|
|
import org.springframework.messaging.handler.annotation.Payload; |
|
|
|
|
|
import org.springframework.stereotype.Service; |
|
|
import org.springframework.stereotype.Service; |
|
|
|
|
|
|
|
|
import java.util.List; |
|
|
import java.util.List; |
|
|
import java.util.concurrent.CompletableFuture; |
|
|
|
|
|
import java.util.stream.Collectors; |
|
|
|
|
|
import java.util.stream.IntStream; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Slf4j |
|
|
@Slf4j |
|
|
@Service // <--- 添加这个注解!
|
|
|
@Service // <--- 添加这个注解!
|
|
|
public class KafkaMessageConsumer { |
|
|
public class KafkaMessageConsumer { |
|
|
private final HandAlarmMessageProcess handAlarmMessageProcess; |
|
|
|
|
|
|
|
|
private final HandAlarmMessageProcessor handAlarmMessageProcessor; |
|
|
|
|
|
|
|
|
private final BatchDeviceMessageProcessor batchDeviceMessageProcessor; |
|
|
private final BatchDeviceMessageProcessor batchDeviceMessageProcessor; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public KafkaMessageConsumer(HandAlarmMessageProcess handAlarmMessageProcess, |
|
|
|
|
|
|
|
|
public KafkaMessageConsumer(HandAlarmMessageProcessor handAlarmMessageProcessor, |
|
|
BatchDeviceMessageProcessor batchDeviceMessageProcessor) { |
|
|
BatchDeviceMessageProcessor batchDeviceMessageProcessor) { |
|
|
this.handAlarmMessageProcess = handAlarmMessageProcess; |
|
|
|
|
|
|
|
|
this.handAlarmMessageProcessor = handAlarmMessageProcessor; |
|
|
this.batchDeviceMessageProcessor = batchDeviceMessageProcessor; |
|
|
this.batchDeviceMessageProcessor = batchDeviceMessageProcessor; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
@ -67,7 +56,7 @@ public class KafkaMessageConsumer { |
|
|
// 遍历 List,一条条处理
|
|
|
// 遍历 List,一条条处理
|
|
|
for (ConsumerRecord<String, String> record : records) { |
|
|
for (ConsumerRecord<String, String> record : records) { |
|
|
try { |
|
|
try { |
|
|
handAlarmMessageProcess.processSingle(record.value()); |
|
|
|
|
|
|
|
|
handAlarmMessageProcessor.processSingle(record.value()); |
|
|
|
|
|
|
|
|
} catch (Exception e) { |
|
|
} catch (Exception e) { |
|
|
log.error("单条消息处理失败,已跳过。Key: {}, Value: {}", record.key(), record.value(), e); |
|
|
log.error("单条消息处理失败,已跳过。Key: {}, Value: {}", record.key(), record.value(), e); |
|
|
|