pubsub

package
v0.0.1-alpha.4 Latest Latest
Warning

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

Go to latest
Published: Jan 4, 2026 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrClosed = errors.New("pubsub: subscriber is closed")
)
View Source
var WireSet = wire.NewSet(
	ProvidePubSub,
)

Functions

This section is empty.

Types

type Config

type Config struct {
	App       string // app namespace prefix
	Namespace string

	Provider Provider

	HealthInterval time.Duration
	SendTimeout    time.Duration
	ChannelSize    int
}

type Consumer

type Consumer interface {
	// Subscribe(ctx context.Context, topics ...string) error
	// Publish(ctx context.Context, topics ...string) error
	Close() error
}

type InMemory

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

func (*InMemory) Publish

func (m *InMemory) Publish(ctx context.Context, topic string, payload []byte, options ...PublishOption) error

func (*InMemory) Subscribe

func (m *InMemory) Subscribe(
	ctx context.Context,
	topic string,
	handler func(payload []byte) error,
	options ...SubscribeOption,
) Consumer

type Option

type Option interface {
	Apply(*Config)
}

An Option configures a pubsub instance.

func WithApp

func WithApp(value string) Option

WithApp returns an option that set config app name.

func WithHealthCheckInterval

func WithHealthCheckInterval(value time.Duration) Option

WithHealthCheckInterval specifies the config health check interval. PubSub will ping Server if it does not receive any messages within the interval (redis, ...). To disable health check, use zero interval.

func WithNamespace

func WithNamespace(value string) Option

WithNamespace returns an option that set config namespace.

func WithSendTimeout

func WithSendTimeout(value time.Duration) Option

WithSendTimeout specifies the pubsub send timeout after which the message is dropped.

func WithSize

func WithSize(value int) Option

WithSize specifies the Go chan size in config that is used to buffer incoming messages.

type OptionFunc

type OptionFunc func(*Config)

OptionFunc is a function that configures a pubsub config.

func (OptionFunc) Apply

func (f OptionFunc) Apply(config *Config)

Apply calls f(config).

type Provider

type Provider string
const (
	ProviderMemory Provider = "inmemory"
	ProviderRedis  Provider = "redis"
)

type PubSub

type PubSub interface {
	Publisher
	Subscriber
}

func ProvidePubSub

func ProvidePubSub(config Config, client redis.UniversalClient) PubSub

type PublishConfig

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

type PublishOption

type PublishOption interface {
	Apply(*PublishConfig)
}

func WithPublishNamespace

func WithPublishNamespace(value string) PublishOption

WithPublishNamespace modifies publish config namespace.

type PublishOptionFunc

type PublishOptionFunc func(*PublishConfig)

PublishOptionFunc is a function that configures a publish config.

func (PublishOptionFunc) Apply

func (f PublishOptionFunc) Apply(config *PublishConfig)

Apply calls f(publishConfig).

type Publisher

type Publisher interface {
	// Publish message to topic
	Publish(ctx context.Context, topic string, payload []byte, options ...PublishOption) error
}

type Redis

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

func (*Redis) Close

func (r *Redis) Close(_ context.Context) error

func (*Redis) Publish

func (r *Redis) Publish(ctx context.Context, topic string, payload []byte, opts ...PublishOption) error

Publish event topic to message broker with payload.

func (*Redis) Subscribe

func (r *Redis) Subscribe(
	ctx context.Context,
	topic string,
	handler func(payload []byte) error,
	options ...SubscribeOption,
) Consumer

Subscribe consumer to process the event with payload.

type SubscribeConfig

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

type SubscribeOption

type SubscribeOption interface {
	Apply(*SubscribeConfig)
}

func WithChannelNamespace

func WithChannelNamespace(value string) SubscribeOption

WithNamespace returns an channel option that configures namespace.

type SubscribeOptionFunc

type SubscribeOptionFunc func(*SubscribeConfig)

SubscribeOptionFunc is a function that configures a subscription config.

func (SubscribeOptionFunc) Apply

func (f SubscribeOptionFunc) Apply(config *SubscribeConfig)

Apply calls f(subscribeConfig).

type Subscriber

type Subscriber interface {
	// Subscribe consumer to process the topic with payload, this should be blocking operation.
	Subscribe(ctx context.Context, topic string, handler func(payload []byte) error, options ...SubscribeOption) Consumer
}

Jump to

Keyboard shortcuts

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