package com.cisdi.dsp.modules.metaAnalysis.rest.kafka2023;



import org.apache.kafka.clients.producer.*;
import org.apache.kafka.common.serialization.StringSerializer;

import java.time.Duration;
import java.util.Properties;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;

public class KafkaTest02 {
    public static void main(String[] args) {
        System.out.println(StringSerializer.class.getName());
        Properties properties= new Properties();

        properties.setProperty(ProducerConfig.KEY_SERIALIZER_CLASS_CONFIG, StringSerializer.class.getName());
        properties.setProperty(ProducerConfig.VALUE_SERIALIZER_CLASS_CONFIG, StringSerializer.class.getName());
        properties.setProperty(ProducerConfig.BOOTSTRAP_SERVERS_CONFIG,"xxx.xxx.xxx.xxx:9092");
        KafkaProducer<String,String> kafkaProducer=new KafkaProducer<String, String>(properties);
        ProducerRecord<String,String> producerRecord=new ProducerRecord<>("paul","hello ,Miss Cloud");
        kafkaProducer.send(producerRecord, (RecordMetadata metadata, Exception exception) -> {
                System.out.println(metadata.offset());
                System.out.println(metadata.topic());
            } );


        //kafkaProducer.close();
        kafkaProducer.close(Duration.ofMillis(5000));
    }
}