-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathServerApplication.java
More file actions
34 lines (27 loc) · 1.18 KB
/
ServerApplication.java
File metadata and controls
34 lines (27 loc) · 1.18 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
package question9.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 reactor.core.scheduler.Schedulers;
import java.time.Duration;
@SpringBootApplication(scanBasePackages = "question9.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 = "/question9/slowmillionvalues", produces = MediaType.TEXT_EVENT_STREAM_VALUE)
Flux<Integer> millionvalues() {
return Flux.range(1, 1_000_000)
.delayElements(Duration.ofSeconds(1), Schedulers.elastic())
.doOnNext(i -> LOGGER.info("Produced: {}", i));
}
}
}