mirror of
https://github.com/OtusTeam/Spring.git
synced 2026-05-30 10:50:42 +00:00
spring-2019-08 - 17 - websocket example
This commit is contained in:
+13
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user