Documentation
¶
Overview ¶
Package broadcaster listens for the database's notifications, on a channel, and publishes them, as changes, to a go-server broadcaster, so the server's modules, and its clients, which watch the broadcaster, are told of them, with one connection which listens, rather than one each.
Index ¶
- type Manager
- func (self *Manager) Broadcaster() *changes.Broadcaster
- func (self *Manager) Channel() string
- func (self *Manager) Listening() bool
- func (self *Manager) Publish(ctx context.Context, change changeschema.Change) (err error)
- func (self *Manager) Run(ctx context.Context, logger *slog.Logger) error
- func (self *Manager) Running() bool
- func (self *Manager) Schema() string
- func (self *Manager) Shared() bool
- func (self *Manager) WaitListening(ctx context.Context) error
- func (self *Manager) Watch(ctx context.Context, filter changeschema.ChangeFilter, ...) (<-chan error, error)
- type Opt
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Manager ¶
func New ¶
New creates a new manager, which listens for the notifications on its channel when it's run
func (*Manager) Broadcaster ¶ added in v1.4.9
func (self *Manager) Broadcaster() *changes.Broadcaster
Broadcaster returns the broadcaster which the changes are published to, which its HTTP handler streams
func (*Manager) Listening ¶
Listening reports whether the manager is listening on its channel, so the changes published to it are published to the broadcaster
func (*Manager) Publish ¶
Publish publishes the change to the manager's channel, as JSON, so every server listening on it publishes it to its broadcaster. Returns ErrBadParameter when the change is larger than a notification can be.
func (*Manager) Run ¶
Run listens for the notifications on the manager's channel, and publishes each, as a change, to the broadcaster, logging with the logger, until the context is cancelled, and runs the broadcaster, when it's the manager's, so its watches end when it stops. A notification which isn't a change, such as one whose action isn't INSERT, UPDATE or DELETE, is logged, and skipped. When the connection which listens closes, such as when it fails, it listens again, and the notifications in between are missed. When it can't listen again, such as while the database restarts, it logs that, and tries again, after a delay which doubles each time, until it can, or the context is cancelled. When it can't listen at first, it returns the error. Only one can run at a time.
func (*Manager) Shared ¶ added in v1.4.9
Shared returns true when the broadcaster is shared with the manager, with WithBroadcaster, so it isn't the manager's, which runs it
func (*Manager) WaitListening ¶
WaitListening waits until the manager is listening on its channel, so the changes made from then are published to the broadcaster, or returns the context's error when it's cancelled first
func (*Manager) Watch ¶ added in v1.4.9
func (self *Manager) Watch(ctx context.Context, filter changeschema.ChangeFilter, ch chan<- changeschema.Change) (<-chan error, error)
Watch sends the changes which are published to the broadcaster, and match the filter, to the channel, as the broadcaster's Watch does, until the context is cancelled, or the broadcaster stops running
type Opt ¶
type Opt func(*opt) error
Opt is a functional option for the broadcaster manager's configuration
func WithBroadcaster ¶ added in v1.4.9
func WithBroadcaster(broadcaster *changes.Broadcaster) Opt
WithBroadcaster publishes the changes to the broadcaster, which is shared, such as with the server's other modules, which publish theirs to it, so their clients watch one stream of changes. A shared broadcaster isn't run by the manager, but by whatever shares it.
func WithChannel ¶
WithChannel sets the channel the notifications are listened for on, which must be an identifier
func WithSchema ¶
WithSchema sets the database schema, which must be an identifier
func WithTracer ¶
WithTracer sets the tracer used for tracing operations