-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathServerApplication.java
More file actions
39 lines (32 loc) · 1.45 KB
/
ServerApplication.java
File metadata and controls
39 lines (32 loc) · 1.45 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
package question11.apigateway;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.reactive.function.client.WebClient;
import reactor.core.publisher.Flux;
import reactor.core.scheduler.Schedulers;
import java.time.Duration;
@SpringBootApplication(scanBasePackages = "question11.apigateway")
public class ServerApplication {
private static final Logger LOGGER = LoggerFactory.getLogger(ServerApplication.class);
public static void main(String[] args) {
SpringApplication.run(ServerApplication.class, args);
}
@RestController
public static class HelloWorldReactorRestController {
@GetMapping(value = "/question11/apigateway", produces = MediaType.TEXT_EVENT_STREAM_VALUE)
Flux<Integer> apigateway() {
return WebClient.create("http://localhost:9090")
.get()
.uri("/question11/fakepersistencevalues")
.retrieve()
.bodyToFlux(Integer.class)
.delayElements(Duration.ofMillis(1), Schedulers.elastic())
.doOnNext(value -> LOGGER.info("Value in API bridge: {}", value));
}
}
}