Last active
September 11, 2019 05:22
-
-
Save LearningJournal/6fdd78a8fb8f7579c4278ab07b2442cf 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
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") | |
) |
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
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