event

package
v0.1.21 Latest Latest
Warning

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

Go to latest
Published: Jul 17, 2025 License: Apache-2.0 Imports: 10 Imported by: 1

Documentation

Overview

Package event defines Fluxor's publish-subscribe mechanism that allows observers to react to execution lifecycle events.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func QueueOf

func QueueOf[T any](s *Service, name string) (messaging.Queue[T], error)

func SetListenerOf

func SetListenerOf[T any](s *Service, handler func(*Event[T])) error

Types

type Context

type Context struct {
	ProcessID   string `json:"processID"`
	TaskID      string `json:"taskID"`
	EventType   string `json:"eventType"`
	Service     string `json:"service"`
	Method      string `json:"method"`
	TimeTakenMs int    `json:"timeTakenMs"`
}

type Event

type Event[T any] struct {
	Context   *Context               `json:"context"`
	CreatedAt time.Time              `json:"createdAt"`
	Metadata  map[string]interface{} `json:"metadata"`
	Data      T                      `json:"data"`
}

func NewEvent

func NewEvent[T any](context *Context, data T) *Event[T]

type Listener

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

func NewListener

func NewListener[T any](publisher *Publisher[T], handler func(*Event[T])) *Listener[T]

func (*Listener[T]) Start

func (l *Listener[T]) Start()

func (*Listener[T]) Stop

func (l *Listener[T]) Stop()

type Option

type Option func(s *Service)

func WithNewFsQueueConfig

func WithNewFsQueueConfig(newConfig func(name string) fs.Config) Option

WithNewFsQueueConfig sets the new file system queue configuration

func WithNewMemoryQueueConfig

func WithNewMemoryQueueConfig(newQueue func(name string) memory.Config) Option

WithNewMemoryQueueConfig sets the new memory queue configuration

type Publisher

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

func NewPublisher

func NewPublisher[T any](queue messaging.Queue[Event[T]]) *Publisher[T]

func PublisherOf

func PublisherOf[T any](s *Service) (*Publisher[T], error)

PublisherOf returns a publisher for the provided type

func (*Publisher[T]) Consume

func (p *Publisher[T]) Consume(ctx context.Context) (*Event[T], error)

func (*Publisher[T]) Publish

func (p *Publisher[T]) Publish(ctx context.Context, event *Event[T]) error

type Service

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

func New

func New(queueVendor messaging.Vendor, opts ...Option) (*Service, error)

func (*Service) SetListener

func (s *Service) SetListener(handler func(*Event[any]))

Jump to

Keyboard shortcuts

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