eventing

package
v0.0.7 Latest Latest
Warning

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

Go to latest
Published: Mar 25, 2024 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrBusClosed = errors.New("eventbus is closed")
)

Functions

This section is empty.

Types

type EventEnvelope

type EventEnvelope struct {
	Id            uint64
	EventType     string
	EventVersion  uint
	Event         interface{}
	SourceType    EventSource
	SourceId      string
	UserId        string
	CreatedAt     uint64
	CausationId   string
	CorrelationId string
}

type EventMeta

type EventMeta struct {
	EventVersion uint
	SourceType   EventSource
	SourceId     string
}

type EventSource

type EventSource string

type Eventbus

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

func NewEventbus

func NewEventbus(db *sql.DB, clock utils.Clock) *Eventbus

NewEventbus creates a new event bus. The event bus is backed by a SQL database and uses the provided clock to timestamp events. It is basically functioning as both a pubsub and an event store.

func (*Eventbus) Close

func (bus *Eventbus) Close()

func (*Eventbus) Publish

func (bus *Eventbus) Publish(ctx app.Context, event interface{}, meta EventMeta) error

Publish publishes an event to the event bus. The event will be stored in the database and sent to all subscribers of the event source.

func (*Eventbus) PublishTx

func (bus *Eventbus) PublishTx(ctx app.Context, event interface{}, meta EventMeta, tx *sql.Tx) (PublishContinuation, error)

PublishTx publishes an event to the event bus. The event will be stored in the database and sent to all subscribers of the event source. The event will be published when the returned PublishContinuation is called. This allows the caller to publish the event after a transaction has been committed.

func (*Eventbus) Subscribe

func (bus *Eventbus) Subscribe(source EventSource) <-chan EventEnvelope

Subscribe subscribes to events from a given source. The returned channel will receive all events published by the source.

type PublishContinuation

type PublishContinuation func()

Jump to

Keyboard shortcuts

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