1 package de.juplo.kafka;
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;
10 public class RestService
12 private final WebClient client;
13 private final String username;
17 WebClient.Builder builder,
18 ApplicationProperties properties)
21 .baseUrl(properties.getBaseUrl())
23 this.username = properties.getUsername();
27 public Mono<RestResult> send(long number)
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));