event

package
v0.1.3 Latest Latest
Warning

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

Go to latest
Published: May 22, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

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

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

func NewBaseEvent(name string, payload interface{}) *BaseEvent

NewBaseEvent 创建基础事件。

func (*BaseEvent) Name

func (e *BaseEvent) Name() string

func (*BaseEvent) OccurredAt

func (e *BaseEvent) OccurredAt() time.Time

func (*BaseEvent) Payload

func (e *BaseEvent) Payload() interface{}

type LocalEventBus

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

LocalEventBus 本地内存事件总线。

中文说明: - 基于 goroutine 的本地事件总线实现; - 支持同步和异步发布; - 支持一个事件多个处理器(广播模式); - 适合单体应用内部事件通信,后续可演进为 MQ。

func NewLocalEventBus

func NewLocalEventBus() *LocalEventBus

NewLocalEventBus 创建本地事件总线。

func (*LocalEventBus) HasSubscribers

func (b *LocalEventBus) HasSubscribers(eventName string) bool

HasSubscribers 检查事件是否有订阅者。

func (*LocalEventBus) Publish

Publish 同步发布事件。

中文说明: - 阻塞直到所有处理器执行完毕; - 处理器按注册顺序依次执行; - 如果某个处理器失败,记录错误但继续执行其他处理器; - 返回第一个遇到的错误。

func (*LocalEventBus) PublishAsync

func (b *LocalEventBus) PublishAsync(ctx context.Context, event integrationcontract.Event) error

PublishAsync 异步发布事件。

中文说明: - 立即返回,事件在后台 goroutine 中处理; - 使用 goroutine.SafeGo 包装,确保 panic 不会导致程序崩溃; - 适合不需要等待处理完成的场景。

func (*LocalEventBus) Subscribe

func (b *LocalEventBus) Subscribe(eventName string, handler integrationcontract.EventHandler)

Subscribe 订阅事件。

中文说明: - 注册事件处理器; - 同一事件可以有多个处理器,按注册顺序执行; - 处理器执行失败不会影响其他处理器的执行。

func (*LocalEventBus) Unsubscribe

func (b *LocalEventBus) Unsubscribe(eventName string)

Unsubscribe 取消订阅事件。

中文说明: - 移除指定事件的所有处理器; - 用于清理或重新配置事件处理。

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

Boot initializes the event bus provider. No additional startup logic required.

Boot 初始化事件总线 provider。 无需额外启动逻辑。

func (*Provider) IsDefer

func (p *Provider) IsDefer() bool

IsDefer indicates event bus should not defer loading. Events may be needed early in application lifecycle.

IsDefer 表示事件总线不应延迟加载。 事件可能在应用生命周期早期就需要。

func (*Provider) Name

func (p *Provider) Name() string

Name returns provider name for identification.

Name 返回 provider 名称,用于标识。

func (*Provider) Provides

func (p *Provider) Provides() []string

Provides returns the capability keys this provider exposes. Exposes EventKey for event bus service.

Provides 返回 provider 暴露的能力键。 暴露 EventKey 用于事件总线服务。

func (*Provider) Register

func (p *Provider) Register(c runtimecontract.Container) error

Register binds the event bus factory to the container. Core logic: Create LocalEventBus, bind to container.

Register 将事件总线工厂绑定到容器。 核心逻辑:创建 LocalEventBus、绑定到容器。

Jump to

Keyboard shortcuts

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