Interface ServerSentEventsBuilder


  • public interface ServerSentEventsBuilder
    Creates a builder for a server sent event stream.
    Since:
    1.10
    • 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)
      • noContentOnEmpty

        ServerSentEventsBuilder noContentOnEmpty()
        Causes a HTTP 204 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 every heartbeatAfterIdleFor since the last write, to keep the connection alive.

        By default, no keep alive is applied.

        Returns:
        this