Durable Streams
HTTP-based streaming of NATS JetStream data to web/mobile clients. Implements the Durable Streams Protocol.
Architecture
Section titled “Architecture”Client (Browser/CLI) ↓ HTTP/SSEStreams Service (port 52012) ↓ JetStreamNATSKey design: Predefined streams only. The service handles auth and userID injection into subject filters.
Endpoints
Section titled “Endpoints”# List available streamsGET /api/streams/
# Subscribe to a stream (auth required)GET /api/streams/{name}CLI Usage
Section titled “CLI Usage”# List available streamsorbital str ls
# Subscribe to a streamorbital str sub heartbeatorbital str sub walletSSE Protocol
Section titled “SSE Protocol”Response format:
event: datadata: {"seq":1,"timestamp":"2025-12-14T10:00:00Z"}
event: controldata: {"streamNextOffset":"00000000000000000042"}
: heartbeatHeaders:
Stream-Next-Offset: Resume cursor for next requestStream-Cursor: Current positionStream-Up-To-Date: true: Caught up to head of stream
Code Structure
Section titled “Code Structure”| Package | Purpose |
|---|---|
internal/dstreams | Generic SSE protocol layer |
services/streams/api | Service (auth, mappings, handlers) |
internal/cli/stream.go | CLI commands |
Adding Streams
Section titled “Adding Streams”Edit services/streams/api/mappings.go:
var streamMappings = map[string]StreamMapping{ "wallet": { Stream: "wallet", SubjectFilter: "wallet.{userID}.>", Description: "Wallet events", },}Each mapping creates a GET /api/streams/{name} endpoint.