Merge des Upgrades der Confluent-Images auf 7.0.2
[demos/kafka/training] / src / main / java / de / juplo / kafka / RestService.java
1 package de.juplo.kafka;
2
3 import org.springframework.http.MediaType;
4 import org.springframework.stereotype.Service;
5 import org.springframework.web.reactive.function.client.WebClient;
6 import reactor.core.publisher.Mono;
7
8
9 @Service
10 public class RestService
11 {
12   private final WebClient client;
13   private final String username;
14
15
16   public RestService(
17       WebClient.Builder builder,
18       ApplicationProperties properties)
19   {
20     this.client = builder
21         .baseUrl(properties.getBaseUrl())
22         .build();
23     this.username = properties.getUsername();
24   }
25
26
27   public Mono<RestResult> send(long number)
28   {
29     return client
30         .post()
31         .uri("/{username}", username)
32         .bodyValue(Long.toString(number))
33         .accept(MediaType.APPLICATION_JSON)
34         .exchangeToMono(response ->
35             response.statusCode().isError()
36                 ? response.bodyToMono(RestFailure.class)
37                 : response.bodyToMono(RestSuccess.class));
38   }
39 }