-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathServerApplication.java
More file actions
35 lines (28 loc) · 1.29 KB
/
ServerApplication.java
File metadata and controls
35 lines (28 loc) · 1.29 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
package question5.server;
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 reactor.core.publisher.Flux;
import java.time.Duration;
@SpringBootApplication(scanBasePackages = "question5.server")
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 = "/question5/slowflightprice", produces = MediaType.TEXT_EVENT_STREAM_VALUE)
Flux<Integer> flightprice() {
return Flux.interval(Duration.ofSeconds(10)).take(1)
.doOnSubscribe(subscription -> LOGGER.info("price is requested"))
.flatMap(tick -> Flux.just(250))
.doOnCancel(() -> LOGGER.info("cancelled"))
.doOnNext(price -> LOGGER.info("published price: {}", price));
}
}
}