eventbus

package
v0.0.15 Latest Latest
Warning

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

Go to latest
Published: Mar 29, 2024 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// PublishService - 客户端服务方法
	PublishService = "ClientService.PushEvent"
)
View Source
const RegisterService = "ServerService.Register"

常量,定义服务器订阅服务的方法名

Variables

This section is empty.

Functions

This section is empty.

Types

type Bus

type Bus interface {
	BusController
	BusSubscriber
	BusPublisher
}

Bus 整合全局(订阅,发布,控制)总线行为

func New

func New() Bus

New 创建一个新的 EventBus 实例

type BusController

type BusController interface {
	HasCallback(topic string) bool // 检查是否有回调
	WaitAsync()                    // 等待异步回调完成
}

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 - 能够订阅远程事件总线的对象

func NewClient

func NewClient(address, path string, eventBus Bus) *Client

NewClient - 使用地址、路径和事件总线创建一个新的客户端

func (*Client) EventBus

func (client *Client) EventBus() Bus

EventBus - 返回底层的事件总线

func (*Client) Start

func (client *Client) Start() error

Start - 启动客户端服务以侦听远程事件

func (*Client) Stop

func (client *Client) Stop()

Stop - 发出停止服务的信号

func (*Client) Subscribe

func (client *Client) Subscribe(topic string, fn interface{}, serverAddr, serverPath string) error

Subscribe - 在远程事件总线上订阅主题,并处理任何可能的错误

func (*Client) SubscribeOnce

func (client *Client) SubscribeOnce(topic string, fn interface{}, serverAddr, serverPath string) error

SubscribeOnce - 一次性订阅远程事件总线上的主题,并处理任何可能的错误

type ClientArg

type ClientArg struct {
	Args  []interface{} // 参数
	Topic string        // 主题
}

ClientArg - 包含客户端要在本地发布的事件的对象

type ClientService

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

ClientService - 侦听远程事件总线中发布的事件的服务对象

func (*ClientService) PushEvent

func (service *ClientService) PushEvent(arg *ClientArg, reply *bool) error

PushEvent - 侦听远程事件的导出服务

type EventBus

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

EventBus 提供了一个实现了 Bus 接口的基本事件总线

func (*EventBus) HasCallback

func (bus *EventBus) HasCallback(topic string) bool

HasCallback 检查指定主题是否有回调处理程序

func (*EventBus) Publish

func (bus *EventBus) Publish(topic string, args ...interface{})

Publish 发布事件到指定主题

func (*EventBus) Subscribe

func (bus *EventBus) Subscribe(topic string, fn interface{}) error

Subscribe 订阅指定主题的事件

func (*EventBus) SubscribeAsync

func (bus *EventBus) SubscribeAsync(topic string, fn interface{}, transactional bool) error

SubscribeAsync 异步订阅指定主题的事件

func (*EventBus) SubscribeOnce

func (bus *EventBus) SubscribeOnce(topic string, fn interface{}) error

SubscribeOnce 订阅一次指定主题的事件

func (*EventBus) SubscribeOnceAsync

func (bus *EventBus) SubscribeOnceAsync(topic string, fn interface{}) error

SubscribeOnceAsync 异步订阅一次指定主题的事件

func (*EventBus) Unsubscribe

func (bus *EventBus) Unsubscribe(topic string, handler interface{}) error

Unsubscribe 取消订阅指定主题的事件

func (*EventBus) WaitAsync

func (bus *EventBus) WaitAsync()

WaitAsync 等待所有异步处理程序执行完成

type EventRegistry

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

EventRegistry 用于注册和获取事件总线实例

func NewEventRegistry

func NewEventRegistry() *EventRegistry

NewEventRegistry 创建一个新的事件注册器

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 创建并初始化一个新的网络总线实例

func (*NetworkBus) EventBus

func (nb *NetworkBus) EventBus() Bus

EventBus 返回当前网络总线关联的事件总线实例

func (*NetworkBus) Start

func (nb *NetworkBus) Start() error

Start 启动网络总线,包括其关联的 RPC 服务

func (*NetworkBus) Stop

func (nb *NetworkBus) Stop()

Stop 停止网络总线服务

type NetworkBusService

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

NetworkBusService 定义了网络总线服务的状态和同步机制

type Server

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

Server 定义了能够被远程处理器订阅的服务端结构

func NewServer

func NewServer(address, path string, eventBus Bus) *Server

NewServer 创建并初始化一个新的Server实例

func (*Server) EventBus

func (server *Server) EventBus() Bus

EventBus 返回服务端关联的事件总线

func (*Server) HasClientSubscribed

func (server *Server) HasClientSubscribed(arg *SubscribeArg) bool

HasClientSubscribed 检查客户端是否已经订阅了指定的主题

func (*Server) Start

func (server *Server) Start() error

Start 启动服务器来监听远程客户端的订阅请求

func (*Server) Stop

func (server *Server) Stop()

Stop 停止服务并释放所有资源

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
)

Jump to

Keyboard shortcuts

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