spring-2019-08 - 17 - websocket example

This commit is contained in:
Yuriy Dvorzhetskiy
2019-10-26 12:37:39 +06:00
parent 340f6e0853
commit 4c1853f798
@@ -1,10 +1,13 @@
package ru.otus.spring;
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.publisher.Mono;
import java.time.Duration;
@RestController
public class ReactorController {
@@ -17,4 +20,14 @@ public class ReactorController {
public Flux<Integer> list() {
return Flux.range(1, 10);
}
@GetMapping(path = "/flux/stream", produces = MediaType.TEXT_EVENT_STREAM_VALUE)
public Flux<String> stream() {
return Flux.generate(() -> 0, (state, emitter) -> {
emitter.next(state);
return state + 1;
})
.delayElements(Duration.ofSeconds(1L))
.map(Object::toString);
}
}