inmem

package
v0.3.1 Latest Latest
Warning

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

Go to latest
Published: Mar 14, 2024 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrClosed = errors.New("pubsub: subscriber is closed")
)

Functions

This section is empty.

Types

type Config

type Config struct {
	App       string
	Namespace string

	SendTimeout time.Duration
	ChannelSize int
}

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 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 PubSub

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

func New

func New(options ...Option) *PubSub

New create an instance of memory pubsub implementation.

func (*PubSub) Close

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

func (*PubSub) Publish

func (ps *PubSub) Publish(ctx context.Context, topic string, payload []byte, opts ...pubsub.PublishOption) error

Publish event to message broker with payload.

func (*PubSub) Subscribe

func (ps *PubSub) Subscribe(
	ctx context.Context,
	topic string,
	handler func(payload *pubsub.Msg) error,
	options ...pubsub.SubscribeOption,
) pubsub.Consumer

Subscribe consumer to process the event with payload.

func (*PubSub) SubscribeChan

func (ps *PubSub) SubscribeChan(
	ctx context.Context,
	topic string,
	options ...pubsub.SubscribeOption,
) (pubsub.Consumer, <-chan *pubsub.Msg)

Jump to

Keyboard shortcuts

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