-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathClientApplication.java
More file actions
61 lines (51 loc) · 2.32 KB
/
ClientApplication.java
File metadata and controls
61 lines (51 loc) · 2.32 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
package question3.client;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.ApplicationRunner;
import org.springframework.boot.WebApplicationType;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.context.annotation.Bean;
import org.springframework.web.reactive.function.client.WebClient;
import reactor.core.publisher.Mono;
import java.util.concurrent.TimeUnit;
@SpringBootApplication(scanBasePackages = "question3.client")
public class ClientApplication {
private static final Logger LOGGER = LoggerFactory.getLogger(ClientApplication.class);
public static void main(String[] args) throws Exception {
new SpringApplicationBuilder(ClientApplication.class)
.web(WebApplicationType.NONE)
.run(args);
TimeUnit.SECONDS.sleep(10); // keep the JVM alive
}
@Bean
ApplicationRunner runner() {
return args -> {
WebClient webClient = WebClient.create("http://localhost:8080");
Mono<Integer> flightPriceMono = webClient
.get()
.uri("/question3/flightprice")
.retrieve()
.bodyToMono(Integer.class)
.doOnNext(price -> LOGGER.info("got flight price: {}", price));
Mono<Integer> hotelPriceMono = webClient
.get()
.uri("/question3/hotelprice")
.retrieve()
.bodyToMono(Integer.class)
.doOnNext(price -> LOGGER.info("got hotel price: {}", price));
Mono<Integer> carPriceMono = webClient
.get()
.uri("/question3/carprice")
.retrieve()
.bodyToMono(Integer.class)
.doOnNext(price -> LOGGER.info("got car price: {}", price));
Mono.zip(flightPriceMono, hotelPriceMono, carPriceMono)
.map(priceTriple -> priceTriple.getT1() + priceTriple.getT2() + priceTriple.getT3())
.subscribe(
totalPrice -> LOGGER.info("total price: {}", totalPrice),
Throwable::printStackTrace
);
};
}
}