diff --git a/spring-5-reactive/src/main/java/com/baeldung/reactive/webflux/Event.java b/spring-5-reactive/src/main/java/com/baeldung/reactive/webflux/Event.java new file mode 100644 index 0000000000..03e80e915e --- /dev/null +++ b/spring-5-reactive/src/main/java/com/baeldung/reactive/webflux/Event.java @@ -0,0 +1,13 @@ +package com.baeldung.reactive.webflux; + +import lombok.AllArgsConstructor; +import lombok.Data; + +@Data +@AllArgsConstructor +public class Event { + + private Long id; + private String body; + +} diff --git a/spring-5-reactive/src/main/java/com/baeldung/reactive/webflux/EventStreamController.java b/spring-5-reactive/src/main/java/com/baeldung/reactive/webflux/EventStreamController.java new file mode 100644 index 0000000000..5a88f6823e --- /dev/null +++ b/spring-5-reactive/src/main/java/com/baeldung/reactive/webflux/EventStreamController.java @@ -0,0 +1,20 @@ +package com.baeldung.reactive.webflux; + +import java.time.Duration; + +import org.springframework.http.MediaType; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RestController; + +import reactor.core.publisher.Flux; + +@RestController +public class EventStreamController { + + @GetMapping(value = "/events", produces = MediaType.TEXT_EVENT_STREAM_VALUE) + public Flux getMessages() { + return Flux.interval(Duration.ofMillis(1000)) + .map(tick -> new Event(tick, "This is Message #" + tick)); + } + +} diff --git a/spring-5-reactive/src/main/java/com/baeldung/reactive/webflux/WebfluxDemoApplication.java b/spring-5-reactive/src/main/java/com/baeldung/reactive/webflux/WebfluxDemoApplication.java new file mode 100644 index 0000000000..70cad0ad22 --- /dev/null +++ b/spring-5-reactive/src/main/java/com/baeldung/reactive/webflux/WebfluxDemoApplication.java @@ -0,0 +1,12 @@ +package com.baeldung.reactive.webflux; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +@SpringBootApplication +public class WebfluxDemoApplication { + + public static void main(String[] args) { + SpringApplication.run(WebfluxDemoApplication.class, args); + } +} diff --git a/spring-5-reactive/src/main/resources/static/webflux/client-event-stream.html b/spring-5-reactive/src/main/resources/static/webflux/client-event-stream.html new file mode 100644 index 0000000000..d7631f9217 --- /dev/null +++ b/spring-5-reactive/src/main/resources/static/webflux/client-event-stream.html @@ -0,0 +1,45 @@ + + + + + Baeldung: Spring 5 Reactive Webflux - real time event streaming + + + + + + +

Events streamed...

+ + + + + + + + + +
Event IdEvent Body
+ + + + + \ No newline at end of file