Documentation ¶
Index ¶
- Constants
- type Bus
- type BusController
- type BusPublisher
- type BusSubscriber
- type Client
- func (client *Client) EventBus() Bus
- func (client *Client) Start() error
- func (client *Client) Stop()
- func (client *Client) Subscribe(topic string, fn interface{}, serverAddr, serverPath string) error
- func (client *Client) SubscribeOnce(topic string, fn interface{}, serverAddr, serverPath string) error
- type ClientArg
- type ClientService
- type EventBus
- func (bus *EventBus) HasCallback(topic string) bool
- func (bus *EventBus) Publish(topic string, args ...interface{})
- func (bus *EventBus) Subscribe(topic string, fn interface{}) error
- func (bus *EventBus) SubscribeAsync(topic string, fn interface{}, transactional bool) error
- func (bus *EventBus) SubscribeOnce(topic string, fn interface{}) error
- func (bus *EventBus) SubscribeOnceAsync(topic string, fn interface{}) error
- func (bus *EventBus) Unsubscribe(topic string, handler interface{}) error
- func (bus *EventBus) WaitAsync()
- type EventRegistry
- type NetworkBus
- type NetworkBusService
- type Server
- type ServerService
- type SubscribeArg
- type SubscribeType
Constants ¶
const (
// PublishService - 客户端服务方法
PublishService = "ClientService.PushEvent"
)
const RegisterService = "ServerService.Register"
常量,定义服务器订阅服务的方法名
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type BusController ¶
BusController 定义了总线控制行为(检查处理程序的存在,同步)
type BusPublisher ¶
type BusPublisher interface {
Publish(topic string, args ...interface{}) // 发布主题
}
BusPublisher 定义了与发布相关的总线行为
type BusSubscriber ¶
type BusSubscriber interface { Subscribe(topic string, fn interface{}) error // 订阅主题 SubscribeAsync(topic string, fn interface{}, transactional bool) error // 异步订阅主题 SubscribeOnce(topic string, fn interface{}) error // 订阅一次主题 SubscribeOnceAsync(topic string, fn interface{}) error // 异步订阅一次主题 Unsubscribe(topic string, handler interface{}) error // 取消订阅 }
BusSubscriber 定义了与订阅相关的总线行为
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client - 能够订阅远程事件总线的对象
type ClientArg ¶
type ClientArg struct { Args []interface{} // 参数 Topic string // 主题 }
ClientArg - 包含客户端要在本地发布的事件的对象
type ClientService ¶
type ClientService struct {
// contains filtered or unexported fields
}
ClientService - 侦听远程事件总线中发布的事件的服务对象
type EventBus ¶
type EventBus struct {
// contains filtered or unexported fields
}
EventBus 提供了一个实现了 Bus 接口的基本事件总线
func (*EventBus) HasCallback ¶
HasCallback 检查指定主题是否有回调处理程序
func (*EventBus) SubscribeAsync ¶
SubscribeAsync 异步订阅指定主题的事件
func (*EventBus) SubscribeOnce ¶
SubscribeOnce 订阅一次指定主题的事件
func (*EventBus) SubscribeOnceAsync ¶
SubscribeOnceAsync 异步订阅一次指定主题的事件
func (*EventBus) Unsubscribe ¶
Unsubscribe 取消订阅指定主题的事件
type EventRegistry ¶
type EventRegistry struct {
// contains filtered or unexported fields
}
EventRegistry 用于注册和获取事件总线实例
func (*EventRegistry) GetEventBus ¶
func (er *EventRegistry) GetEventBus(eventType string) Bus
GetEventBus 获取一个事件总线,如果不存在则返回nil
func (*EventRegistry) RegisterEvent ¶
func (er *EventRegistry) RegisterEvent(eventType string, bus Bus)
RegisterEvent 注册一个新的事件总线
type NetworkBus ¶
type NetworkBus struct { Client *Client // 内嵌客户端 Server *Server // 内嵌服务器 // contains filtered or unexported fields }
NetworkBus 定义了网络总线的结构,包含客户端、服务器和共享的事件总线
func NewNetworkBus ¶
func NewNetworkBus(address, path string) *NetworkBus
NewNetworkBus 创建并初始化一个新的网络总线实例
type NetworkBusService ¶
type NetworkBusService struct {
// contains filtered or unexported fields
}
NetworkBusService 定义了网络总线服务的状态和同步机制
type Server ¶
type Server struct {
// contains filtered or unexported fields
}
Server 定义了能够被远程处理器订阅的服务端结构
func (*Server) HasClientSubscribed ¶
func (server *Server) HasClientSubscribed(arg *SubscribeArg) bool
HasClientSubscribed 检查客户端是否已经订阅了指定的主题
type ServerService ¶
type ServerService struct {
// contains filtered or unexported fields
}
ServerService 定义了服务器服务结构,处理客户端的远程订阅
func (*ServerService) Register ¶
func (service *ServerService) Register(arg *SubscribeArg, success *bool) error
Register 允许客户端订阅指定的主题
type SubscribeArg ¶
type SubscribeArg struct { ClientAddr string // 客户端地址 ClientPath string // 客户端路径 ServiceMethod string // 服务方法名 SubscribeType SubscribeType // 订阅类型 Topic string // 主题名称 }
SubscribeArg 定义了远程处理器的订阅参数结构
type SubscribeType ¶
type SubscribeType int
SubscribeType 定义了客户端订阅的方式
const ( // Subscribe - 普通订阅,即接收所有事件 Subscribe SubscribeType = iota // SubscribeOnce - 订阅一次,即事件触发后取消订阅 SubscribeOnce )