// Collection of code snippets by Arne Vajhøj 
// (from articles on eksperten.dk / vajhoej.dk written sometime between 2004 and now) 
package kafka;

import java.util.Properties;

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

public class KProducer {
    private static final String SERVER = "localhost:9092";
    private static final String TNAME = "TestT";
    private static final String PAYLOAD = "<data>\r\n    <id>123</id>\r\n    <name>ABC</name>\r\n</data>";
    public static void main(String[] args) {
         Properties props = new Properties();
         props.put("bootstrap.servers", SERVER);
         props.put("key.serializer", "org.apache.kafka.common.serialization.IntegerSerializer");
         props.put("value.serializer", "org.apache.kafka.common.serialization.StringSerializer");
         Producer<Integer, String> sender = new KafkaProducer<Integer, String>(props);
         for(int i = 0; i < 3; i++) {
             sender.send(new ProducerRecord<Integer, String>(TNAME, i, PAYLOAD));
         }
         sender.flush();
         sender.close();
    }
}
