Created
December 25, 2018 09:51
-
-
Save john-nash-rs/cc4db1902b6a6620192e47ccbfaecdb8 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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