public class EventSource extends Object
Please see the Server-Sent Events specification for details.
Example implementation of EventSource in a Controller:
{{{ //import akka.stream.javadsl.Source; //import play.mvc.*; //import play.libs.*; //import java.time.ZonedDateTime; //import java.time.format.*; //import scala.concurrent.duration.Duration; //import static java.util.concurrent.TimeUnit.*; //import static play.libs.EventSource.Event.event; //private final DateTimeFormatter df = DateTimeFormatter.ofPattern("HH mm ss");
public Result liveClock() { Source<String, ?> tickSource = Source.tick(Duration.Zero(), Duration.create(100, MILLISECONDS), "TICK"); Source<EventSource.Event, ?> eventSource = tickSource.map((tick) -> EventSource.Event.event(df.format(ZonedDateTime.now()))); return ok().chunked(eventSource.via(EventSource.flow())).as(Http.MimeTypes.EVENT_STREAM); } }}}
Modifier and Type | Class and Description |
---|---|
static class |
EventSource.Event
Utility class to build events.
|
Constructor and Description |
---|
EventSource() |
Modifier and Type | Method and Description |
---|---|
static akka.stream.javadsl.Flow<EventSource.Event,akka.util.ByteString,?> |
flow() |
public static akka.stream.javadsl.Flow<EventSource.Event,akka.util.ByteString,?> flow()