command
Version:
v0.9.1
Opens a new window with list of versions in this module.
Published: Aug 21, 2026
License: Apache-2.0
Opens a new window with license information.
Imports: 2
Opens a new window with list of imports.
Imported by: 0
Opens a new window with list of known importers.
README
¶
eventbus —— 事件总线
演示进程内 pkg/messaging/eventbus 按 topic 分发事件,多模块独立订阅、互不影响。
运行
go run ./examples/eventbus
说明
Subscribe(topic, handler) 注册监听;同一 topic 可有多个订阅者(通知、审计、成就各收一份)。
Publish(topic, event) 同步 fan-out,返回通知的订阅者数量。
- 返回的
Unsubscribe 函数可退订;退订后不再收到该 topic 事件。
- 与
pkg/messaging/mq 的区别:eventbus 是进程内;跨进程异步通信用 mq。
Documentation
¶
eventbus 示例:进程内按主题分发的事件总线。
演示 pkg/eventbus:多模块订阅同一事件、topic 隔离、退订。
场景:玩家上线事件 → 通知模块 + 审计模块 + 成就模块各自订阅,发布方无需感知。
Source Files
¶
Click to show internal directories.
Click to hide internal directories.