Skip to main content

Module streams

Module streams 

Source
Expand description

Per-session, per-stream SSE delivery (shared by the HTTP adapters).

The Streamable HTTP spec requires that the server “MUST send each of its JSON-RPC messages on only one of the connected streams”, that SSE event ids be “globally unique across all streams within that session” and “SHOULD encode sufficient information to identify the originating stream”, and that the server “MUST NOT replay messages that would have been delivered on a different stream”.

StreamRegistry implements those rules once, so the four adapters share one delivery/replay implementation instead of four drifting copies:

  • each GET opens (or resumes) one stream with its own bounded mpsc channel and its own replay buffer;
  • every outbound message is stored on, and delivered to, exactly one stream — the designated stream (the oldest live one, stable while it lives; a resumed stream keeps its identity and therefore its designation);
  • event ids are {stream_id}-{seq}, allocated once at store time, so the id on the wire always equals the id in the buffer and Last-Event-ID replay works;
  • replay serves only events buffered on the stream the cursor names;
  • a full channel kills its stream (never a silent skip): the buffer is retained for StreamConfig::max_age, so a reconnecting client resumes and replays what the dead channel missed.

Structs§

StoredEvent
An event stored for delivery and replay on one stream.
StreamConfig
Configuration for a session’s stream registry.
StreamHandle
One live stream: the receiving half consumed by the adapter’s SSE loop.
StreamRegistry
Per-session registry of SSE streams. See the module docs for the rules it enforces.