broker

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Jun 30, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Broker

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

func New

func New() *Broker

func (*Broker) SetObserver

func (b *Broker) SetObserver(o Observer)

func (*Broker) Subscriptions

func (b *Broker) Subscriptions() []Subscription

func (*Broker) UnsubscribeAll

func (b *Broker) UnsubscribeAll(subscriberID string)

type Event

type Event[T any] struct {
	ID            string
	CorrelationID string
	Name          string
	Timestamp     time.Time
	Data          T
	Metadata      Metadata
}

type Handler

type Handler[T any] func(ctx context.Context, e Event[T]) error

type Metadata

type Metadata struct {
	ActorID   *uuid.UUID
	PartnerID *uuid.UUID
	IPAddress string
	UserAgent string
	Extra     map[string]string
}

type ObservedEvent

type ObservedEvent struct {
	EventName           string
	CorrelationID       string
	Timestamp           time.Time
	ActorID             *uuid.UUID
	PartnerID           *uuid.UUID
	PayloadJSON         []byte
	MetadataJSON        []byte
	SubscribersNotified int
	Err                 error
}

type Observer

type Observer func(ctx context.Context, info ObservedEvent)

type PublishOption

type PublishOption func(correlationID *string, md *Metadata)

func WithCorrelationID

func WithCorrelationID(id string) PublishOption

func WithMetadata

func WithMetadata(md Metadata) PublishOption

type Subscription

type Subscription struct {
	EventName    string
	SubscriberID string
}

type Topic

type Topic[T any] struct {
	// contains filtered or unexported fields
}

func NewTopic

func NewTopic[T any](name string) *Topic[T]

func (*Topic[T]) Name

func (t *Topic[T]) Name() string

func (*Topic[T]) Publish

func (t *Topic[T]) Publish(ctx context.Context, b *Broker, data T, opts ...PublishOption) error

func (*Topic[T]) Subscribe

func (t *Topic[T]) Subscribe(b *Broker, subscriberID string, h Handler[T])

func (*Topic[T]) Unsubscribe

func (t *Topic[T]) Unsubscribe(b *Broker, subscriberID string)

Jump to

Keyboard shortcuts

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