pubsub

package
v0.4.0 Latest Latest
Warning

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

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

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FormatTopic

func FormatTopic(app, ns, topic string) string

Types

type Config

type Config struct {
	App       string
	Namespace string

	SendTimeout time.Duration
	ChannelSize int
}

type Consumer

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

type Msg

type Msg struct {
	Topic   string
	Payload []byte
}

type PublishConfig

type PublishConfig struct {
	App       string
	Namespace string
}

func (*PublishConfig) Apply

func (c *PublishConfig) Apply(pc *PublishConfig)

type PublishOption

type PublishOption interface {
	Apply(*PublishConfig)
}

func WithPublishApp

func WithPublishApp(value string) PublishOption

WithPublishApp modifies publish config app identifier.

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 topic to message broker with payload.
	Publish(ctx context.Context, topic string, payload []byte,
		options ...PublishOption) error
}

type SubscribeConfig

type SubscribeConfig struct {
	Topics         []string
	App            string
	Namespace      string
	HealthInterval time.Duration
	SendTimeout    time.Duration
	ChannelSize    int
}

type SubscribeOption

type SubscribeOption interface {
	Apply(*SubscribeConfig)
}

SubscribeOption configures a subscription config.

func WithChannelHealthCheckInterval

func WithChannelHealthCheckInterval(value time.Duration) SubscribeOption

WithChannelHealthCheckInterval specifies the channel health check interval. PubSub will ping Server if it does not receive any messages within the interval. To disable health check, use zero interval.

func WithChannelNamespace

func WithChannelNamespace(value string) SubscribeOption

WithNamespace returns an channel option that configures namespace.

func WithChannelSendTimeout

func WithChannelSendTimeout(value time.Duration) SubscribeOption

WithChannelSendTimeout specifies the channel send timeout after which the message is dropped.

func WithChannelSize

func WithChannelSize(value int) SubscribeOption

WithChannelSize specifies the Go chan size that is used to buffer incoming messages for subscriber.

func WithTopics

func WithTopics(topics ...string) SubscribeOption

WithTopics specifies the topics to subsribe.

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(ctx context.Context, topic string,
		handler func(payload *Msg) error, options ...SubscribeOption) Consumer
	SubscribeChan(ctx context.Context, topic string,
		options ...SubscribeOption) (Consumer, <-chan *Msg)
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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