From: Kai Moritz Date: Sat, 4 Feb 2023 09:46:03 +0000 (+0100) Subject: recorder: 1.1.0 - recordings are sent as JSON X-Git-Tag: recorder-1.1.0 X-Git-Url: http://juplo.de/gitweb/?a=commitdiff_plain;h=22615ba45bd7697e041eb10f88166cd2074de305;p=demos%2Fkafka%2Fwordcount recorder: 1.1.0 - recordings are sent as JSON --- diff --git a/pom.xml b/pom.xml index 44a6cd1..658769b 100644 --- a/pom.xml +++ b/pom.xml @@ -10,7 +10,7 @@ de.juplo.kafka.wordcount recorder - 1.0.2 + 1.1.0 Wordcount-Recorder Recorder-service of the multi-user wordcount-example @@ -26,8 +26,8 @@ spring-boot-starter-web - org.apache.kafka - kafka-clients + org.springframework.kafka + spring-kafka org.hibernate.validator diff --git a/src/main/java/de/juplo/kafka/wordcount/recorder/RecorderApplication.java b/src/main/java/de/juplo/kafka/wordcount/recorder/RecorderApplication.java index abe0685..11248d8 100644 --- a/src/main/java/de/juplo/kafka/wordcount/recorder/RecorderApplication.java +++ b/src/main/java/de/juplo/kafka/wordcount/recorder/RecorderApplication.java @@ -17,7 +17,7 @@ import java.util.Properties; public class RecorderApplication { @Bean(destroyMethod = "close") - KafkaProducer producer(RecorderApplicationProperties properties) + KafkaProducer producer(RecorderApplicationProperties properties) { Assert.hasText(properties.getBootstrapServer(), "juplo.wordcount.recorder.bootstrap-server must be set"); diff --git a/src/main/java/de/juplo/kafka/wordcount/recorder/RecorderController.java b/src/main/java/de/juplo/kafka/wordcount/recorder/RecorderController.java index f7e32e2..c9d2109 100644 --- a/src/main/java/de/juplo/kafka/wordcount/recorder/RecorderController.java +++ b/src/main/java/de/juplo/kafka/wordcount/recorder/RecorderController.java @@ -18,10 +18,12 @@ import jakarta.validation.constraints.NotEmpty; public class RecorderController { private final String topic; - private final KafkaProducer producer; + private final KafkaProducer producer; - public RecorderController(RecorderApplicationProperties properties, KafkaProducer producer) + public RecorderController( + RecorderApplicationProperties properties, + KafkaProducer producer) { this.topic = properties.getTopic(); this.producer = producer; @@ -44,7 +46,11 @@ public class RecorderController { DeferredResult> result = new DeferredResult<>(); - ProducerRecord record = new ProducerRecord<>(topic, username, sentence); + ProducerRecord record = new ProducerRecord<>( + topic, + username, + Recording.of(username, sentence)); + producer.send(record, (metadata, exception) -> { if (metadata != null) diff --git a/src/main/java/de/juplo/kafka/wordcount/recorder/Recording.java b/src/main/java/de/juplo/kafka/wordcount/recorder/Recording.java new file mode 100644 index 0000000..6117438 --- /dev/null +++ b/src/main/java/de/juplo/kafka/wordcount/recorder/Recording.java @@ -0,0 +1,11 @@ +package de.juplo.kafka.wordcount.recorder; + +import lombok.Value; + + +@Value(staticConstructor = "of") +public class Recording +{ + String user; + String sentence; +}