Modulo_1-TratamientoDato/Kafka/Ejercicios/edem2021/1-kakfa-producer-consumer-api/src/main/java/com/gft/dlp/kafka/Producer.java
package com.gft.dlp.kafka;

import org.apache.kafka.clients.producer.KafkaProducer;
import org.apache.kafka.clients.producer.ProducerRecord;

import java.util.Properties;

public class Producer {

    public static void main(String[] args){
        Properties properties = new Properties();
        properties.put("bootstrap.servers", "localhost:9092");
        properties.put("key.serializer", "org.apache.kafka.common.serialization.StringSerializer");
        properties.put("value.serializer", "org.apache.kafka.common.serialization.StringSerializer");

        KafkaProducer<String, String> kafkaProducer = new KafkaProducer<String, String>(properties);
        try{
            for(int i = 0; i < 100; i++){
                int value = i*4;
                System.out.println(i);
                kafkaProducer.send(new ProducerRecord<String, String>("myTopic", Integer.toString(i), "test message - " + value));
            }
        }catch (Exception e){
            e.printStackTrace();
        }finally {
            kafkaProducer.close();
        }
    }
}