Documentation
¶
Overview ¶
Package event provides EventBus options for retry and DLQ configurations.
Package event provides local in-memory event bus implementation for gorp framework. Suitable for single-application internal event communication. Supports synchronous and asynchronous publishing, multiple handlers per event.
事件包提供本地内存事件总线实现,用于 gorp 框架。 适用于单体应用内部事件通信。 支持同步和异步发布、单事件多处理器。
Package event provides event bus provider for gorp framework. Registers local in-memory event bus as default implementation.
事件包提供事件总线 provider,用于 gorp 框架。 注册本地内存事件总线作为默认实现。
Index ¶
- type BaseEvent
- type DLQHandler
- type EventBusOptions
- type LocalEventBus
- func (b *LocalEventBus) Close() error
- func (b *LocalEventBus) HasSubscribers(eventName string) bool
- func (b *LocalEventBus) Publish(ctx context.Context, event integrationcontract.Event) error
- func (b *LocalEventBus) PublishAsync(ctx context.Context, event integrationcontract.Event) error
- func (b *LocalEventBus) Subscribe(eventName string, handler integrationcontract.EventHandler)
- func (b *LocalEventBus) Unsubscribe(eventName string)
- type Option
- type Provider
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type BaseEvent ¶
type BaseEvent struct {
// contains filtered or unexported fields
}
BaseEvent 基础事件实现。
中文说明: - 提供事件的默认实现,可直接使用或作为嵌入; - 包含事件名称、载荷和时间戳。
func NewBaseEvent ¶
NewBaseEvent 创建基础事件。
func (*BaseEvent) OccurredAt ¶
type DLQHandler ¶ added in v0.2.0
type DLQHandler func(ctx context.Context, event integrationcontract.Event, err error)
DLQHandler is the callback function invoked when an event exhausts all retry attempts.
type EventBusOptions ¶ added in v0.2.0
type EventBusOptions struct {
MaxRetries int // Maximum retry attempts (default: 3)
InitialBackoff time.Duration // Initial retry delay (default: 50ms)
MaxBackoff time.Duration // Maximum retry delay (default: 1s)
EnableDLQ bool // Enable Dead-Letter Queue routing (default: true)
DLQHandler DLQHandler // Custom DLQ handler
AsyncWorkerCount int // Number of background workers for PublishAsync (default: 8)
AsyncQueueSize int // Buffer size for async event queue (default: 1024)
}
EventBusOptions configures the EventBus behavior including exponential retries and DLQ.
func DefaultEventBusOptions ¶ added in v0.2.0
func DefaultEventBusOptions() EventBusOptions
DefaultEventBusOptions returns sensible defaults for production.
type LocalEventBus ¶
type LocalEventBus struct {
// contains filtered or unexported fields
}
func NewLocalEventBus ¶
func NewLocalEventBus(opts ...Option) *LocalEventBus
NewLocalEventBus 创建具备重试、DLQ 与异步 Worker 协程池能力的本地事件总线。
func (*LocalEventBus) Close ¶ added in v0.2.0
func (b *LocalEventBus) Close() error
Close stops the background async workers and releases resources. Implements io.Closer for container lifecycle cleanup.
func (*LocalEventBus) HasSubscribers ¶
func (b *LocalEventBus) HasSubscribers(eventName string) bool
HasSubscribers 检查事件是否有订阅者。
func (*LocalEventBus) Publish ¶
func (b *LocalEventBus) Publish(ctx context.Context, event integrationcontract.Event) error
Publish 同步发布事件(带有指数退避重试与死信队列 DLQ 路由)。
func (*LocalEventBus) PublishAsync ¶
func (b *LocalEventBus) PublishAsync(ctx context.Context, event integrationcontract.Event) error
PublishAsync 异步发布事件(通过定长 Worker 协程池削峰处理)。
func (*LocalEventBus) Subscribe ¶
func (b *LocalEventBus) Subscribe(eventName string, handler integrationcontract.EventHandler)
Subscribe 订阅事件。
func (*LocalEventBus) Unsubscribe ¶
func (b *LocalEventBus) Unsubscribe(eventName string)
Unsubscribe 取消订阅事件。
中文说明: - 移除指定事件的所有处理器; - 用于清理或重新配置事件处理。
type Option ¶ added in v0.2.0
type Option func(*EventBusOptions)
Option configures EventBusOptions.
func WithAsyncWorkers ¶ added in v0.2.0
WithAsyncWorkers configures the worker pool and queue size for asynchronous event publishing.
func WithBackoff ¶ added in v0.2.0
WithBackoff configures exponential backoff delays.
func WithDLQHandler ¶ added in v0.2.0
func WithDLQHandler(handler DLQHandler) Option
WithDLQHandler configures the Dead Letter Queue handler callback.
func WithMaxRetries ¶ added in v0.2.0
WithMaxRetries configures max retry attempts.
type Provider ¶
type Provider struct{}
Provider registers the event bus service contract. Core logic: Bind LocalEventBus factory to container.
Provider 注册事件总线服务契约。 核心逻辑:将 LocalEventBus 工厂绑定到容器。
func NewProvider ¶
func NewProvider() *Provider
NewProvider creates a new event bus provider.
NewProvider 创建新的事件总线 provider。
func (*Provider) Boot ¶
func (p *Provider) Boot(runtimecontract.Container) error
Boot initializes the event bus provider. No additional startup logic required.
Boot 初始化事件总线 provider。 无需额外启动逻辑。
func (*Provider) IsDefer ¶
IsDefer indicates event bus should not defer loading. Events may be needed early in application lifecycle.
IsDefer 表示事件总线不应延迟加载。 事件可能在应用生命周期早期就需要。