eventbus

package
v0.0.4 Latest Latest
Warning

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

Go to latest
Published: Aug 26, 2022 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type DefaultEvent

type DefaultEvent struct {
	Topic string `json:"topic"`

	Producer string `json:"producer"`
}

func NewDefaultEvent

func NewDefaultEvent(topic string, producer string) DefaultEvent

func (*DefaultEvent) GetProducer

func (e *DefaultEvent) GetProducer() string

func (*DefaultEvent) GetTopic

func (e *DefaultEvent) GetTopic() string

type Event

type Event interface {
	GetTopic() string

	GetProducer() string

	GetData() interface{}
}

Event

type Eventbus added in v0.0.2

type Eventbus interface {
	// Register registers the event to the topic
	Register(topic string, subscribers ...*Subscriber) error
	// Post posts the event to the topic
	Post(ctx context.Context, event Event) error
	// Serve starts the event bus async
	Serve(ctx context.Context)
}

Eventbus is the interface for event bus

func NewEventbus

func NewEventbus(mq messageQueue, workers int) Eventbus

NewEventbus creates the event bus

type Subscriber

type Subscriber struct {
	// UID
	UID func() string

	// NewEvent is a function that creates a new event from a message.
	NewEvent func() Event

	// HandleEvent handles the event
	HandleEvent func(ctx context.Context, event Event) error
}

Subscriber is the interface for subscriber

type Subscribers added in v0.0.2

type Subscribers struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

Subscribers is the list of subscribers

func (*Subscribers) Add added in v0.0.2

func (s *Subscribers) Add(sub *Subscriber)

func (*Subscribers) Contains added in v0.0.2

func (s *Subscribers) Contains(uid string) bool

func (*Subscribers) Each added in v0.0.2

func (s *Subscribers) Each(f func(sub *Subscriber))

func (*Subscribers) Len added in v0.0.2

func (s *Subscribers) Len() int

Jump to

Keyboard shortcuts

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