package com.mosty.common.core.util;

//import org.apache.kafka.clients.producer.ProducerConfig;
//import org.apache.kafka.common.serialization.StringSerializer;
//import org.springframework.beans.factory.annotation.Value;
//import org.springframework.context.annotation.Bean;
//import org.springframework.context.annotation.Configuration;
//import org.springframework.kafka.core.DefaultKafkaProducerFactory;
//import org.springframework.kafka.core.KafkaTemplate;
//import org.springframework.kafka.core.ProducerFactory;
//
//import java.util.HashMap;
//import java.util.Map;
//
//@Configuration
public class KafkaProducerConfig {
////    @Value("${spring.kafka.bootstrap-servers}")
//    private static String servers = "82.157.32.48:9092";
////    @Value("${spring.kafka.producer.retries}")
//    private static int retries = 0;
////    @Value("${spring.kafka.producer.acks}")
//    private static String acks = "1";
////    @Value("${spring.kafka.producer.batch-size}")
//    private static int batchSize = 16384;
////    @Value("${spring.kafka.producer.properties.linger.ms}")
//    private static int linger = 0;
////    @Value("${spring.kafka.producer.buffer-memory}")
//    private static int bufferMemory = 33554432;
//
//    public static Map<String, Object> producerConfigs() {
//        Map<String, Object> props = new HashMap<>();
//        props.put(ProducerConfig.BOOTSTRAP_SERVERS_CONFIG, servers);
//        props.put(ProducerConfig.RETRIES_CONFIG, retries);
//        props.put(ProducerConfig.ACKS_CONFIG, acks);
//        props.put(ProducerConfig.BATCH_SIZE_CONFIG, batchSize);
//        props.put(ProducerConfig.LINGER_MS_CONFIG, linger);
//        props.put(ProducerConfig.BUFFER_MEMORY_CONFIG, bufferMemory);
//        props.put(ProducerConfig.KEY_SERIALIZER_CLASS_CONFIG, StringSerializer.class);
//        props.put(ProducerConfig.VALUE_SERIALIZER_CLASS_CONFIG, StringSerializer.class);
//        return props;
//    }
//
//    public static ProducerFactory<String, Object> producerFactory() {
//        return new DefaultKafkaProducerFactory<>(producerConfigs());
//    }
//
////    @Bean
//    public static KafkaTemplate<String, Object> kafkaTemplate() {
//        KafkaTemplate template = new KafkaTemplate<String, Object>(producerFactory());
//        template.setDefaultTopic("platform-log1"); // 设置默认的 topic
//        return template;
//    }
//
//    public static void main(String[] args) {
//        KafkaTemplate<String, Object> template = KafkaProducerConfig.kafkaTemplate();
//        template.setDefaultTopic("2022-09-16---aaaaaaaaaaaaa");
//        template.send("platform-log1", "2022-09-16---bbbbbbbbbbb").addCallback(success -> {
//                    // 消息发送到的topic
//                    String topic = success.getRecordMetadata().topic();
//                    // 消息发送到的分区
//                    int partition = success.getRecordMetadata().partition();
//                    // 消息在分区内的offset
//                    long offset = success.getRecordMetadata().offset();
//                    System.out.println("发送消息成功:" + topic + "-" + partition + "-" + offset);
//                }, failure -> {
//                    System.out.println("发送消息失败:" + failure.getMessage());
//                });
//    }

}