Documentation
¶
Overview ¶
Package sse provides the sole reactive catalog-publication transport.
Index ¶
Constants ¶
const ( // CatalogPublishedEvent is the stable SSE event name. CatalogPublishedEvent = remote.CatalogPublishedEvent // DefaultHeartbeatInterval keeps idle streams alive through common proxies. DefaultHeartbeatInterval = 20 * time.Second // DefaultWriteTimeout bounds each event or heartbeat write and flush. DefaultWriteTimeout = 10 * time.Second )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Broadcaster ¶
type Broadcaster struct {
// contains filtered or unexported fields
}
Broadcaster delivers publications to HTTP SSE connections. Each connection owns exactly one writer goroutine: its request handler. Publication overload terminates that connection so reconnect catch-up can recover without a silently healthy stream.
func NewBroadcaster ¶
func NewBroadcaster(config Config, logger *zerolog.Logger) (*Broadcaster, error)
NewBroadcaster constructs an idle broadcaster. It starts no goroutine.
func (*Broadcaster) ClientCount ¶
func (b *Broadcaster) ClientCount() int
ClientCount returns the number of currently registered SSE connections.
func (*Broadcaster) Close ¶ added in v0.2.0
func (b *Broadcaster) Close()
Close terminates every active connection and rejects new ones.
func (*Broadcaster) Health ¶ added in v0.2.0
func (b *Broadcaster) Health() Health
Health returns the current server-side stream delivery health.
func (*Broadcaster) Publish ¶ added in v0.2.0
func (b *Broadcaster) Publish(publication Publication) error
Publish offers one committed generation to every connected stream. It never blocks the catalog commit path. A connection that cannot accept the publication is terminated instead of silently losing it.
func (*Broadcaster) ServeHTTP ¶
func (b *Broadcaster) ServeHTTP(writer http.ResponseWriter, request *http.Request)
ServeHTTP serves one heartbeat-enabled SSE connection.
func (*Broadcaster) Stats ¶ added in v0.2.0
func (b *Broadcaster) Stats() DeliveryStats
Stats returns cumulative delivery counters.
type DeliveryError ¶ added in v0.2.0
DeliveryError is a secret-free classification of the latest stream failure.
type DeliveryStats ¶ added in v0.2.0
type DeliveryStats struct {
Published uint64 `json:"published"`
Sent uint64 `json:"sent"`
Heartbeats uint64 `json:"heartbeats"`
Disconnected uint64 `json:"disconnected"`
BackpressureTerminated uint64 `json:"backpressure_terminated"`
Failed uint64 `json:"failed"`
}
DeliveryStats is a lock-free snapshot of SSE delivery behavior.
type Health ¶ added in v0.2.0
type Health struct {
State StreamState `json:"state"`
Clients int `json:"clients"`
LastHeartbeatAt time.Time `json:"last_heartbeat_at"`
LastEventAt time.Time `json:"last_event_at"`
LastGenerationID string `json:"last_generation_id,omitempty"`
LastSequence uint64 `json:"last_sequence"`
LastError *DeliveryError `json:"last_error,omitempty"`
Delivery DeliveryStats `json:"delivery"`
}
Health reports server-side SSE publication delivery without conflating heartbeat liveness with catalog freshness.
type Publication ¶ added in v0.2.0
type Publication = remote.Publication
Publication identifies one committed immutable catalog generation.
type StreamState ¶ added in v0.2.0
type StreamState string
StreamState is the server-side publication stream state.
const ( // StreamStateIdle means the broadcaster accepts streams but has no clients. StreamStateIdle StreamState = "idle" // StreamStateStreaming means at least one SSE client is connected. StreamStateStreaming StreamState = "streaming" // StreamStateStopped means the broadcaster rejects new streams. StreamStateStopped StreamState = "stopped" )