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
producer.initTransactions(); | |
try { | |
producer.beginTransaction(); | |
producer.send(record1); | |
producer.send(record2); | |
producer.commitTransaction(); | |
} catch(ProducerFencedException e) { | |
producer.close(); | |
} catch(KafkaException e) { | |
producer.abortTransaction(); |
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
KStreamBuilder builder = new KStreamBuilder(); | |
KStream<String, String> textLines = builder.stream(stringSerde, stringSerde,"TextLinesTopic"); | |
Pattern pattern = Pattern.compile("\\W+", Pattern.UNICODE_CHARACTER_CLASS); | |
KStream<String, Long> wordCounts = textLines | |
.flatMapValues(value-> Arrays.asList(pattern.split(value.toLowerCase()))) | |
.map((key, word) -> new KeyValue<>(word, word)) | |
.countByKey("Counts") | |
.toStream(); | |
wordCounts.to(stringSerde, longSerde, "WordsWithCountsTopic"); | |
KafkaStreams streams = new KafkaStreams(builder, streamsConfiguration); |