eventbus

command
v0.9.2 Latest Latest
Warning

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

Go to latest
Published: Aug 28, 2026 License: Apache-2.0 Imports: 2 Imported by: 0

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

Overview

eventbus 示例:进程内按主题分发的事件总线。

演示 pkg/eventbus:多模块订阅同一事件、topic 隔离、退订。 场景:玩家上线事件 → 通知模块 + 审计模块 + 成就模块各自订阅,发布方无需感知。

Jump to

Keyboard shortcuts

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