pubsub

package
v1.34.3 Latest Latest
Warning

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

Go to latest
Published: Nov 27, 2025 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrInvalidConfig = errors.New("invalid config")
	ErrPubSubClosed  = errors.New("pubsub is closed")
	ErrInvalidTopic  = errors.New("invalid topic name")
)

Functions

This section is empty.

Types

type MemoryPubSub added in v1.34.3

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

func NewMemory

func NewMemory(opts ...Option) *MemoryPubSub

func (*MemoryPubSub) Close added in v1.34.3

func (m *MemoryPubSub) Close() error

func (*MemoryPubSub) Publish added in v1.34.3

func (m *MemoryPubSub) Publish(ctx context.Context, topic string, data []byte) error

Publish sends a message to all subscribers of the given topic. This method blocks until all subscribers have received the message or until ctx is cancelled or the pubsub instance is closed.

func (*MemoryPubSub) Subscribe added in v1.34.3

func (m *MemoryPubSub) Subscribe(ctx context.Context, topic string) (*Subscription, error)

type Message

type Message struct {
	Topic string
	Data  []byte
}

type Option

type Option func(*options)

func WithBufferSize

func WithBufferSize(bufferSize uint) Option

type PubSub

type PubSub interface {
	Publisher
	Subscriber
	// Close closes the pubsub instance and releases all resources.
	Close() error
}

type Publisher

type Publisher interface {
	// Publish publishes a message to a topic.
	// All subscribers to the topic will receive the message (fan-out).
	Publish(ctx context.Context, topic string, data []byte) error
}

type RedisConfig

type RedisConfig struct {
	// Client is the Redis client to use.
	// If nil, a client is created from the URL.
	// If both Client and URL are provided, Client takes precedence.
	Client *redis.Client

	// URL is the Redis URL to use.
	// If empty, the Redis client is not created.
	URL string

	// Prefix is the prefix to use for all topics.
	Prefix string
}

RedisConfig configures the Redis pubsub backend.

type RedisPubSub added in v1.34.3

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

func NewRedis

func NewRedis(config RedisConfig, opts ...Option) (*RedisPubSub, error)

func (*RedisPubSub) Close added in v1.34.3

func (r *RedisPubSub) Close() error

func (*RedisPubSub) Publish added in v1.34.3

func (r *RedisPubSub) Publish(ctx context.Context, topic string, data []byte) error

func (*RedisPubSub) Subscribe added in v1.34.3

func (r *RedisPubSub) Subscribe(ctx context.Context, topic string) (*Subscription, error)

type Subscriber

type Subscriber interface {
	// Subscribe subscribes to a topic and returns a channel for receiving messages.
	// The channel will be closed when the context is cancelled.
	Subscribe(ctx context.Context, topic string) (*Subscription, error)
}

type Subscription

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

func (*Subscription) Close

func (s *Subscription) Close()

func (*Subscription) Receive

func (s *Subscription) Receive() <-chan Message

Jump to

Keyboard shortcuts

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