From: Kai Moritz Date: Sun, 25 Sep 2022 15:38:28 +0000 (+0200) Subject: WIP X-Git-Url: http://juplo.de/gitweb/?a=commitdiff_plain;h=bf22e88ee5c8ca389df91f6879896e59335c8f2d;p=demos%2Fkafka%2Fwordcount WIP --- diff --git a/pom.xml b/pom.xml index edcedf5..ca23258 100644 --- a/pom.xml +++ b/pom.xml @@ -8,10 +8,10 @@ 2.5.4 - de.juplo.kafka.wordcount - recorder - 1.0.1 - Wordcount-Recorder + de.juplo.kafka.sumup + gateway + 1-SNAPSHOT + REST Gateway for the SumUp-Services Recorder-service of the multi-user wordcount-example 0.33.0 diff --git a/src/main/java/de/juplo/kafka/sumup/gateway/Application.java b/src/main/java/de/juplo/kafka/sumup/gateway/Application.java index abe0685..928a17f 100644 --- a/src/main/java/de/juplo/kafka/sumup/gateway/Application.java +++ b/src/main/java/de/juplo/kafka/sumup/gateway/Application.java @@ -1,4 +1,4 @@ -package de.juplo.kafka.wordcount.recorder; +package de.juplo.kafka.sumup.gateway; import org.apache.kafka.clients.producer.KafkaProducer; import org.apache.kafka.clients.producer.ProducerConfig; @@ -13,11 +13,11 @@ import java.util.Properties; @SpringBootApplication -@EnableConfigurationProperties(RecorderApplicationProperties.class) -public class RecorderApplication +@EnableConfigurationProperties(ApplicationProperties.class) +public class Application { @Bean(destroyMethod = "close") - KafkaProducer producer(RecorderApplicationProperties properties) + KafkaProducer producer(ApplicationProperties properties) { Assert.hasText(properties.getBootstrapServer(), "juplo.wordcount.recorder.bootstrap-server must be set"); @@ -31,6 +31,6 @@ public class RecorderApplication public static void main(String[] args) { - SpringApplication.run(RecorderApplication.class, args); + SpringApplication.run(Application.class, args); } } diff --git a/src/main/java/de/juplo/kafka/sumup/gateway/ApplicationController.java b/src/main/java/de/juplo/kafka/sumup/gateway/ApplicationController.java index 5fe69ad..3ae1552 100644 --- a/src/main/java/de/juplo/kafka/sumup/gateway/ApplicationController.java +++ b/src/main/java/de/juplo/kafka/sumup/gateway/ApplicationController.java @@ -1,4 +1,4 @@ -package de.juplo.kafka.wordcount.recorder; +package de.juplo.kafka.sumup.gateway; import org.apache.kafka.clients.producer.KafkaProducer; import org.apache.kafka.clients.producer.ProducerRecord; @@ -15,13 +15,13 @@ import javax.validation.constraints.NotEmpty; @RestController -public class RecorderController +public class ApplicationController { private final String topic; private final KafkaProducer producer; - public RecorderController(RecorderApplicationProperties properties, KafkaProducer producer) + public ApplicationController(ApplicationProperties properties, KafkaProducer producer) { this.topic = properties.getTopic(); this.producer = producer; @@ -34,7 +34,7 @@ public class RecorderController MimeTypeUtils.APPLICATION_JSON_VALUE }, produces = MimeTypeUtils.APPLICATION_JSON_VALUE) - DeferredResult> speak( + DeferredResult> speak( @PathVariable @NotEmpty(message = "A username must be provided") String username, @@ -42,7 +42,7 @@ public class RecorderController @NotEmpty(message = "The spoken sentence must not be empty!") String sentence) { - DeferredResult> result = new DeferredResult<>(); + DeferredResult> result = new DeferredResult<>(); ProducerRecord record = new ProducerRecord<>(topic, username, sentence); producer.send(record, (metadata, exception) -> @@ -50,7 +50,7 @@ public class RecorderController if (metadata != null) { result.setResult( - ResponseEntity.ok(RecordingResult.of( + ResponseEntity.ok(Result.of( username, sentence, topic, @@ -64,7 +64,7 @@ public class RecorderController result.setErrorResult( ResponseEntity .internalServerError() - .body(RecordingResult.of( + .body(Result.of( username, sentence, topic, diff --git a/src/main/java/de/juplo/kafka/sumup/gateway/ApplicationProperties.java b/src/main/java/de/juplo/kafka/sumup/gateway/ApplicationProperties.java index 552ebaf..029489b 100644 --- a/src/main/java/de/juplo/kafka/sumup/gateway/ApplicationProperties.java +++ b/src/main/java/de/juplo/kafka/sumup/gateway/ApplicationProperties.java @@ -1,4 +1,4 @@ -package de.juplo.kafka.wordcount.recorder; +package de.juplo.kafka.sumup.gateway; import lombok.Getter; @@ -7,12 +7,12 @@ import lombok.ToString; import org.springframework.boot.context.properties.ConfigurationProperties; -@ConfigurationProperties("juplo.wordcount.recorder") +@ConfigurationProperties("juplo.sumup.gateway") @Getter @Setter @ToString -public class RecorderApplicationProperties +public class ApplicationProperties { private String bootstrapServer = "localhost:9092"; - private String topic = "recordings"; + private String topic = "requests"; } diff --git a/src/main/java/de/juplo/kafka/sumup/gateway/Result.java b/src/main/java/de/juplo/kafka/sumup/gateway/Result.java index 939b1d4..b08894a 100644 --- a/src/main/java/de/juplo/kafka/sumup/gateway/Result.java +++ b/src/main/java/de/juplo/kafka/sumup/gateway/Result.java @@ -1,4 +1,4 @@ -package de.juplo.kafka.wordcount.recorder; +package de.juplo.kafka.sumup.gateway; import com.fasterxml.jackson.annotation.JsonInclude; import lombok.Value; @@ -7,7 +7,7 @@ import static com.fasterxml.jackson.annotation.JsonInclude.Include.NON_NULL; @Value(staticConstructor = "of") -public class RecordingResult +public class Result { @JsonInclude(NON_NULL) private final String username; @JsonInclude(NON_NULL) private final String sentence; diff --git a/src/test/java/de/juplo/kafka/sumup/gateway/ApplicationTests.java b/src/test/java/de/juplo/kafka/sumup/gateway/ApplicationTests.java index 885a408..7ad2b7f 100644 --- a/src/test/java/de/juplo/kafka/sumup/gateway/ApplicationTests.java +++ b/src/test/java/de/juplo/kafka/sumup/gateway/ApplicationTests.java @@ -1,4 +1,4 @@ -package de.juplo.kafka.wordcount.recorder; +package de.juplo.kafka.sumup.gateway; import org.junit.jupiter.api.Test; import org.springframework.boot.test.context.SpringBootTest;