<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>
-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;
@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");
public static void main(String[] args)
{
- SpringApplication.run(RecorderApplication.class, args);
+ SpringApplication.run(Application.class, args);
}
}
-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;
@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;
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,
@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) ->
if (metadata != null)
{
result.setResult(
- ResponseEntity.ok(RecordingResult.of(
+ ResponseEntity.ok(Result.of(
username,
sentence,
topic,
result.setErrorResult(
ResponseEntity
.internalServerError()
- .body(RecordingResult.of(
+ .body(Result.of(
username,
sentence,
topic,
-package de.juplo.kafka.wordcount.recorder;
+package de.juplo.kafka.sumup.gateway;
import lombok.Getter;
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";
}
-package de.juplo.kafka.wordcount.recorder;
+package de.juplo.kafka.sumup.gateway;
import com.fasterxml.jackson.annotation.JsonInclude;
import lombok.Value;
@Value(staticConstructor = "of")
-public class RecordingResult
+public class Result
{
@JsonInclude(NON_NULL) private final String username;
@JsonInclude(NON_NULL) private final String sentence;
-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;