2026-04-25 13:21:39 +08:00

29 lines
860 B
Go
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package room
import "context"
// EventHandler 是 room outbox 事件进入 activity-service 后的处理边界。
// 消费来源可以是 MySQL outbox、Redis Stream 或 MQ但处理侧必须保持幂等。
type EventHandler interface {
HandleRoomEvent(ctx context.Context, eventID string, eventType string, payload []byte) error
}
// Consumer 描述活动服务的房间事件消费骨架。
type Consumer struct {
handler EventHandler
}
// NewConsumer 创建房间事件消费者。
func NewConsumer(handler EventHandler) *Consumer {
return &Consumer{handler: handler}
}
// Handle 把外部事件交给幂等 handler。
func (c *Consumer) Handle(ctx context.Context, eventID string, eventType string, payload []byte) error {
if c == nil || c.handler == nil {
return nil
}
return c.handler.HandleRoomEvent(ctx, eventID, eventType, payload)
}