bus

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Nov 15, 2024 License: MIT, Apache-2.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// CtxKeyTxID tx id context key
	CtxKeyTxID = ctxKey(116)

	// CtxKeySource source context key
	CtxKeySource = ctxKey(117)
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Broker

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

Broker controls the message bus

func New

func New(g IDGenerator) (*Broker, error)

New inits a new bus

func (*Broker) DeregisterHandler

func (b *Broker) DeregisterHandler(key string)

DeregisterHandler deletes handler from the registry

func (*Broker) DeregisterTopics

func (b *Broker) DeregisterTopics(topics ...string)

DeregisterTopics deletes topic

func (*Broker) Emit

func (b *Broker) Emit(ctx context.Context,
	topic string, data interface{},
) error

Emit inits a new message and delivers to the interested in handlers with sync safety

func (*Broker) EmitWithOpts

func (b *Broker) EmitWithOpts(ctx context.Context,
	topic string, data interface{}, options ...MessageOption,
) error

EmitWithOpts inits a new message and delivers to the interested in handlers with sync safety and options

func (*Broker) HandlerKeys

func (b *Broker) HandlerKeys() []string

HandlerKeys returns list of registered handler keys

func (*Broker) HandlerTopicSubscriptions

func (b *Broker) HandlerTopicSubscriptions(handlerKey string) []string

HandlerTopicSubscriptions returns all topic subscriptions of the handler

func (*Broker) RegisterHandler

func (b *Broker) RegisterHandler(key string, h Handler)

RegisterHandler re/register the handler to the registry

func (*Broker) RegisterTopics

func (b *Broker) RegisterTopics(topics ...string)

RegisterTopics registers topics and fulfills handlers

func (*Broker) TopicHandlerKeys

func (b *Broker) TopicHandlerKeys(topic string) []string

TopicHandlerKeys returns all handlers for the topic

func (*Broker) Topics

func (b *Broker) Topics() []string

Topics lists the all registered topics

type BrokerError

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

func (*BrokerError) Error

func (e *BrokerError) Error() string

type Handler

type Handler struct {

	// handler func to process messages
	Handle func(ctx context.Context, m Message)

	// topic matcher as regex pattern
	Matcher string
	// contains filtered or unexported fields
}

Handler is a receiver for message reference with the given regex pattern

type IDGenerator

type IDGenerator interface {
	Generate() string
}

IDGenerator is a sequential unique id generator interface

type Message

type Message struct {
	ID         string      // identifier
	TxID       string      // transaction identifier
	Topic      string      // topic name
	Source     string      // source of the message
	OccurredAt time.Time   // inception time in nanoseconds
	Data       interface{} // actual message data
}

Message is data structure for any logs

type MessageOption

type MessageOption = func(Message) Message

MessageOption is a function type to mutate message fields

func WithID

func WithID(id string) MessageOption

WithID returns an option to set message's id field

func WithOccurredAt

func WithOccurredAt(t time.Time) MessageOption

WithOccurredAt returns an option to set message's occurredAt field

func WithSource

func WithSource(source string) MessageOption

WithSource returns an option to set message's source field

func WithTxID

func WithTxID(txID string) MessageOption

WithTxID returns an option to set message's txID field

type Next

type Next func() string

Next is a sequential unique id generator func type

func (Next) Generate

func (n Next) Generate() string

Generate is an implementation of IDGenerator for bus.Next fn type

type Sequential

type Sequential struct {
	Format string
	// contains filtered or unexported fields
}

func (*Sequential) Generate

func (g *Sequential) Generate() string

Jump to

Keyboard shortcuts

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