public class Kafkaproducerdemo {public static void main (string[] args) throws Interruptedexception {/* Properties props = New Properties (); * Props.put ("Bootstrap.servers", "localhost:9092"); * Props.put ("ACKs", "all"); * Props.put ("retries", 0); * Props.put ("batch.size", 16384); * Props.put ("linger.ms", 1); * Props.put ("buffer.memory", 33554432); * Props.put ("Key.serializer", "Org.apache.kafka.common.serialization.StringSerializer"); * Props.put ("Value.serializer", "Org.apache.kafka.common.serialization.StringSerializer"); */map<string, object> config = new hashmap<string, object> (); Config.put ("Key.serializer", " Org.apache.kafka.common.serialization.StringSerializer "); Config.put (" Value.serializer "," Org.apache.kafka.common.serialization.StringSerializer "); Config.put (" Bootstrap.servers "," m2:9092 "); producer<string, string> Producer = new kafkaproducer<string, string> (config);//Send Business message//Read file read memory database Read socket port for (int i = 1; i <=; i++) {Thread.Sleep ($);pRoducer.send (New producerrecord<string, string> ("test2", I + ""));}}}
Kafka producer Java Code