Documentation
¶
Index ¶
- type Event
- type EventBus
- type InMemoryEventBus
- type RedisStreamsClient
- type RedisStreamsClientAdapter
- func (a *RedisStreamsClientAdapter) XAck(ctx context.Context, stream, group string, ids ...string) (int64, error)
- func (a *RedisStreamsClientAdapter) XAdd(ctx context.Context, args *redis.XAddArgs) (string, error)
- func (a *RedisStreamsClientAdapter) XClaim(ctx context.Context, args *redis.XClaimArgs) ([]redis.XMessage, error)
- func (a *RedisStreamsClientAdapter) XGroupCreateMkStream(ctx context.Context, stream, group, start string) error
- func (a *RedisStreamsClientAdapter) XInfoGroups(ctx context.Context, stream string) ([]redis.XInfoGroup, error)
- func (a *RedisStreamsClientAdapter) XLen(ctx context.Context, stream string) (int64, error)
- func (a *RedisStreamsClientAdapter) XPending(ctx context.Context, stream, group string) (*redis.XPending, error)
- func (a *RedisStreamsClientAdapter) XPendingExt(ctx context.Context, args *redis.XPendingExtArgs) ([]redis.XPendingExt, error)
- func (a *RedisStreamsClientAdapter) XReadGroup(ctx context.Context, args *redis.XReadGroupArgs) ([]redis.XStream, error)
- type RedisStreamsConfig
- type RedisStreamsEventBus
- func (b *RedisStreamsEventBus) Acknowledge(ctx context.Context, messageID string) error
- func (b *RedisStreamsEventBus) Client() RedisStreamsClient
- func (b *RedisStreamsEventBus) EnsureConsumerGroup(ctx context.Context) error
- func (b *RedisStreamsEventBus) PendingCount(ctx context.Context) (int64, error)
- func (b *RedisStreamsEventBus) Publish(ctx context.Context, evt Event)
- func (b *RedisStreamsEventBus) Stats() (published, dropped int)
- func (b *RedisStreamsEventBus) Stop()
- func (b *RedisStreamsEventBus) StreamLength(ctx context.Context) (int64, error)
- func (b *RedisStreamsEventBus) Subscribe() <-chan Event
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 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 RedisStreamsClient ¶
type RedisStreamsClient interface {
// XAdd adds an entry to a stream
XAdd(ctx context.Context, args *redis.XAddArgs) (string, error)
// XReadGroup reads entries from a stream using a consumer group
XReadGroup(ctx context.Context, args *redis.XReadGroupArgs) ([]redis.XStream, error)
// XAck acknowledges processed messages
XAck(ctx context.Context, stream, group string, ids ...string) (int64, error)
// XGroupCreateMkStream creates a consumer group (and the stream if needed)
XGroupCreateMkStream(ctx context.Context, stream, group, start string) error
// XPending returns pending entries for a consumer group
XPending(ctx context.Context, stream, group string) (*redis.XPending, error)
// XPendingExt returns detailed pending entries
XPendingExt(ctx context.Context, args *redis.XPendingExtArgs) ([]redis.XPendingExt, error)
// XClaim claims pending messages for a consumer
XClaim(ctx context.Context, args *redis.XClaimArgs) ([]redis.XMessage, error)
// XLen returns the length of a stream
XLen(ctx context.Context, stream string) (int64, error)
// XInfoGroups returns consumer group info for a stream
XInfoGroups(ctx context.Context, stream string) ([]redis.XInfoGroup, error)
}
RedisStreamsClient interface for Redis Streams operations. This abstraction allows for easy mocking in tests.
type RedisStreamsClientAdapter ¶
RedisStreamsClientAdapter adapts go-redis/v9 Client to the RedisStreamsClient interface.
func (*RedisStreamsClientAdapter) XAck ¶
func (a *RedisStreamsClientAdapter) XAck(ctx context.Context, stream, group string, ids ...string) (int64, error)
XAck acknowledges processed messages
func (*RedisStreamsClientAdapter) XClaim ¶
func (a *RedisStreamsClientAdapter) XClaim(ctx context.Context, args *redis.XClaimArgs) ([]redis.XMessage, error)
XClaim claims pending messages for a consumer
func (*RedisStreamsClientAdapter) XGroupCreateMkStream ¶
func (a *RedisStreamsClientAdapter) XGroupCreateMkStream(ctx context.Context, stream, group, start string) error
XGroupCreateMkStream creates a consumer group (and the stream if needed)
func (*RedisStreamsClientAdapter) XInfoGroups ¶
func (a *RedisStreamsClientAdapter) XInfoGroups(ctx context.Context, stream string) ([]redis.XInfoGroup, error)
XInfoGroups returns consumer group info for a stream
func (*RedisStreamsClientAdapter) XPending ¶
func (a *RedisStreamsClientAdapter) XPending(ctx context.Context, stream, group string) (*redis.XPending, error)
XPending returns pending entries for a consumer group
func (*RedisStreamsClientAdapter) XPendingExt ¶
func (a *RedisStreamsClientAdapter) XPendingExt(ctx context.Context, args *redis.XPendingExtArgs) ([]redis.XPendingExt, error)
XPendingExt returns detailed pending entries
func (*RedisStreamsClientAdapter) XReadGroup ¶
func (a *RedisStreamsClientAdapter) XReadGroup(ctx context.Context, args *redis.XReadGroupArgs) ([]redis.XStream, error)
XReadGroup reads entries from a stream using a consumer group
type RedisStreamsConfig ¶
type RedisStreamsConfig struct {
StreamKey string // Redis stream key name
ConsumerGroup string // Consumer group name
ConsumerName string // Unique consumer name within the group
MaxLen int64 // Max stream length (0 = unlimited, uses MAXLEN ~ approximation)
BlockTimeout time.Duration // Block timeout for XREADGROUP (0 = non-blocking)
ClaimMinIdleTime time.Duration // Minimum idle time before claiming pending messages
BatchSize int64 // Number of messages to read at once
}
RedisStreamsConfig holds configuration for Redis Streams event bus.
func DefaultRedisStreamsConfig ¶
func DefaultRedisStreamsConfig() RedisStreamsConfig
DefaultRedisStreamsConfig returns default configuration.
type RedisStreamsEventBus ¶
type RedisStreamsEventBus struct {
// contains filtered or unexported fields
}
RedisStreamsEventBus implements EventBus using Redis Streams. It provides durable, distributed event delivery with consumer groups, acknowledgment, and at-least-once delivery semantics.
func NewRedisStreamsEventBus ¶
func NewRedisStreamsEventBus(client RedisStreamsClient, config RedisStreamsConfig) *RedisStreamsEventBus
NewRedisStreamsEventBus creates a new Redis Streams event bus.
func (*RedisStreamsEventBus) Acknowledge ¶
func (b *RedisStreamsEventBus) Acknowledge(ctx context.Context, messageID string) error
Acknowledge manually acknowledges a message by ID. This is useful when external code handles message processing and acknowledgment.
func (*RedisStreamsEventBus) Client ¶
func (b *RedisStreamsEventBus) Client() RedisStreamsClient
Client returns the underlying RedisStreamsClient.
func (*RedisStreamsEventBus) EnsureConsumerGroup ¶
func (b *RedisStreamsEventBus) EnsureConsumerGroup(ctx context.Context) error
EnsureConsumerGroup creates the consumer group if it doesn't exist. This should be called before starting to consume messages.
func (*RedisStreamsEventBus) PendingCount ¶
func (b *RedisStreamsEventBus) PendingCount(ctx context.Context) (int64, error)
PendingCount returns the number of pending messages in the consumer group.
func (*RedisStreamsEventBus) Publish ¶
func (b *RedisStreamsEventBus) Publish(ctx context.Context, evt Event)
Publish adds an event to the Redis stream using XADD.
func (*RedisStreamsEventBus) Stats ¶
func (b *RedisStreamsEventBus) Stats() (published, dropped int)
Stats returns the number of published and dropped events.
func (*RedisStreamsEventBus) Stop ¶
func (b *RedisStreamsEventBus) Stop()
Stop gracefully stops the event bus and closes all subscriber channels.
func (*RedisStreamsEventBus) StreamLength ¶
func (b *RedisStreamsEventBus) StreamLength(ctx context.Context) (int64, error)
StreamLength returns the current length of the stream.
func (*RedisStreamsEventBus) Subscribe ¶
func (b *RedisStreamsEventBus) Subscribe() <-chan Event
Subscribe returns a channel that receives events from the stream. This starts a background goroutine that reads from the stream using consumer groups.