bus

package
v0.3.2 Latest Latest
Warning

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

Go to latest
Published: Jul 29, 2025 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type EventBus

type EventBus interface {
	// Publish 发布事件
	Publish(ctx context.Context, event domainEvent.DomainEvent) error
	// Subscribe 订阅事件
	Subscribe(handler EventHandler)
	// Unsubscribe 取消订阅事件
	Unsubscribe(handler EventHandler)
}

EventBus 事件总线接口

type EventHandler

type EventHandler interface {
	// Handle 事件处理器
	Handle(ctx context.Context, event domainEvent.DomainEvent) error
	// CanHandle 判断是否可以处理该事件
	CanHandle(eventType string) bool
}

EventHandler 事件处理器接口

type InMemoryEventBus

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

InMemoryEventBus 基于内存的事件总线

func NewInMemoryEventBus

func NewInMemoryEventBus() *InMemoryEventBus

func (*InMemoryEventBus) Publish

func (bus *InMemoryEventBus) Publish(ctx context.Context, event domainEvent.DomainEvent) error

func (*InMemoryEventBus) Subscribe

func (bus *InMemoryEventBus) Subscribe(handler EventHandler)

func (*InMemoryEventBus) Unsubscribe

func (bus *InMemoryEventBus) Unsubscribe(handler EventHandler)

Jump to

Keyboard shortcuts

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