pubsub

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Dec 15, 2025 License: MPL-2.0 Imports: 15 Imported by: 0

Documentation

Overview

Package pubsub provides cluster-wide publishing and subscribing of events

Index

Constants

This section is empty.

Variables

View Source
var ErrSubscriptionTerminated = errors.New("broker terminated the subscription")

ErrSubscriptionTerminated is for use by subscribers to indicate that their subscription has been terminated by the broker.

Functions

func WriteSSEEvent

func WriteSSEEvent(w io.Writer, data []byte, event string, base64encode bool)

WriteSSEEvent writes an server-side-event to w. The data is optionally base64 encoded before being written.

Types

type Broker

type Broker[T any] struct {
	logr.Logger
	// contains filtered or unexported fields
}

Broker allows clients to subscribe to OTF events.

func NewBroker

func NewBroker[T any](logger logr.Logger, listener databaseListener, table string) *Broker[T]

func (*Broker[T]) Subscribe

func (b *Broker[T]) Subscribe(ctx context.Context) (<-chan Event[T], func())

Subscribe subscribes the caller to a stream of events. The caller can close the subscription by either canceling the context or calling the returned unsubscribe function.

type Event

type Event[T any] struct {
	Type    EventType
	Payload T
	Time    time.Time
}

Event represents an event in the lifecycle of an otf resource

func (Event[T]) LogValue added in v0.3.23

func (e Event[T]) LogValue() slog.Value

type EventType

type EventType string

EventType identifies the type of event

const (
	CreatedEvent EventType = "created"
	UpdatedEvent EventType = "updated"
	DeletedEvent EventType = "deleted"
)

type SubscriptionService added in v0.2.0

type SubscriptionService[T any] interface {
	Subscribe(context.Context) (<-chan Event[T], func())
}

SubscriptionService is a service that provides subscriptions to events

Jump to

Keyboard shortcuts

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