//package com.jay.monitor.data.client.ext.kafka.consumer;
//
//import com.jay.monitor.data.client.MonitorSendProducer;
//import com.jay.monitor.data.client.ext.MonitorRuleFactory;
//import com.jay.monitor.data.client.utils.MonitorUtils;
//import com.jay.monitor.data.core.model.serializable.MQDataDTO;
//import org.apache.kafka.clients.consumer.ConsumerRecord;
//import org.slf4j.Logger;
//import org.slf4j.LoggerFactory;
//import org.springframework.kafka.listener.AcknowledgingMessageListener;
//import org.springframework.kafka.support.Acknowledgment;
//
///**
// * @Module 监听器
// * @Description kafka监控消费者监听器
// * @Author liukaixiong
// * @Date 2020/10/27 19:14
// */
//public class KafkaMonitorConsumerListener implements AcknowledgingMessageListener<String, String> {
//    private Logger logger = LoggerFactory.getLogger(getClass());
//
//    private MonitorRuleFactory monitorRuleFactory;
//
//    public AcknowledgingMessageListener listener;
//
//    public KafkaMonitorConsumerListener(AcknowledgingMessageListener listener, MonitorRuleFactory monitorRuleFactory) {
//        this.listener = listener;
//    }
//
//    @Override
//    public void onMessage(ConsumerRecord<String, String> data, Acknowledgment acknowledgment) {
//        try {
//            listener.onMessage(data, acknowledgment);
//            // todo 不在一个事务消息内，无法获取准确的LOGId
//            sendMonitorData(data, 1);
//        } catch (Exception e) {
//            sendMonitorData(data, -1);
//            throw e;
//        }
//    }
//
//    private void sendMonitorData(ConsumerRecord<String, String> data, Integer status) {
//        MQDataDTO mqDataDTO = MonitorUtils.builderConsumerMqDataDTO(data.topic(), data.key(), data.partition() + "", data.offset(), data.value(), status);
//        MonitorSendProducer.sendMsg(data.topic(), mqDataDTO);
//    }
//}
