package cn.com.taiji.track.consumer;

import cn.com.taiji.track.service.IBeidouTrackService;
import cn.com.taiji.track.service.IWarningRecordService;
import lombok.extern.slf4j.Slf4j;
import org.apache.kafka.clients.consumer.ConsumerRecord;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.kafka.annotation.KafkaListener;
import org.springframework.kafka.support.Acknowledgment;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * 消费预警记录
 * @author kok20
 */
@Component
@Slf4j
@ConditionalOnProperty(name = "taiji.kafka.consumer.beidou.enable",havingValue = "true")
public class BeidouWarningRecordConsumer {

    @Autowired
    private IWarningRecordService warningRecordService;

    @KafkaListener(
            groupId = "${taiji.kafka.consumer.warning.group}",
            topics = {"${taiji.kafka.consumer.warning.topic}"}
    )
    public void consumer(List<ConsumerRecord<?, ?>> records, Acknowledgment ack) {
        warningRecordService.warningRecordToCache(records);
        ack.acknowledge();
    }
}
