Interface OutboundSseStream

All Known Implementing Classes:
PostSseStream

@InternalApi public interface OutboundSseStream
Outbound SSE stream bound to the current dispatch context. Allows a handler executing a JSON-RPC request to lazily upgrade the response transport to a Server-Sent Events stream so the server can push notifications and requests to the client before the final response.

The stream is dormant until start() is called (typically on the first server-to-client message issued during dispatch). Once started, subsequent events flow as SSE frames. The final response is appended as an SSE event by the dispatcher after the handler completes, then the stream is closed.

Implementations are transport-specific. The Netty implementation (PostSseStream) ties this to the HTTP POST response channel; other transports may bind it differently.

  • Method Summary

    Modifier and Type
    Method
    Description
    void
    Closes the SSE stream.
    default void
    comment(@Nullable String message)
    Writes an SSE comment line (: message\r\n), upgrading the stream via start() first if it has not started.
    void
    Activates the SSE stream and emits initial framing.
    boolean
     
    default @Nullable String
    A stable key identifying this stream within its session, used to tag event-log entries and to suffix SSE event ids (<n>#<key>) so a Last-Event-ID can be correlated back to the originating stream for per-stream replay.
    void
    writeEvent(@Nullable SseEvent event)
    Writes an SSE event.
  • Method Details

    • streamKey

      default @Nullable String streamKey()
      A stable key identifying this stream within its session, used to tag event-log entries and to suffix SSE event ids (<n>#<key>) so a Last-Event-ID can be correlated back to the originating stream for per-stream replay. null identifies the session's general-purpose GET stream.
    • start

      void start()
      Activates the SSE stream and emits initial framing. Idempotent — subsequent calls are no-ops. May be called from any thread.
    • started

      boolean started()
      Returns:
      true once the stream has been opened.
    • writeEvent

      void writeEvent(@Nullable SseEvent event)
      Writes an SSE event. If start() has not been called yet, the event is buffered and emitted when the stream upgrades. May be called from any thread.
      Parameters:
      event - the SSE event to write
    • comment

      default void comment(@Nullable String message)
      Writes an SSE comment line (: message\r\n), upgrading the stream via start() first if it has not started. A comment carries no event data — it exists to keep the connection alive without a progress token. A null or blank message emits a bare :\r\n. May be called from any thread. Default is a no-op for transports that do not support raw comments.
      Parameters:
      message - comment text (a single line; embedded line breaks are flattened), or null
    • close

      void close()
      Closes the SSE stream. Idempotent — subsequent calls are no-ops.