pubsub

package
v2.5.1 Latest Latest
Warning

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

Go to latest
Published: Dec 14, 2023 License: AGPL-3.0 Imports: 8 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

View Source
const BufferSize = 2048

BufferSize is the maximum number of unhandled messages we will buffer for a subscriber before dropping messages.

Variables

View Source
var ErrDroppedMessages = xerrors.New("dropped messages")

ErrDroppedMessages is sent to ListenerWithErr if messages are dropped or might have been dropped.

Functions

This section is empty.

Types

type Listener

type Listener func(ctx context.Context, message []byte)

Listener represents a pubsub handler.

type ListenerWithErr

type ListenerWithErr func(ctx context.Context, message []byte, err error)

ListenerWithErr represents a pubsub handler that can also receive error indications

type MemoryPubsub

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

MemoryPubsub is an in-memory Pubsub implementation. It's an exported type so that our test code can do type checks.

func (*MemoryPubsub) Close

func (*MemoryPubsub) Close() error

func (*MemoryPubsub) Publish

func (m *MemoryPubsub) Publish(event string, message []byte) error

func (*MemoryPubsub) Subscribe

func (m *MemoryPubsub) Subscribe(event string, listener Listener) (cancel func(), err error)

func (*MemoryPubsub) SubscribeWithErr

func (m *MemoryPubsub) SubscribeWithErr(event string, listener ListenerWithErr) (cancel func(), err error)

type Pubsub

type Pubsub interface {
	Subscribe(event string, listener Listener) (cancel func(), err error)
	SubscribeWithErr(event string, listener ListenerWithErr) (cancel func(), err error)
	Publish(event string, message []byte) error
	Close() error
}

Pubsub is a generic interface for broadcasting and receiving messages. Implementors should assume high-availability with the backing implementation.

func New

func New(ctx context.Context, database *sql.DB, connectURL string) (Pubsub, error)

New creates a new Pubsub implementation using a PostgreSQL connection.

func NewInMemory

func NewInMemory() Pubsub

Jump to

Keyboard shortcuts

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