Skip to content

Instantly share code, notes, and snippets.

@john-nash-rs
Created December 25, 2018 09:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save john-nash-rs/cc4db1902b6a6620192e47ccbfaecdb8 to your computer and use it in GitHub Desktop.
Save john-nash-rs/cc4db1902b6a6620192e47ccbfaecdb8 to your computer and use it in GitHub Desktop.
package com.wp.npe.client;
import java.util.Properties;
import com.sun.tools.internal.xjc.reader.xmlschema.bindinfo.BIConversion;
import org.apache.kafka.clients.producer.KafkaProducer;
import org.apache.kafka.clients.producer.Producer;
import org.apache.kafka.clients.producer.ProducerRecord;
public class KafkaProducerAPI {
Properties props = new Properties();
public static final String TOPIC = "bulk";
public KafkaProducerAPI() {
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");
}
public void send(String key, String value){
Producer<String, String> producer = new KafkaProducer<String, String>(props);
producer.send(new ProducerRecord<String, String>(TOPIC,
key, value));
System.out.println("Message sent successfully");
producer.close();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment