recorder: 1.2.0 - Fixed a bug (error-detection) in `RecorderController`
[demos/kafka/wordcount] / src / main / java / de / juplo / kafka / wordcount / recorder / RecorderController.java
index f7e32e2..e76d24c 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<User, Recording> producer;
 
 
-  public RecorderController(RecorderApplicationProperties properties, KafkaProducer<String,String> producer)
+  public RecorderController(
+      RecorderApplicationProperties properties,
+      KafkaProducer<User, Recording> producer)
   {
     this.topic = properties.getTopic();
     this.producer = producer;
@@ -44,10 +46,14 @@ public class RecorderController
   {
     DeferredResult<ResponseEntity<RecordingResult>> result = new DeferredResult<>();
 
-    ProducerRecord<String, String> record = new ProducerRecord<>(topic, username, sentence);
+    ProducerRecord<User, Recording> record = new ProducerRecord<>(
+        topic,
+        User.of(username),
+        Recording.of(username, sentence));
+
     producer.send(record, (metadata, exception) ->
     {
-      if (metadata != null)
+      if (exception == null)
       {
         result.setResult(
             ResponseEntity.ok(RecordingResult.of(