eventbus

package
v0.0.32 Latest Latest
Warning

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

Go to latest
Published: Apr 2, 2024 License: MIT Imports: 8 Imported by: 3

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Close

func Close() error

Close 关闭事件总线

func PackData

func PackData(topic string, payload interface{}) ([]byte, error)

PackData 打包数据

func Publish

func Publish(ctx context.Context, topic string, message interface{}) error

Publish 发布事件

func SetEventbus

func SetEventbus(eventbus Eventbus)

SetEventbus 设置事件总线

func Subscribe

func Subscribe(ctx context.Context, topic string, handler EventHandler) error

Subscribe 订阅事件

func Unsubscribe

func Unsubscribe(ctx context.Context, topic string, handler EventHandler) error

Unsubscribe 取消订阅

Types

type Event

type Event struct {
	ID        string      // 事件ID
	Topic     string      // 事件主题
	Payload   value.Value // 事件载荷
	Timestamp time.Time   // 事件时间
}

func UnpackData

func UnpackData(v []byte) (*Event, error)

UnpackData 解析

type EventHandler

type EventHandler func(event *Event)

type Eventbus

type Eventbus interface {
	// Close 关闭事件总线
	Close() error
	// Publish 发布事件
	Publish(ctx context.Context, topic string, message interface{}) error
	// Subscribe 订阅事件
	Subscribe(ctx context.Context, topic string, handler EventHandler) error
	// Unsubscribe 取消订阅
	Unsubscribe(ctx context.Context, topic string, handler EventHandler) error
}

func GetEventbus

func GetEventbus() Eventbus

GetEventbus 获取事件总线

Directories

Path Synopsis
kafka module
nats module
redis module

Jump to

Keyboard shortcuts

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