bus

package
v0.0.0-...-34a2968 Latest Latest
Warning

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

Go to latest
Published: Oct 6, 2020 License: Apache-2.0 Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrHandlerNotFound = errors.New("handler not found")

ErrHandlerNotFound defines an error if a handler is not found

Functions

func AddEventListener

func AddEventListener(handler HandlerFunc)

AddEventListener attaches a handler function to the event listener. Package level function.

func AddHandler

func AddHandler(implName string, handler HandlerFunc)

AddHandler attaches a handler function to the global bus. Package level function.

func AddHandlerCtx

func AddHandlerCtx(implName string, handler HandlerFunc)

AddHandlerCtx attaches a handler function to the global bus context. Package level function.

func ClearBusHandlers

func ClearBusHandlers()

func Dispatch

func Dispatch(msg Msg) error

func DispatchCtx

func DispatchCtx(ctx context.Context, msg Msg) error

func InTransaction

func InTransaction(ctx context.Context, fn func(ctx context.Context) error) error

InTransaction starts a transaction and store it in the context. The caller can then pass a function with multiple DispatchCtx calls that all will be executed in the same transaction. InTransaction will rollback if the callback returns an error.

func Publish

func Publish(msg Msg) error

Types

type Bus

type Bus interface {
	Dispatch(msg Msg) error
	DispatchCtx(ctx context.Context, msg Msg) error
	Publish(msg Msg) error

	// InTransaction starts a transaction and store it in the context.
	// The caller can then pass a function with multiple DispatchCtx calls that
	// all will be executed in the same transaction. InTransaction will rollback if the
	// callback returns an error.
	InTransaction(ctx context.Context, fn func(ctx context.Context) error) error

	AddHandler(handler HandlerFunc)
	AddHandlerCtx(handler HandlerFunc)
	AddEventListener(handler HandlerFunc)

	// SetTransactionManager allows the user to replace the internal
	// noop TransactionManager that is responsible for managing
	// transactions in `InTransaction`
	SetTransactionManager(tm TransactionManager)
}

Bus type defines the bus interface structure

func GetBus

func GetBus() Bus

Want to get rid of global bus

func New

func New() Bus

New initialize the bus

type CtxHandlerFunc

type CtxHandlerFunc func()

CtxHandlerFunc defines a context handler function.

type HandlerFunc

type HandlerFunc interface{}

HandlerFunc defines a handler function interface.

type InProcBus

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

InProcBus defines the bus structure

func (*InProcBus) AddEventListener

func (b *InProcBus) AddEventListener(handler HandlerFunc)

func (*InProcBus) AddHandler

func (b *InProcBus) AddHandler(handler HandlerFunc)

func (*InProcBus) AddHandlerCtx

func (b *InProcBus) AddHandlerCtx(handler HandlerFunc)

func (*InProcBus) Dispatch

func (b *InProcBus) Dispatch(msg Msg) error

Dispatch function dispatch a message to the bus.

func (*InProcBus) DispatchCtx

func (b *InProcBus) DispatchCtx(ctx context.Context, msg Msg) error

DispatchCtx function dispatch a message to the bus context.

func (*InProcBus) InTransaction

func (b *InProcBus) InTransaction(ctx context.Context, fn func(ctx context.Context) error) error

InTransaction defines an in transaction function

func (*InProcBus) Publish

func (b *InProcBus) Publish(msg Msg) error

Publish function publish a message to the bus listener.

func (*InProcBus) SetTransactionManager

func (b *InProcBus) SetTransactionManager(tm TransactionManager)

SetTransactionManager function assign a transaction manager to the bus.

type Msg

type Msg interface{}

Msg defines a message interface.

type TransactionManager

type TransactionManager interface {
	InTransaction(ctx context.Context, fn func(ctx context.Context) error) error
}

TransactionManager defines a transaction interface

Jump to

Keyboard shortcuts

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