org.springframework.web.servlet.function

## Interface ServerResponse.SseBuilder

- Enclosing interface:
    ServerResponse

      public static interface ServerResponse.SseBuilder

  Defines a builder for a body that sends server-sent events.
  Since:
    5.3.2

- - ### Method Summary

    All Methods Instance Methods Abstract Methods
    Modifier and Type | Method and Description
    --- | ---
    `ServerResponse.SseBuilder` | `comment(String comment)` Add an SSE comment.
    `void` | `complete()` Completes the event stream.
    `void` | `data(Object object)` Add an SSE "data" line for the given object and sends the built server-sent event to the client.
    `void` | `error(Throwable t)` Completes the event stream with the given error.
    `ServerResponse.SseBuilder` | `event(String eventName)` Add an SSE "event" line.
    `ServerResponse.SseBuilder` | `id(String id)` Add an SSE "id" line.
    `ServerResponse.SseBuilder` | `onComplete(Runnable onCompletion)` Register a callback to be invoked when the SSE request completes.
    `ServerResponse.SseBuilder` | `onError(Consumer<Throwable> onError)` Register a callback to be invoked when an error occurs during SSE processing.
    `ServerResponse.SseBuilder` | `onTimeout(Runnable onTimeout)` Register a callback to be invoked when an SSE request times out.
    `ServerResponse.SseBuilder` | `retry(Duration duration)` Add an SSE "retry" line.
    `void` | `send(Object object)` Sends the given object as a server-sent event.

- - ### Method Detail

    - #### send

          void send(Object object)
             throws IOException

      Sends the given object as a server-sent event. Strings will be sent as UTF-8 encoded bytes, and other objects will be converted into JSON using message converters.

      This convenience method has the same effect as `data(Object)`.

      Parameters:
        `object` - the object to send
      Throws:
        `IOException` - in case of I/O errors

    - #### id

          ServerResponse.SseBuilder id(String id)

      Add an SSE "id" line.
      Parameters:
        `id` - the event identifier
      Returns:
        this builder

    - #### event

          ServerResponse.SseBuilder event(String eventName)

      Add an SSE "event" line.
      Parameters:
        `eventName` - the event name
      Returns:
        this builder

    - #### retry

          ServerResponse.SseBuilder retry(Duration duration)

      Add an SSE "retry" line.
      Parameters:
        `duration` - the duration to convert into millis
      Returns:
        this builder

    - #### comment

          ServerResponse.SseBuilder comment(String comment)

      Add an SSE comment.
      Parameters:
        `comment` - the comment
      Returns:
        this builder

    - #### data

          void data(Object object)
             throws IOException

      Add an SSE "data" line for the given object and sends the built server-sent event to the client. Strings will be sent as UTF-8 encoded bytes, and other objects will be converted into JSON using message converters.
      Parameters:
        `object` - the object to send as data
      Throws:
        `IOException` - in case of I/O errors

    - #### error

          void error(Throwable t)

      Completes the event stream with the given error.

      The throwable is dispatched back into Spring MVC, and passed to its exception handling mechanism. Since the response has been committed by this point, the response status can not change.

      Parameters:
        `t` - the throwable to dispatch

    - #### complete

          void complete()

      Completes the event stream.

    - #### onTimeout

          ServerResponse.SseBuilder onTimeout(Runnable onTimeout)

      Register a callback to be invoked when an SSE request times out.
      Parameters:
        `onTimeout` - the callback to invoke on timeout
      Returns:
        this builder

    - #### onError

          ServerResponse.SseBuilder onError(Consumer<Throwable> onError)

      Register a callback to be invoked when an error occurs during SSE processing.
      Parameters:
        `onError` - the callback to invoke on error
      Returns:
        this builder

    - #### onComplete

          ServerResponse.SseBuilder onComplete(Runnable onCompletion)

      Register a callback to be invoked when the SSE request completes.
      Parameters:
        `onCompletion` - the callback to invoked on completion
      Returns:
        this builder