recorder: 1.1.0 - recordings are sent as JSON recorder-1.1.0
authorKai Moritz <kai@juplo.de>
Sat, 4 Feb 2023 09:46:03 +0000 (10:46 +0100)
committerKai Moritz <kai@juplo.de>
Fri, 17 Feb 2023 16:49:20 +0000 (17:49 +0100)
pom.xml
src/main/java/de/juplo/kafka/wordcount/recorder/RecorderApplication.java
src/main/java/de/juplo/kafka/wordcount/recorder/RecorderController.java
src/main/java/de/juplo/kafka/wordcount/recorder/Recording.java [new file with mode: 0644]

diff --git a/pom.xml b/pom.xml
index 44a6cd1..658769b 100644 (file)
--- a/pom.xml
+++ b/pom.xml
@@ -10,7 +10,7 @@
        </parent>
        <groupId>de.juplo.kafka.wordcount</groupId>
        <artifactId>recorder</artifactId>
-       <version>1.0.2</version>
+       <version>1.1.0</version>
        <name>Wordcount-Recorder</name>
        <description>Recorder-service of the multi-user wordcount-example</description>
        <properties>
@@ -26,8 +26,8 @@
                        <artifactId>spring-boot-starter-web</artifactId>
                </dependency>
                <dependency>
-                       <groupId>org.apache.kafka</groupId>
-                       <artifactId>kafka-clients</artifactId>
+                       <groupId>org.springframework.kafka</groupId>
+                       <artifactId>spring-kafka</artifactId>
                </dependency>
                <dependency>
                        <groupId>org.hibernate.validator</groupId>
index abe0685..11248d8 100644 (file)
@@ -17,7 +17,7 @@ import java.util.Properties;
 public class RecorderApplication
 {
        @Bean(destroyMethod = "close")
-       KafkaProducer<String, String> producer(RecorderApplicationProperties properties)
+       KafkaProducer<String, Recording> producer(RecorderApplicationProperties properties)
        {
                Assert.hasText(properties.getBootstrapServer(), "juplo.wordcount.recorder.bootstrap-server must be set");
 
index f7e32e2..c9d2109 100644 (file)
@@ -18,10 +18,12 @@ import jakarta.validation.constraints.NotEmpty;
 public class RecorderController
 {
   private final String topic;
-  private final KafkaProducer<String, String> producer;
+  private final KafkaProducer<String, Recording> producer;
 
 
-  public RecorderController(RecorderApplicationProperties properties, KafkaProducer<String,String> producer)
+  public RecorderController(
+      RecorderApplicationProperties properties,
+      KafkaProducer<String,Recording> producer)
   {
     this.topic = properties.getTopic();
     this.producer = producer;
@@ -44,7 +46,11 @@ public class RecorderController
   {
     DeferredResult<ResponseEntity<RecordingResult>> result = new DeferredResult<>();
 
-    ProducerRecord<String, String> record = new ProducerRecord<>(topic, username, sentence);
+    ProducerRecord<String, Recording> 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 (file)
index 0000000..6117438
--- /dev/null
@@ -0,0 +1,11 @@
+package de.juplo.kafka.wordcount.recorder;
+
+import lombok.Value;
+
+
+@Value(staticConstructor = "of")
+public class Recording
+{
+  String user;
+  String sentence;
+}