messaging

package
v0.9.3 Latest Latest
Warning

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

Go to latest
Published: Feb 7, 2025 License: Apache-2.0 Imports: 5 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Event

type Event struct {
	ID          string         `json:"id"`
	Source      string         `json:"source"`
	SpecVersion string         `json:"specversion"`
	Type        string         `json:"type"`
	Data        map[string]any `json:"data"`
	Time        time.Time      `json:"time"`
}

Event represents a generic event

type EventBus

type EventBus interface {
	Publish(ctx context.Context, event Event) error
	Subscribe(eventType string, handler func(ctx context.Context, event Event)) error
	Close() error // Clean up resources
}

EventBus defines the interface for publishing and subscribing to events

var DefaultEventBus EventBus

type EventWithCtx

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

EventWithCtx couples an event with its associated context.

type MemoryEventBus

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

MemoryEventBus is an in-memory implementation of the EventBus using channels.

func NewMemoryEventBus

func NewMemoryEventBus() (*MemoryEventBus, error)

NewEventBus creates a new MemoryEventBus.

func (*MemoryEventBus) Close

func (b *MemoryEventBus) Close() error

Close shuts down the event bus and cleans up all channels.

func (*MemoryEventBus) Publish

func (b *MemoryEventBus) Publish(ctx context.Context, event Event) error

Publish sends an event to all subscribers of the specified event type asynchronously.

func (*MemoryEventBus) Subscribe

func (b *MemoryEventBus) Subscribe(eventType string, handler func(ctx context.Context, event Event)) error

Subscribe registers a handler for the specified event type. It returns an error if the bus is closed.

Jump to

Keyboard shortcuts

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