WIP
authorKai Moritz <kai@juplo.de>
Sun, 25 Sep 2022 15:38:28 +0000 (17:38 +0200)
committerKai Moritz <kai@juplo.de>
Sun, 25 Sep 2022 15:38:28 +0000 (17:38 +0200)
pom.xml
src/main/java/de/juplo/kafka/sumup/gateway/Application.java
src/main/java/de/juplo/kafka/sumup/gateway/ApplicationController.java
src/main/java/de/juplo/kafka/sumup/gateway/ApplicationProperties.java
src/main/java/de/juplo/kafka/sumup/gateway/Result.java
src/test/java/de/juplo/kafka/sumup/gateway/ApplicationTests.java

diff --git a/pom.xml b/pom.xml
index edcedf5..ca23258 100644 (file)
--- a/pom.xml
+++ b/pom.xml
@@ -8,10 +8,10 @@
                <version>2.5.4</version>
                <relativePath/> <!-- lookup parent from repository -->
        </parent>
-       <groupId>de.juplo.kafka.wordcount</groupId>
-       <artifactId>recorder</artifactId>
-       <version>1.0.1</version>
-       <name>Wordcount-Recorder</name>
+       <groupId>de.juplo.kafka.sumup</groupId>
+       <artifactId>gateway</artifactId>
+       <version>1-SNAPSHOT</version>
+       <name>REST Gateway for the SumUp-Services</name>
        <description>Recorder-service of the multi-user wordcount-example</description>
        <properties>
                <docker-maven-plugin.version>0.33.0</docker-maven-plugin.version>
index abe0685..928a17f 100644 (file)
@@ -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<String, String> producer(RecorderApplicationProperties properties)
+       KafkaProducer<String, String> 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);
        }
 }
index 5fe69ad..3ae1552 100644 (file)
@@ -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<String, String> producer;
 
 
-  public RecorderController(RecorderApplicationProperties properties, KafkaProducer<String,String> producer)
+  public ApplicationController(ApplicationProperties properties, KafkaProducer<String,String> 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<ResponseEntity<RecordingResult>> speak(
+  DeferredResult<ResponseEntity<Result>> 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<ResponseEntity<RecordingResult>> result = new DeferredResult<>();
+    DeferredResult<ResponseEntity<Result>> result = new DeferredResult<>();
 
     ProducerRecord<String, String> 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,
index 552ebaf..029489b 100644 (file)
@@ -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";
 }
index 939b1d4..b08894a 100644 (file)
@@ -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;
index 885a408..7ad2b7f 100644 (file)
@@ -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;