Package ratpack.core.sse
Interface ServerSentEventsBuilder
-
public interface ServerSentEventsBuilder
Creates a builder for a server sent event stream.- Since:
- 1.10
-
-
Method Summary
All Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description default ServerSentEventsBuilder
buffered()
Applies sensible buffering defaults, for low latency.ServerSentEventsBuilder
buffered(int numEvents, int numBytes, Duration duration)
Specifies how events should be buffered.ServerSentEvents
build(Publisher<? extends ServerSentEvent> events)
Builds the server sent events with the given publisher.ServerSentEventsBuilder
keepAlive(Duration heartbeatAfterIdleFor)
Causes a comment to be written everyheartbeatAfterIdleFor
since the last write, to keep the connection alive.ServerSentEventsBuilder
noContentOnEmpty()
Causes a HTTP204 No Content
response to be rendered if the stream closes before sending any events.
-
-
-
Method Detail
-
buffered
ServerSentEventsBuilder buffered(int numEvents, int numBytes, Duration duration)
Specifies how events should be buffered.By default, no buffering is applied. This causes each event to be immediately written and flushed, which is generally inefficient. Unless it is required to absolutely send all events as soon as they are available, buffering should be applied.
Events are buffered by number of events, number of bytes, and time. The buffer will be flushed if any dimension is exceeded, and there is downstream demand.
Use
buffered()
to use sensible defaults.- Parameters:
numEvents
- the number of events to buffer (must be > 0)numBytes
- the number of bytes to buffer (must be > 0)duration
- the amount of time to buffer events (use 0 to disable)- Returns:
this
- See Also:
buffered(int, int, Duration)
-
buffered
default ServerSentEventsBuilder buffered()
Applies sensible buffering defaults, for low latency.- Events: 512
- Bytes: 57344
- Duration: 1 second
- Returns:
this
- See Also:
buffered(int, int, Duration)
-
noContentOnEmpty
ServerSentEventsBuilder noContentOnEmpty()
Causes a HTTP204 No Content
response to be rendered if the stream closes before sending any events.When used in conjunction with
buffered(int, int, java.time.Duration)
, buffering begins after the first event is received. As such, it is typically not suitable for long lived connections that stream data that will become available later.- Returns:
- this
-
keepAlive
ServerSentEventsBuilder keepAlive(Duration heartbeatAfterIdleFor)
Causes a comment to be written everyheartbeatAfterIdleFor
since the last write, to keep the connection alive.By default, no keep alive is applied.
- Returns:
- this
-
build
ServerSentEvents build(Publisher<? extends ServerSentEvent> events)
Builds the server sent events with the given publisher.- Parameters:
events
- the publisher of events- Returns:
- a renderable
ServerSentEvents
-
-