Created
October 9, 2019 13:45
-
-
Save recursivecodes/fe0ed9c857a9f96ba266fa3821edc906 to your computer and use it in GitHub Desktop.
CompatibleProducer.java
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
KafkaProducer producer = new KafkaProducer<>(properties); | |
for (int i = 0; i < 5; i++) { | |
ProducerRecord<String, String> record = new ProducerRecord<>(topicName, UUID.randomUUID().toString(), "Test record #" + i); | |
producer.send(record, (md, ex) -> { | |
if( ex != null ) { | |
ex.printStackTrace(); | |
} | |
else { | |
System.out.println( | |
"Sent msg to " | |
+ md.partition() | |
+ " with offset " | |
+ md.offset() | |
+ " at " | |
+ md.timestamp() | |
); | |
} | |
}); | |
} | |
producer.flush(); | |
producer.close(); | |
System.out.println("produced 5 messages"); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment