pubsub

package
v5.2.0 Latest Latest
Warning

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

Go to latest
Published: Jan 15, 2026 License: Apache-2.0, BSD-3-Clause Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	Backend    Type
	Store      store.Store
	InstanceID string
}

Config holds the configuration for the pub/sub system.

type DistributedPublisher

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

DistributedPublisher implements a distributed pub/sub system using database storage.

func NewDistributed

func NewDistributed(store store.Store, instanceID string) *DistributedPublisher

NewDistributed creates a distributed publisher that works across multiple instances.

func (*DistributedPublisher) Close

func (p *DistributedPublisher) Close() error

Close shuts down the distributed publisher.

func (*DistributedPublisher) Publish

func (p *DistributedPublisher) Publish(message Message)

Publish publishes a message to all subscribers across all instances.

func (*DistributedPublisher) Subscribe

func (p *DistributedPublisher) Subscribe(c context.Context, receiver Receiver)

Subscribe subscribes to messages with the given receiver function.

type MemoryPublisher

type MemoryPublisher struct {
	sync.Mutex
	// contains filtered or unexported fields
}

func New

func New() *MemoryPublisher

New creates an in-memory publisher.

func (*MemoryPublisher) Publish

func (p *MemoryPublisher) Publish(message Message)

func (*MemoryPublisher) Subscribe

func (p *MemoryPublisher) Subscribe(c context.Context, receiver Receiver)

type Message

type Message struct {
	// ID identifies this message.
	ID string `json:"id,omitempty"`

	// Data is the actual data in the entry.
	Data []byte `json:"data"`

	// Labels represents the key-value pairs the entry is labeled with.
	Labels map[string]string `json:"labels,omitempty"`
}

Message defines a published message.

type Publisher

type Publisher interface {
	Publish(message Message)
	Subscribe(c context.Context, receiver Receiver)
}

Publisher defines the interface for pub/sub operations.

func NewPublisher

func NewPublisher(config Config) Publisher

New creates a new publisher based on the provided configuration.

type Receiver

type Receiver func(Message)

Receiver receives published messages.

type Type

type Type string

Type represents the pub/sub backend type.

const (
	TypeMemory      Type = "memory"
	TypeDistributed Type = "distributed"
)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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