//package com.jay.monitor.data.client.ext.kafka;
//
//import com.jay.monitor.data.client.MonitorSendProducer;
//import com.jay.monitor.data.client.utils.MonitorUtils;
//import com.jay.monitor.data.core.model.serializable.MQDataDTO;
//import org.apache.kafka.clients.producer.RecordMetadata;
//import org.slf4j.Logger;
//import org.slf4j.LoggerFactory;
//import org.springframework.beans.factory.InitializingBean;
//import org.springframework.kafka.support.ProducerListener;
//import org.springframework.stereotype.Component;
//
///**
// * @Module 生产者监听器
// * @Description kafka发送的时候会回调该接口告诉你成功或者失败
// * @Author liukaixiong
// * @Date 2020/10/29 16:10
// */
//@Component
//public class KafkaMonitorProducer implements ProducerListener<String, String>, InitializingBean {
//    private Logger logger = LoggerFactory.getLogger(getClass());
//
//    @Override
//    public void onSuccess(String topic, Integer partition, String key, String value, RecordMetadata recordMetadata) {
//        try {
//            MQDataDTO mq = MonitorUtils.builderProducerMqDataDTO(topic, topic, partition + "", recordMetadata.offset(), value, 1);
//            MonitorSendProducer.sendMsg(topic, mq);
//        } catch (Exception e) {
//            logger.warn("success监控发送器发送失败" + e.getMessage());
//        }
//    }
//
//    @Override
//    public void onError(String topic, Integer partition, String key, String value, Exception exception) {
//        try {
//            MQDataDTO mq = MonitorUtils.builderProducerMqDataDTO(topic, topic, partition + "", null, value, -1);
//            MonitorSendProducer.sendMsg(topic, mq);
//        } catch (Exception e) {
//            logger.warn("error监控发送器发送失败 :" + e.getMessage());
//        }
//    }
//
//    @Override
//    public void afterPropertiesSet() throws Exception {
//
//    }
//}
