mempubsub

package
v1.0.2 Latest Latest
Warning

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

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

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	// Timeout is the time that we should wait for an Ack or a Nack.
	Timeout time.Duration

	// Concurrency specifies the maximum number of concurrent requests.
	Concurrency int

	// BufferSize is the size of the Go channel buffer for a subscription.
	BufferSize int
}

Config holds the configuration for the publisher/subscriber.

func DefaultConfig

func DefaultConfig() Config

DefaultConfig returns the default configuration.

type PubSub

type PubSub struct {
	*lifecycle.Lifecycle
	Config
	// contains filtered or unexported fields
}

PubSub implements a publisher/subscriber using Go channels. This implementation works only on a single node, i.e. handlers are not distributed. In order to distribute the load across a cluster, a persistent message queue (such as RabbitMQ or Kafka) should instead be used.

func New

func New(cfg Config) *PubSub

New returns a new publisher/subscriber.

func (*PubSub) Close

func (p *PubSub) Close() error

Close closes all resources.

func (*PubSub) IsConnected

func (p *PubSub) IsConnected() bool

IsConnected return true is connected.

func (*PubSub) Publish

func (p *PubSub) Publish(topic string, messages ...*message.Message) error

Publish publishes the given messages to the given topic. This function returns immediately after sending the messages to the Go channel(s), although it will block if the concurrency limit (defined by Config.Concurrency) has been reached.

func (*PubSub) PublishWithOpts

func (p *PubSub) PublishWithOpts(topic string, msg *message.Message, _ ...spi.Option) error

PublishWithOpts simply calls Publish since options are not supported.

func (*PubSub) Subscribe

func (p *PubSub) Subscribe(ctx context.Context, topic string) (<-chan *message.Message, error)

Subscribe subscribes to a topic and returns the Go channel over which messages are sent. The returned channel will be closed when Close() is called on this struct.

func (*PubSub) SubscribeWithOpts

func (p *PubSub) SubscribeWithOpts(_ context.Context, topic string, _ ...spi.Option) (<-chan *message.Message, error)

SubscribeWithOpts subscribes to a topic and returns the Go channel over which messages are sent. The returned channel will be closed when Close() is called on this struct.

Jump to

Keyboard shortcuts

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