Skip to content

Instantly share code, notes, and snippets.

@LearningJournal
Last active September 11, 2019 05:22
Show Gist options
  • Save LearningJournal/6fdd78a8fb8f7579c4278ab07b2442cf to your computer and use it in GitHub Desktop.
Save LearningJournal/6fdd78a8fb8f7579c4278ab07b2442cf to your computer and use it in GitHub Desktop.
name := "KafkaTest"
libraryDependencies ++= Seq(
"org.apache.kafka" % "kafka-clients" % "0.10.1.0"
exclude("javax.jms", "jms")
exclude("com.sun.jdmk", "jmxtools")
exclude("com.sun.jmx", "jmxri")
exclude("org.slf4j", "slf4j-simple")
)
import java.util.*;
import org.apache.kafka.clients.producer.*;
public class SimpleProducer {
public static void main(String[] args) throws Exception{
String key = "Key1";
String value = "Value-1";
String topicName = "SimpleProducerTopic";
Properties props = new Properties();
props.put("bootstrap.servers", "localhost:9092,localhost:9093");
props.put("key.serializer","org.apache.kafka.common.serialization.StringSerializer");
props.put("value.serializer", "org.apache.kafka.common.serialization.StringSerializer");
Producer<String, String> producer = new KafkaProducer<>(props);
ProducerRecord<String, String> record = new ProducerRecord<>(topicName,key,value);
producer.send(record);
producer.close();
System.out.println("SimpleProducer Completed.");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment