eventbus

package
v0.0.0-...-48df7e4 Latest Latest
Warning

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

Go to latest
Published: Sep 12, 2025 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Event

type Event struct {
	LogID           int64 // Monotonic event log ID
	RequestID       string
	Method          string
	Path            string
	Status          int
	Duration        time.Duration
	ResponseHeaders http.Header
	ResponseBody    []byte
	RequestBody     []byte
}

Event represents an observability event emitted by the proxy.

type EventBus

type EventBus interface {
	Publish(ctx context.Context, evt Event)
	Subscribe() <-chan Event
	Stop()
}

EventBus is a simple interface for publishing events to subscribers.

type InMemoryEventBus

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

InMemoryEventBus is an EventBus implementation backed by a buffered channel and fan-out broadcasting to multiple subscribers. Events are dispatched asynchronously to avoid blocking the request path.

func NewInMemoryEventBus

func NewInMemoryEventBus(bufferSize int) *InMemoryEventBus

NewInMemoryEventBus creates a new in-memory event bus with the given buffer size.

func (*InMemoryEventBus) Publish

func (b *InMemoryEventBus) Publish(ctx context.Context, evt Event)

Publish sends an event to the bus without blocking if the buffer is full.

func (*InMemoryEventBus) Stats

func (b *InMemoryEventBus) Stats() (published, dropped int)

Stats returns the number of published and dropped events.

func (*InMemoryEventBus) Stop

func (b *InMemoryEventBus) Stop()

Stop gracefully stops the event bus and closes all subscriber channels.

func (*InMemoryEventBus) Subscribe

func (b *InMemoryEventBus) Subscribe() <-chan Event

Subscribe returns a channel that receives events published to the bus. Each subscriber receives all events.

type RedisClient

type RedisClient interface {
	LPush(ctx context.Context, key string, values ...interface{}) error
	LRANGE(ctx context.Context, key string, start, stop int64) ([]string, error)
	LLEN(ctx context.Context, key string) (int64, error)
	EXPIRE(ctx context.Context, key string, expiration time.Duration) error
	LTRIM(ctx context.Context, key string, start, stop int64) error
	Incr(ctx context.Context, key string) (int64, error)
	Get(ctx context.Context, key string) (string, error)
	Set(ctx context.Context, key, value string) error
}

Extend RedisClient interface for LRANGE, LLEN, EXPIRE, LTRIM, Incr, Get, Set

type RedisEventBus

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

RedisEventBus is a Redis-backed EventBus implementation. Events are encoded as JSON and pushed to a Redis list. This version is a persistent log: events are never removed by consumers.

func NewRedisEventBusLog

func NewRedisEventBusLog(client RedisClient, key string, ttl time.Duration, maxLen int64) *RedisEventBus

NewRedisEventBusLog creates a Redis event bus that acts as a persistent log (non-destructive, with TTL and optional max length)

func NewRedisEventBusPublisher

func NewRedisEventBusPublisher(client RedisClient, key string) *RedisEventBus

NewRedisEventBusPublisher creates a Redis event bus that only publishes events (no background consumer).

func (*RedisEventBus) Client

func (b *RedisEventBus) Client() RedisClient

Client returns the underlying RedisClient for this RedisEventBus

func (*RedisEventBus) EventCount

func (b *RedisEventBus) EventCount(ctx context.Context) (int64, error)

EventCount returns the current number of events in the log

func (*RedisEventBus) Publish

func (b *RedisEventBus) Publish(ctx context.Context, evt Event)

Publish pushes the event JSON to the Redis list.

func (*RedisEventBus) ReadEvents

func (b *RedisEventBus) ReadEvents(ctx context.Context, start, end int64) ([]Event, error)

ReadEvents returns events in [start, end] (inclusive, like LRANGE)

func (*RedisEventBus) Stop

func (b *RedisEventBus) Stop()

Stop is a no-op for the log-based RedisEventBus (required to satisfy EventBus interface)

func (*RedisEventBus) Subscribe

func (b *RedisEventBus) Subscribe() <-chan Event

Subscribe is not supported for the log-based RedisEventBus. It returns a closed channel.

type RedisGoClientAdapter

type RedisGoClientAdapter struct {
	Client *redis.Client
}

RedisGoClientAdapter adapts go-redis/v9 Client to the RedisClient interface.

func (*RedisGoClientAdapter) EXPIRE

func (a *RedisGoClientAdapter) EXPIRE(ctx context.Context, key string, expiration time.Duration) error

func (*RedisGoClientAdapter) Get

func (a *RedisGoClientAdapter) Get(ctx context.Context, key string) (string, error)

func (*RedisGoClientAdapter) Incr

func (a *RedisGoClientAdapter) Incr(ctx context.Context, key string) (int64, error)

func (*RedisGoClientAdapter) LLEN

func (a *RedisGoClientAdapter) LLEN(ctx context.Context, key string) (int64, error)

func (*RedisGoClientAdapter) LPush

func (a *RedisGoClientAdapter) LPush(ctx context.Context, key string, values ...interface{}) error

func (*RedisGoClientAdapter) LRANGE

func (a *RedisGoClientAdapter) LRANGE(ctx context.Context, key string, start, stop int64) ([]string, error)

Extend RedisGoClientAdapter to implement new methods

func (*RedisGoClientAdapter) LTRIM

func (a *RedisGoClientAdapter) LTRIM(ctx context.Context, key string, start, stop int64) error

func (*RedisGoClientAdapter) Set

func (a *RedisGoClientAdapter) Set(ctx context.Context, key, value string) error

Jump to

Keyboard shortcuts

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