driver

package
v0.4.10 Latest Latest
Warning

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

Go to latest
Published: Jul 13, 2026 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Driver

type Driver interface {

	// Subscribe registers a named subscriber for the given topic and returns
	// a channel that will receive messages published to matching topics.
	Subscribe(name string, topic string) (<-chan entity.PubsubMessage, error)

	// GetSubscribers returns the names of all subscribers matching the given topic,
	// including those subscribed to parent topics.
	GetSubscribers(topic string) []string

	// Unsubscribe removes a subscriber from receiving events for the given topic.
	// The subscriber's channel is closed.
	Unsubscribe(name string, topic string) error

	// Publish dispatches an event to local subscribers and handles
	// cross-instance delivery (e.g., via Redis).
	// The from parameter is the publisher's name, used to skip self-delivery.
	// ctx applies only to the cross-instance hop; local fan-out runs to
	// completion regardless, so partial delivery is possible if ctx is
	// canceled mid-publish.
	Publish(ctx context.Context, from string, topic string, kind string, payload any) error

	// lifecycle
	common.Daemon
}

Driver defines the interface for subscription storage and event delivery.

func NewKafka

func NewKafka(brokers []string, groupID string, log log.Logger, opts ...Option) (Driver, error)

func NewMemory

func NewMemory(log log.Logger, opts ...Option) Driver

func NewRedis

func NewRedis(client *redis.Client, log log.Logger, opts ...Option) (Driver, error)

type OnFull added in v0.4.9

type OnFull int

OnFull selects what a driver does when a subscriber's pending queue is full, meaning the subscriber is not draining its channel fast enough.

const (
	// DropMessage discards the message and keeps the subscription. The
	// subscriber never learns that it missed a message.
	DropMessage OnFull = iota
	// DropSubscriber closes the subscriber's channel and removes it from the
	// topic. A subscriber that reconnects and resumes from its own cursor
	// loses nothing; one that is silently skipped loses a message forever.
	DropSubscriber
)

type Option added in v0.4.9

type Option func(*options)

Option configures a driver.

func WithChannelBuffer added in v0.4.9

func WithChannelBuffer(n int) Option

WithChannelBuffer sets the buffer size of the channel handed to subscribers.

func WithOnFull added in v0.4.9

func WithOnFull(v OnFull) Option

WithOnFull sets the policy applied when a subscriber's queue is full. The default is DropMessage, which preserves the historical behavior.

func WithQueueCap added in v0.4.9

func WithQueueCap(n int) Option

WithQueueCap bounds each subscriber's pending queue.

type Stats added in v0.4.9

type Stats interface {
	// Dropped returns the number of messages discarded because a subscriber
	// could not keep up.
	Dropped() uint64
	// Evicted returns the number of subscribers removed because they could
	// not keep up.
	Evicted() uint64
}

Stats is implemented by drivers that report delivery statistics.

Jump to

Keyboard shortcuts

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