broker

package
v0.1.4 Latest Latest
Warning

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

Go to latest
Published: Mar 26, 2021 License: MIT Imports: 9 Imported by: 5

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Shutdown

func Shutdown() error

func Start

func Start() error

Types

type Broker

type Broker interface {
	Options() Options
	NewPublisher(topic string, opts ...PublishOption) (pub Publisher, err error)
	NewSubscriber(subscription string, hdlr Handler, opts ...SubscribeOption) (sub Subscriber, err error)
	Start() error
	Shutdown() error
}

Broker is an interface used for asynchronous messaging.

var DefaultBroker Broker

func NewBroker

func NewBroker(ctx context.Context, opts ...Option) Broker

NewBroker creates and returns a new Broker based on the packages within.

type Handler

type Handler func(context.Context, *pubsub.Message)

Handler is used to process messages via a subscription of a topic. The handler is passed a publication interface which contains the message and optional Ack method to acknowledge receipt of the message.

type Option

type Option func(*Options)

func ClientOption

func ClientOption(c ...option.ClientOption) Option

ClientOption is a broker Option which allows google pubsub client options to be set for the client

func Context

func Context(ctx context.Context) Option

Context specifies a context for the service. Can be used to signal shutdown of the service Can be used for extra option values.

func ErrorHandler

func ErrorHandler(h Handler) Option

ErrorHandler will catch all broker errors that cant be handled in normal way, for example Codec errors

func ProjectID

func ProjectID(id string) Option

ProjectID provides an option which sets the google project id

type Options

type Options struct {
	ClientOptions []option.ClientOption
	ProjectID     string

	// Handler executed when error happens in broker message
	// processing
	ErrorHandler Handler

	// Other options for implementations of the interface
	// can be stored in a context
	Context context.Context
}

type PublishOption

type PublishOption func(*PublishOptions)

func PublishAsync

func PublishAsync(b bool) PublishOption

func PublishContext

func PublishContext(ctx context.Context) PublishOption

PublishContext set context

func WithPublishSettings

func WithPublishSettings(publishSettings pubsub.PublishSettings) PublishOption

type PublishOptions

type PublishOptions struct {
	// pubsub PublishSettings
	PublishSettings pubsub.PublishSettings
	// publishes msg to the topic asynchronously if set to true.
	// Default false. i.e., publishes synchronously(blocking)
	Async bool
	// Other options for implementations of the interface
	// can be stored in a context
	Context context.Context
}

TODO support more pubsub.PublishSettings settings

type Publisher

type Publisher interface {
	Publish(ctx context.Context, msg *pubsub.Message) error
	Stop()
}

func NewPublisher

func NewPublisher(topic string, opts ...PublishOption) (Publisher, error)

type RecoveryHandler added in v0.1.2

type RecoveryHandler func(context.Context, *pubsub.Message, interface{})

RecoveryHandler is a function that is called when the recovery middleware recovers from a panic. The func takes the receive context, message and the return value from recover which reports whether the goroutine is panicking. Example usages of HandlerFunc could be to log panics or nack/ack messages which cause panics.

type SubscribeOption

type SubscribeOption func(*SubscribeOptions)

func SubscribeContext

func SubscribeContext(ctx context.Context) SubscribeOption

SubscribeContext set context

func WithReceiveSettings

func WithReceiveSettings(receiveSettings pubsub.ReceiveSettings) SubscribeOption

func WithRecoveryHandler added in v0.1.2

func WithRecoveryHandler(r RecoveryHandler) SubscribeOption

WithRecoveryHandler sets the function for recovering from a panic.

type SubscribeOptions

type SubscribeOptions struct {
	// pubsub ReceiveSettings
	ReceiveSettings pubsub.ReceiveSettings

	RecoveryHandler RecoveryHandler

	// Other options for implementations of the interface
	// can be stored in a context
	Context context.Context
}

TODO support more pubsub.ReceiveSettings settings

type Subscriber

type Subscriber interface {
	Start()
	Stop()
}

Subscriber is a convenience ~return~ type for the Subscribe method

func NewSubscriber added in v0.1.2

func NewSubscriber(subscription string, handler Handler, opts ...SubscribeOption) (Subscriber, error)

Jump to

Keyboard shortcuts

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