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]) OccurredAt ¶
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) 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 泛型事件接口
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) PublishEvent ¶
func (b *MQEventBus) PublishEvent(ctx context.Context, event any) error
PublishEvent 发布事件
func (*MQEventBus) SubscribeHandler ¶
func (b *MQEventBus) SubscribeHandler(handler any) error
SubscribeHandler 订阅事件处理器
Click to show internal directories.
Click to hide internal directories.