Documentation
¶
Overview ¶
Package events fans committed events out to subscribed connections and replays the durable log for subscribers that resume (docs/specs/rpc-protocol.md).
Index ¶
Constants ¶
const Buffer = 1024
Buffer is how many undelivered events a subscription holds before the broker drops it as lagging; the client reconnects and resumes by seq.
Variables ¶
var ErrLagged = errors.New("events: subscriber lagged")
ErrLagged ends a subscription whose consumer fell more than Buffer behind.
Functions ¶
This section is empty.
Types ¶
type Broker ¶
type Broker struct {
// contains filtered or unexported fields
}
Broker delivers events to subscriptions. Publish never blocks.
func (*Broker) Publish ¶
func (b *Broker) Publish(evs []api.EventEnvelope)
Publish delivers events, in order, to every subscription; it is the store's OnCommit hook. A full subscription is dropped with ErrLagged.
func (*Broker) Subscribe ¶
func (b *Broker) Subscribe(ctx context.Context, sinceSeq *int64) (*Subscription, api.Subscription, error)
Subscribe registers a subscription before reading the log, so no event falls between replay and live delivery. With sinceSeq nil it delivers live events only. The result reports resync when sinceSeq is no longer replayable, in which case nothing is replayed.
type Log ¶
type Log interface {
LatestSeq(ctx context.Context) (int64, error)
OldestSeq(ctx context.Context) (int64, error)
ChangesSince(ctx context.Context, seq int64) ([]api.EventEnvelope, error)
}
Log is the durable event log (store.DB implements it).
type Subscription ¶
type Subscription struct {
// contains filtered or unexported fields
}
Subscription is one connection's event stream.
func (*Subscription) Close ¶
func (s *Subscription) Close()
Close unregisters the subscription and stops Run.
func (*Subscription) Run ¶
func (s *Subscription) Run(ctx context.Context, send func(api.EventEnvelope) error) error
Run sends the replay, then live events, until ctx ends, the subscription is closed or lags, or send fails. Durable live events already replayed are skipped, so each seq is delivered once and in order.