Documentation
¶
Overview ¶
Package eventcatalog 提供通用事件契约目录。
本包负责从 YAML 加载事件目录,并提供 topic、handler 和 delivery class 的查询视图。 它只表达事件运行时路由契约,不包含项目级事件名常量、消息中间件实现或业务 handler。
支持的 delivery class 包括 best_effort 和 durable_outbox。项目层可以基于 DeliveryClassResolver 判断事件是否需要 outbox 等可靠投递机制。
Index ¶
- Variables
- type Catalog
- func (c *Catalog) AllTopicNames() []string
- func (c *Catalog) Config() *Config
- func (c *Catalog) GetDeliveryClass(eventType string) (DeliveryClass, bool)
- func (c *Catalog) GetEventConfig(eventType string) (EventConfig, bool)
- func (c *Catalog) GetEventsForTopic(topicName string) []string
- func (c *Catalog) GetTopicConfig(topicKey string) (TopicConfig, bool)
- func (c *Catalog) GetTopicForEvent(eventType string) (string, bool)
- func (c *Catalog) IsDurableOutbox(eventType string) bool
- func (c *Catalog) IsEventRegistered(eventType string) bool
- func (c *Catalog) TopicSubscriptions() []TopicSubscription
- type Config
- func (c *Config) GetDeliveryClass(eventType string) (DeliveryClass, bool)
- func (c *Config) GetEventsByTopic(topicKey string) []string
- func (c *Config) GetHandlerName(eventType string) (string, bool)
- func (c *Config) GetTopicKeys() []string
- func (c *Config) GetTopicName(eventType string) (string, bool)
- func (c *Config) ListEventTypes() []string
- func (c *Config) Validate() error
- func (c *Config) ValidateWithOptions(opts ValidateOptions) error
- type DeliveryClass
- type DeliveryClassResolver
- type EventConfig
- type TopicConfig
- type TopicResolver
- type TopicSubscription
- type ValidateOptions
Constants ¶
This section is empty.
Variables ¶
var StrictValidateOptions = ValidateOptions{ RequireHandler: true, RequireTopicReferenced: true, }
Functions ¶
This section is empty.
Types ¶
type Catalog ¶
type Catalog struct {
// contains filtered or unexported fields
}
Catalog 是事件契约的不可变查询视图。
func (*Catalog) AllTopicNames ¶
AllTopicNames 返回所有包含事件的物理 topic 名称。
func (*Catalog) GetDeliveryClass ¶
func (c *Catalog) GetDeliveryClass(eventType string) (DeliveryClass, bool)
GetDeliveryClass 返回事件类型配置的投递等级。
func (*Catalog) GetEventConfig ¶
func (c *Catalog) GetEventConfig(eventType string) (EventConfig, bool)
GetEventConfig 返回事件配置。
func (*Catalog) GetEventsForTopic ¶
GetEventsForTopic 返回绑定到指定物理 topic 名称的事件类型。
func (*Catalog) GetTopicConfig ¶
func (c *Catalog) GetTopicConfig(topicKey string) (TopicConfig, bool)
GetTopicConfig 返回逻辑 topic 配置。
func (*Catalog) GetTopicForEvent ¶
GetTopicForEvent 返回事件类型对应的物理 topic 名称。
func (*Catalog) IsDurableOutbox ¶
IsDurableOutbox 判断事件是否必须经过 outbox 暂存。
func (*Catalog) IsEventRegistered ¶
IsEventRegistered 判断事件类型是否已在目录中注册。
func (*Catalog) TopicSubscriptions ¶
func (c *Catalog) TopicSubscriptions() []TopicSubscription
TopicSubscriptions 返回所有至少包含一个事件的 topic 订阅。
type Config ¶
type Config struct {
Version string `yaml:"version"`
Topics map[string]TopicConfig `yaml:"topics"`
Events map[string]EventConfig `yaml:"events"`
}
Config 是从 YAML 加载的事件契约根配置。
func LoadWithOptions ¶ added in v0.6.1
func LoadWithOptions(path string, opts ValidateOptions) (*Config, error)
LoadWithOptions 从磁盘读取并使用指定策略校验事件目录。
func ParseWithOptions ¶ added in v0.6.1
func ParseWithOptions(data []byte, opts ValidateOptions) (*Config, error)
ParseWithOptions 解码并使用指定策略校验事件目录。
func (*Config) GetDeliveryClass ¶
func (c *Config) GetDeliveryClass(eventType string) (DeliveryClass, bool)
GetDeliveryClass 返回事件类型配置的投递等级。
func (*Config) GetEventsByTopic ¶
GetEventsByTopic 返回绑定到指定逻辑 topic key 的事件类型。
func (*Config) GetHandlerName ¶
GetHandlerName 返回事件类型配置的 handler 名称。
func (*Config) GetTopicKeys ¶
GetTopicKeys 返回所有逻辑 topic key。
func (*Config) GetTopicName ¶
GetTopicName 返回事件类型对应的物理 topic 名称。
func (*Config) ListEventTypes ¶
ListEventTypes 返回目录中声明的所有事件类型。
func (*Config) ValidateWithOptions ¶ added in v0.6.1
func (c *Config) ValidateWithOptions(opts ValidateOptions) error
ValidateWithOptions 校验 topic、delivery 引用,并按策略校验 handler 和 topic 使用情况。
type DeliveryClass ¶
type DeliveryClass string
DeliveryClass 描述一个事件类型的投递可靠性契约。
const ( DeliveryClassBestEffort DeliveryClass = "best_effort" DeliveryClassDurableOutbox DeliveryClass = "durable_outbox" )
func (DeliveryClass) String ¶
func (c DeliveryClass) String() string
type DeliveryClassResolver ¶
type DeliveryClassResolver interface {
GetDeliveryClass(eventType string) (DeliveryClass, bool)
}
DeliveryClassResolver 将事件类型解析为投递可靠性契约。
type EventConfig ¶
type EventConfig struct {
Topic string `yaml:"topic"`
Delivery DeliveryClass `yaml:"delivery"`
Aggregate string `yaml:"aggregate"`
Domain string `yaml:"domain"`
Description string `yaml:"description"`
Handler string `yaml:"handler"`
}
EventConfig 描述一个事件类型及其运行时路由契约。
type TopicConfig ¶
TopicConfig 描述一个逻辑事件 topic。
type TopicResolver ¶
TopicResolver 将事件类型解析为物理 topic 名称。
type TopicSubscription ¶
TopicSubscription 描述一个由目录推导出的 topic 订阅。
type ValidateOptions ¶ added in v0.6.1
ValidateOptions controls optional catalog policies. The zero value keeps only structural validation, while Validate uses StrictValidateOptions for backward compatible service startup checks.