pubsub

package module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jul 27, 2021 License: MIT Imports: 7 Imported by: 1

README

pubsub

Providers

Documentation

Index

Constants

This section is empty.

Variables

View Source
var NewID = func() string {
	return ulid.MustNew(ulid.Now(), entropy).String()
}

NewID creates a new, random, sequential id.

Functions

This section is empty.

Types

type Message

type Message interface {
	ID() string
	Data() []byte
}

A Message is a pub/sub message.

func NewMessage

func NewMessage(data []byte) Message

NewMessage creates a new message.

type Queue

type Queue interface {
	io.Closer
	Topic(ctx context.Context, name string) (Topic, error)
}

A Queue is a pub/sub queue. It contains topics.

type RetryPolicy

type RetryPolicy struct {
	MaxAttempts            int
	MinBackoff, MaxBackoff time.Duration
}

A RetryPolicy configures how messages in the queue should be retried.

func (*RetryPolicy) BackoffDuration

func (retryPolicy *RetryPolicy) BackoffDuration(retries int) time.Duration

BackoffDuration returns the backoff duration for the given number of retries.

type SubscribeConfig

type SubscribeConfig struct {
	RetryPolicy RetryPolicy
}

The SubscribeConfig customizes how subscription works.

func NewSubscribeConfig

func NewSubscribeConfig(opts ...SubscribeOption) *SubscribeConfig

NewSubscribeConfig creates a new SubscribeConfig from the given options.

type SubscribeHandler

type SubscribeHandler = func(ctx context.Context, msg SubscriberMessage)

A SubscribeHandler is a function invoked for pub/sub messages sent to a topic.

type SubscribeOption

type SubscribeOption = func(config *SubscribeConfig)

A SubscribeOption customizes the SubscribeConfig.

func WithMaxAttempts

func WithMaxAttempts(maxAttempts int) SubscribeOption

WithMaxAttempts sets the max attempts in the subscribe config.

func WithMaxBackoff

func WithMaxBackoff(maxBackoff time.Duration) SubscribeOption

WithMaxBackoff sets the max backoff in the subscribe config.

func WithMinBackoff

func WithMinBackoff(minBackoff time.Duration) SubscribeOption

WithMinBackoff sets the min backoff in the subscribe config.

type SubscriberMessage

type SubscriberMessage interface {
	Message
	// Ack signals completion of a message which will then be removed from the pub/sub topic.
	Ack()
	// Nack signals failure of message processing. The message will be retried according to
	// the retry policy of the subscription.
	Nack()
}

A SubscriberMessage is a pub sub message with Ack and Nack methods.

type Subscription

type Subscription interface {
	// Receive receives messages sent to the subscription. The given handler
	// will be invoked for each message in a goroutine. To stop `Receive`
	// cancel the context.
	Receive(ctx context.Context, handler SubscribeHandler) error
}

A Subscription is a single subscription to a topic.

type Topic

type Topic interface {
	// Publish publishes a message to the topic.
	Publish(ctx context.Context, msg Message) error
	// Subscribe creates (or resumes) a subscription to a topic. All messages
	// published to the topic will be sent to all subscribers.
	Subscribe(ctx context.Context, name string, opts ...SubscribeOption) (Subscription, error)
}

A Topic is a named, logical channel which messages can be published to.

Directories

Path Synopsis
providers
google
Package google implements a Pub/Sub queue using Google Cloud Pub/Sub.
Package google implements a Pub/Sub queue using Google Cloud Pub/Sub.
memory
Package memory contains an in-memory implementation of a pub/sub queue.
Package memory contains an in-memory implementation of a pub/sub queue.

Jump to

Keyboard shortcuts

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