X-Git-Url: https://juplo.de/gitweb/?a=blobdiff_plain;f=src%2Fmain%2Fjava%2Fde%2Fjuplo%2Fkafka%2Fwordcount%2Frecorder%2FRecorderController.java;h=e76d24c9125d0945325bf18487ae1b105bfd5670;hb=refs%2Ftags%2Frecorder-1.2.0;hp=5fe69adbc6e111b44234c7fc001c35e023f582ef;hpb=338279a329a06be7a141a3930d80b2a2805719dc;p=demos%2Fkafka%2Fwordcount 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 5fe69ad..e76d24c 100644 --- a/src/main/java/de/juplo/kafka/wordcount/recorder/RecorderController.java +++ b/src/main/java/de/juplo/kafka/wordcount/recorder/RecorderController.java @@ -11,17 +11,19 @@ import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RestController; import org.springframework.web.context.request.async.DeferredResult; -import javax.validation.constraints.NotEmpty; +import jakarta.validation.constraints.NotEmpty; @RestController 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,10 +46,14 @@ public class RecorderController { DeferredResult> result = new DeferredResult<>(); - ProducerRecord record = new ProducerRecord<>(topic, username, sentence); + ProducerRecord 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(