pubsub

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Jun 3, 2023 License: Apache-2.0, BSD-3-Clause, ISC Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type GetPostgresListenerFunc

type GetPostgresListenerFunc func() (*pq.Listener, error)

GetPostgresListenerFunc is a type of function that returns a new pq.Listener ready to start listening to pubsub channels. You must provide such a function to PostgresPubSub.

type Message

type Message struct {
	UUID    uuid.UUID
	Time    time.Time
	Payload []byte
}

Message is a pub/sub message.

type PostgresPubSub

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

PostgresPubSub is an implementation of pubsub using PostgreSQL notifications.

func NewPostgresPubSub

func NewPostgresPubSub(getListener GetPostgresListenerFunc, chanPrefix string, log *log.Entry) (*PostgresPubSub, error)

NewPostgresPubSub creates a new PostgreSQL publish/subscribe engine.

func (*PostgresPubSub) Publish

func (p *PostgresPubSub) Publish(channel string, message Message) error

Publish publishes a message on a given channel.

func (*PostgresPubSub) Subscribe

func (p *PostgresPubSub) Subscribe(channel string) (Stream, error)

Subscribe listens for messages on a given channel.

type PostgresStream

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

PostgresStream is a handler for a single PostgreSQL subscription.

func (*PostgresStream) Channel

func (s *PostgresStream) Channel() <-chan Message

Channel returns a channel of streaming messages.

func (*PostgresStream) Close

func (s *PostgresStream) Close() error

Close ends the pubsub stream.

type PubSub

type PubSub interface {
	Publish(channel string, message Message) error
	Subscribe(channel string) (Stream, error)
}

PubSub is an interface for publish/subscribe messaging systems.

type Stream

type Stream interface {
	Channel() <-chan Message
	Close() error
}

Stream is a stream of incoming pub/sub messages.

Jump to

Keyboard shortcuts

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