memory

package
v0.2.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 15, 2026 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Overview

Package memory is the in-process pubsub.Broker used for single-instance deployments, development and tests.

Publish copies the payload once and queues it for every matching subscription; each subscription has its own goroutine and bounded queue, so handlers run sequentially per subscription and a slow handler never blocks publishers (overflowing messages are dropped with a warning).

Brokers created with NewPeer share one in-process bus, which simulates several server instances connected to the same backend: a message published on any peer is delivered to the subscribers of every open peer.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Broker

type Broker struct {
	// contains filtered or unexported fields
}

Broker is an in-process pubsub.Broker. The zero value is not usable; call New.

func New

func New(opts ...Option) *Broker

New returns a broker on a fresh in-process bus.

func (*Broker) Close

func (b *Broker) Close() error

Close detaches the broker from its bus and stops all of its subscriptions. It is idempotent.

func (*Broker) NewPeer

func (b *Broker) NewPeer() *Broker

NewPeer returns another broker attached to the same bus as b, as if it were a second server instance sharing b's backend. It inherits b's options. Closing one peer does not affect the others.

func (*Broker) Publish

func (b *Broker) Publish(ctx context.Context, topic string, payload []byte) error

Publish delivers payload to the subscribers of topic on every open peer.

func (*Broker) Subscribe

func (b *Broker) Subscribe(ctx context.Context, topic string, h pubsub.Handler) (func(), error)

Subscribe registers h for topic until cancel is called. cancel is idempotent and safe to call from within h.

type Option

type Option func(*fanout.Options)

Option configures a Broker.

func WithLogger

func WithLogger(l *slog.Logger) Option

WithLogger sets the logger used for overflow warnings and handler panics.

func WithQueueLimits

func WithQueueLimits(messages, bytes int) Option

WithQueueLimits bounds the undelivered messages (count and bytes) kept per subscription. Non-positive values keep the defaults (10000 messages, 64 MiB).

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL