pubsub

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Oct 6, 2023 License: MIT Imports: 7 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewDefaultBusInformer

func NewDefaultBusInformer(bus EventBus) (actuator.Informer, error)

func Publish

func Publish(event Event)

func Register

func Register(subscribers ...Subscriber)

func ReplaceGlobal

func ReplaceGlobal(bus EventBus, publisher Publisher)

func Run

func Run()

Types

type DebugLog

type DebugLog func(ctx context.Context, msgFormat string, args ...interface{})

type DefaultBusInformer

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

func (DefaultBusInformer) Key

func (d DefaultBusInformer) Key() string

func (DefaultBusInformer) Value

func (d DefaultBusInformer) Value() interface{}

type DefaultEventBus

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

func NewDefaultEventBus

func NewDefaultEventBus(opts ...EventBusOpt) *DefaultEventBus

func (*DefaultEventBus) Deliver

func (b *DefaultEventBus) Deliver(event Event)

func (*DefaultEventBus) Register

func (b *DefaultEventBus) Register(subscribers ...Subscriber)

func (*DefaultEventBus) Run

func (b *DefaultEventBus) Run()

func (*DefaultEventBus) Stop

func (b *DefaultEventBus) Stop()

type DefaultPublisher

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

func NewDefaultPublisher

func NewDefaultPublisher(bus EventBus, opts ...PublisherOpt) *DefaultPublisher

func (*DefaultPublisher) Publish

func (p *DefaultPublisher) Publish(event Event)

type Event

type Event interface {
	// Identifier returns the ID of event
	Identifier() string

	// Name returns event name of current event
	Name() string

	// Context returns the current context of event
	Context() context.Context

	// Payload returns event payload of current event
	Payload() interface{}

	// String convert event data to string
	String() string
}

type EventBus

type EventBus interface {

	// Register subscriber(s) with the bus
	Register(subscribers ...Subscriber)

	// Deliver an event
	Deliver(event Event)

	// Run the bus
	Run()

	// Stop the bus
	Stop()
}

func GetEventBus

func GetEventBus() EventBus

type EventBusOpt

type EventBusOpt func(bus *DefaultEventBus)

func WithEventBusDebugLog

func WithEventBusDebugLog(debugLog DebugLog) EventBusOpt

func WithEventChannelSize

func WithEventChannelSize(size int) EventBusOpt

func WithEventExecutor

func WithEventExecutor(executor Executor) EventBusOpt

type Executor

type Executor interface {

	// Execute a function
	Execute(fn func())
}

type Publisher

type Publisher interface {

	// Publish an event
	Publish(event Event)
}

func GetPublisher

func GetPublisher() Publisher

type PublisherOpt

type PublisherOpt func(pub *DefaultPublisher)

func WithPublisherDebugLog

func WithPublisherDebugLog(debugLog DebugLog) PublisherOpt

func WithPublisherNotLogPayload

func WithPublisherNotLogPayload(events []string) PublisherOpt

type Subscriber

type Subscriber interface {

	// Supports indicates whether an event is supported by this Subscriber or not.
	Supports(event Event) bool

	// Handle a supported Event that indicated by the Supports function.
	Handle(event Event)
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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