Fix call.

This commit is contained in:
Olga Maciaszek-Sharma
2020-09-11 18:07:37 +02:00
parent 7b2bb7a2f0
commit 35d36f7d41
3 changed files with 8 additions and 10 deletions

View File

@@ -16,7 +16,6 @@
package org.springframework.cloud.kubernetes.examples;
import reactor.core.publisher.Mono;
import org.springframework.web.bind.annotation.GetMapping;
@@ -52,9 +51,9 @@ public class GreetingController {
*/
@GetMapping("/greeting")
public Mono<String> getGreeting(
@RequestParam(value = "delay", defaultValue = "0") int delay) {
return Mono
.just(String.format("Hello from %s!", nameService.getName(delay)));
@RequestParam(value = "delay", defaultValue = "0") int delay) {
return nameService.getName(delay)
.map(name -> String.format("Hello from %s!", name));
}
}

View File

@@ -19,7 +19,6 @@ package org.springframework.cloud.kubernetes.examples;
import reactor.core.publisher.Mono;
import org.springframework.stereotype.Service;
import org.springframework.web.reactive.function.client.ClientResponse;
import org.springframework.web.reactive.function.client.WebClient;
/**
@@ -37,10 +36,10 @@ public class NameService {
webClient = webClientBuilder.build();
}
public Mono<ClientResponse> getName(int delay) {
public Mono<String> getName(int delay) {
return webClient.get()
.uri("http://name-service/name?delay=%d", delay)
.exchange();
.uri(String.format("http://name-service/name?delay=%d", delay)).retrieve()
.bodyToMono(String.class);
}
}

View File

@@ -51,9 +51,9 @@ public class NameController {
*/
@GetMapping("/name")
public Mono<String> getName(
@RequestParam(value = "delay", defaultValue = "0") int delayValue) {
@RequestParam(value = "delay", defaultValue = "0") int delayValue) {
LOG.info(String.format("Returning a name '%s' with a delay '%d'", hostName,
delayValue));
delayValue));
delay(delayValue);
return Mono.just(hostName);
}