Documentation
¶
Overview ¶
Package eventbus is a minimal in-process publish/subscribe channel for server-side change events (migration_added, schema_changed, etc.).
Bus is concurrency-safe. Each subscription owns a buffered channel; slow consumers that fill the buffer have new events dropped (with a metrics counter, not a panic) rather than backpressuring publishers. Producers must remain non-blocking — the bus sits in the hot path of migration apply.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Bus ¶
type Bus struct {
// contains filtered or unexported fields
}
Bus is a fan-out pub/sub channel. Zero value is not usable; call New.
func (*Bus) Dropped ¶
Dropped returns the cumulative count of events the bus dropped due to full subscriber buffers since startup. Exposed for /readyz diagnostics.
func (*Bus) Publish ¶
Publish broadcasts ev to every current subscriber. Caller should set ev.Kind and ev.Payload; ID and At are assigned by the bus.
func (*Bus) Subscribe ¶
func (b *Bus) Subscribe(buffer int) *Subscription
Subscribe returns a new subscription with the given channel buffer. A buffer of 64–256 is typical; pick higher for clients expected to be slow.
type Event ¶
type Event struct {
ID uint64 `json:"event_id"`
Kind string `json:"kind"`
At time.Time `json:"at"`
Payload any `json:"payload,omitempty"`
}
Event is a single notification posted to the bus. ID is monotonic per-bus and lets Subscription consumers resume after a disconnect (via the /events?since= parameter in the HTTP/IPC adapters).
type Subscription ¶
type Subscription struct {
Ch chan Event
// contains filtered or unexported fields
}
Subscription is one consumer's view of the bus. Read events from Ch and call Close when done. The buffer size is fixed at construction; when full, the bus drops further events for this subscription rather than blocking publishers.
func (*Subscription) Close ¶
func (s *Subscription) Close()
Close removes the subscription from the bus and closes Ch. Safe to call multiple times.