event

package
v0.0.0-...-c1a148e Latest Latest
Warning

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

Go to latest
Published: Jun 12, 2024 License: BSD-3-Clause Imports: 11 Imported by: 3

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Channel = "nodehub:events"

Channel 通道名称

Functions

func Register

func Register(eventType string, ev any)

Register 注册事件

每种事件在注册时需要指定一个类型名,类型名只需要保证唯一即可

Types

type Bus

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

Bus 事件总线

func NewBus

func NewBus(queue Queue) *Bus

NewBus 构造函数

func NewNatsBus

func NewNatsBus(conn *nats.Conn) *Bus

NewNatsBus 使用nats构造事件总线

func NewRedisBus

func NewRedisBus(client *redis.Client) *Bus

NewRedisBus 构造函数

func (*Bus) Close

func (bus *Bus) Close()

Close 关闭事件总线连接

func (*Bus) Publish

func (bus *Bus) Publish(ctx context.Context, event any) error

Publish 发布事件

Example:

bus.Publish(ctx, event.UserConnected{...})

func (*Bus) Subscribe

func (bus *Bus) Subscribe(ctx context.Context, handler any)

Subscribe 订阅事件

Example:

 bus.Subscribe(ctx, func(ev event.UserConnected, t time.Time) {
		// ...
 })

 bus.Subscribe(ctx, func(ev event.UserDisconnected, t time.Time) {
		// ...
 })

type NodeAssign

type NodeAssign struct {
	ServiceCode int32     `json:"serviceCode"`
	UserID      []string  `json:"userID"`
	NodeID      ulid.ULID `json:"nodeID"`
}

NodeAssign 给用户分配有状态节点

type NodeUnassign

type NodeUnassign struct {
	ServiceCode int32     `json:"serviceCode"`
	UserID      []string  `json:"userID"`
	NodeID      ulid.ULID `json:"nodeID"`
}

NodeUnassign 取消用户分配的有状态节点

type Queue

type Queue = mq.Queue

Queue 消息队列

type UserConnected

type UserConnected struct {
	GatewayID  string `json:"gatewayID"`
	UserID     string `json:"userID"`
	RemoteAddr string `json:"remoteAddr"`
}

UserConnected 用户连接事件

type UserDisconnected

type UserDisconnected struct {
	GatewayID  string `json:"gatewayID"`
	UserID     string `json:"userID"`
	RemoteAddr string `json:"remoteAddr"`
}

UserDisconnected 用户断开连接事件

Jump to

Keyboard shortcuts

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