pubsub

package
v0.0.0-...-98ba599 Latest Latest
Warning

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

Go to latest
Published: Jul 2, 2020 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Overview

Package pubsub is a simple, label-based, thread-safe PubSub implementation.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type DefaultPublisher

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

func NewPublisher

func NewPublisher() *DefaultPublisher

func (*DefaultPublisher) Close

func (pu *DefaultPublisher) Close() error

func (*DefaultPublisher) Publish

func (pu *DefaultPublisher) Publish(msg Msg) error

func (*DefaultPublisher) Subscribe

func (pu *DefaultPublisher) Subscribe(opts ...SubscriptionOptions) *Subscription

func (*DefaultPublisher) Unsubscribe

func (pu *DefaultPublisher) Unsubscribe(sub *Subscription) error

type EmptyMsg

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

func NewEmptyMsg

func NewEmptyMsg(lbls labels.Labels, createdAt time.Time) *EmptyMsg

func (*EmptyMsg) CreatedAt

func (gm *EmptyMsg) CreatedAt() time.Time

func (*EmptyMsg) Labels

func (gm *EmptyMsg) Labels() labels.Labels

type GenericMsg

type GenericMsg struct {
	*EmptyMsg
	// contains filtered or unexported fields
}

func NewGenericMsg

func NewGenericMsg(lbls labels.Labels, createdAt time.Time, payload interface{}) *GenericMsg

func (*GenericMsg) Payload

func (pm *GenericMsg) Payload() interface{}

type Msg

type Msg interface {
	Labels() labels.Labels
	CreatedAt() time.Time
}

type Publisher

type Publisher interface {
	io.Closer
	Subscribe(opts ...SubscriptionOptions) *Subscription
	Unsubscribe(sub *Subscription) error
	Publish(msg Msg) error
}

type Subscription

type Subscription struct {
	SubscriptionOptions
	Ch chan Msg
}

type SubscriptionOptions

type SubscriptionOptions struct {
	// Buffer is the size of the buffer kept for incoming messages. In case the buffer is full, subsequent messages will
	// be dropped. The default size of the buffer is 10.
	Buffer int

	// LabelMatcher allows subscribers to narrow the selection of messages that they are notified of.
	// By default there is no matcher; the subscriber will receive all messages published by the publisher.
	LabelMatcher labels.Matcher
}

SubscriptionOptions allow subscribers to customize the type and behaviour of the subscription.

Jump to

Keyboard shortcuts

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