event

package
v0.5.2 Latest Latest
Warning

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

Go to latest
Published: Nov 1, 2025 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BaseDomainEvent

type BaseDomainEvent[T any] struct {
	BaseEvent[T]
	AggID   string `json:"aggregate_id"`
	AggName string `json:"aggregate_name"`
}

BaseDomainEvent 基础领域事件实现

func (BaseDomainEvent[T]) AggregateID

func (e BaseDomainEvent[T]) AggregateID() string

func (BaseDomainEvent[T]) AggregateName

func (e BaseDomainEvent[T]) AggregateName() string

type BaseEvent

type BaseEvent[T any] struct {
	Type      string    `json:"type"`
	Timestamp time.Time `json:"timestamp"`
	Data      T         `json:"data"`
}

BaseEvent 基础事件实现

func (BaseEvent[T]) EventType

func (e BaseEvent[T]) EventType() string

func (BaseEvent[T]) OccurredAt

func (e BaseEvent[T]) OccurredAt() time.Time

func (BaseEvent[T]) Payload

func (e BaseEvent[T]) Payload() T

type Bus

type Bus interface {
	// PublishEvent 发布事件
	PublishEvent(ctx context.Context, event any) error
	// SubscribeHandler 订阅事件处理器
	SubscribeHandler(handler any) error
}

Bus 事件总线接口

type ConsumerService

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

ConsumerService 事件消费者服务

func NewEventConsumerService

func NewEventConsumerService(consumer contract.Consumer, logger *zap.Logger) *ConsumerService

NewEventConsumerService 创建事件消费者服务

func (*ConsumerService) PublishEvent

func (s *ConsumerService) PublishEvent(ctx context.Context, event any) error

PublishEvent 发布事件

func (*ConsumerService) Start

func (s *ConsumerService) Start(ctx context.Context) error

Start 启动事件消费服务

func (*ConsumerService) Stop

func (s *ConsumerService) Stop() error

Stop 停止事件消费服务

func (*ConsumerService) SubscribeHandler

func (s *ConsumerService) SubscribeHandler(handler any) error

SubscribeHandler 订阅事件处理器

type DomainEvent

type DomainEvent[T any] interface {
	Event[T]
	// AggregateID 返回聚合根ID
	AggregateID() string
	// AggregateName 返回聚合根名称
	AggregateName() string
}

DomainEvent 领域事件接口

func NewDomainEvent

func NewDomainEvent[T any](eventType string, aggregateID string, aggregateName string, data T) DomainEvent[T]

NewDomainEvent 创建领域事件

type DomainEventHandler

type DomainEventHandler[T any] struct{}

DomainEventHandler 领域事件基础处理器

func (*DomainEventHandler[T]) ParseDomainEvent

func (h *DomainEventHandler[T]) ParseDomainEvent(ctx context.Context, event any) (BaseDomainEvent[T], error)

ParseDomainEvent 解析领域事件

type Event

type Event[T any] interface {
	// EventType 返回事件类型
	EventType() string
	// OccurredAt 返回事件发生时间
	OccurredAt() time.Time
	// Payload 返回事件数据
	Payload() T
}

Event 泛型事件接口

func NewEvent

func NewEvent[T any](eventType string, data T) Event[T]

NewEvent 创建新事件

type Handler

type Handler interface {
	// Handle 事件处理
	Handle(ctx context.Context, event any) error
	// InterestedEventTypes 返回感兴趣的事件类型列表
	InterestedEventTypes() []string
}

Handler 事件处理器接口

type MQEventBus

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

MQEventBus 基于MQ的事件总线实现

func NewMQEventBus

func NewMQEventBus(producer contract.Producer) *MQEventBus

NewMQEventBus 创建基于MQ的事件总线

func (*MQEventBus) Publish

func (b *MQEventBus) Publish(ctx context.Context, eventType string, eventData []byte) error

Publish 发布事件

func (*MQEventBus) PublishEvent

func (b *MQEventBus) PublishEvent(ctx context.Context, event any) error

PublishEvent 发布事件

func (*MQEventBus) SubscribeHandler

func (b *MQEventBus) SubscribeHandler(handler any) error

SubscribeHandler 订阅事件处理器

Jump to

Keyboard shortcuts

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