eventcatalog

package
v0.6.1 Latest Latest
Warning

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

Go to latest
Published: Apr 29, 2026 License: Apache-2.0 Imports: 3 Imported by: 0

Documentation

Overview

Package eventcatalog 提供通用事件契约目录。

本包负责从 YAML 加载事件目录,并提供 topic、handler 和 delivery class 的查询视图。 它只表达事件运行时路由契约,不包含项目级事件名常量、消息中间件实现或业务 handler。

支持的 delivery class 包括 best_effort 和 durable_outbox。项目层可以基于 DeliveryClassResolver 判断事件是否需要 outbox 等可靠投递机制。

Index

Constants

This section is empty.

Variables

View Source
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 NewCatalog

func NewCatalog(cfg *Config) *Catalog

NewCatalog 根据已校验配置构建查询目录。

func (*Catalog) AllTopicNames

func (c *Catalog) AllTopicNames() []string

AllTopicNames 返回所有包含事件的物理 topic 名称。

func (*Catalog) Config

func (c *Catalog) Config() *Config

Config 返回目录配置。

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

func (c *Catalog) GetEventsForTopic(topicName string) []string

GetEventsForTopic 返回绑定到指定物理 topic 名称的事件类型。

func (*Catalog) GetTopicConfig

func (c *Catalog) GetTopicConfig(topicKey string) (TopicConfig, bool)

GetTopicConfig 返回逻辑 topic 配置。

func (*Catalog) GetTopicForEvent

func (c *Catalog) GetTopicForEvent(eventType string) (string, bool)

GetTopicForEvent 返回事件类型对应的物理 topic 名称。

func (*Catalog) IsDurableOutbox

func (c *Catalog) IsDurableOutbox(eventType string) bool

IsDurableOutbox 判断事件是否必须经过 outbox 暂存。

func (*Catalog) IsEventRegistered

func (c *Catalog) IsEventRegistered(eventType string) bool

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 Load

func Load(path string) (*Config, error)

Load 从磁盘读取并校验事件目录。

func LoadWithOptions added in v0.6.1

func LoadWithOptions(path string, opts ValidateOptions) (*Config, error)

LoadWithOptions 从磁盘读取并使用指定策略校验事件目录。

func Parse

func Parse(data []byte) (*Config, error)

Parse 解码并校验事件目录。

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

func (c *Config) GetEventsByTopic(topicKey string) []string

GetEventsByTopic 返回绑定到指定逻辑 topic key 的事件类型。

func (*Config) GetHandlerName

func (c *Config) GetHandlerName(eventType string) (string, bool)

GetHandlerName 返回事件类型配置的 handler 名称。

func (*Config) GetTopicKeys

func (c *Config) GetTopicKeys() []string

GetTopicKeys 返回所有逻辑 topic key。

func (*Config) GetTopicName

func (c *Config) GetTopicName(eventType string) (string, bool)

GetTopicName 返回事件类型对应的物理 topic 名称。

func (*Config) ListEventTypes

func (c *Config) ListEventTypes() []string

ListEventTypes 返回目录中声明的所有事件类型。

func (*Config) Validate

func (c *Config) Validate() error

Validate 校验 topic、handler 和 delivery 引用。

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

func (DeliveryClass) Valid

func (c DeliveryClass) Valid() bool

Valid 判断投递等级是否属于当前支持的契约。

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

type TopicConfig struct {
	Name        string `yaml:"name"`
	Description string `yaml:"description"`
}

TopicConfig 描述一个逻辑事件 topic。

type TopicResolver

type TopicResolver interface {
	GetTopicForEvent(eventType string) (string, bool)
}

TopicResolver 将事件类型解析为物理 topic 名称。

type TopicSubscription

type TopicSubscription struct {
	TopicName  string
	TopicKey   string
	EventTypes []string
}

TopicSubscription 描述一个由目录推导出的 topic 订阅。

type ValidateOptions added in v0.6.1

type ValidateOptions struct {
	RequireHandler         bool
	RequireTopicReferenced bool
}

ValidateOptions controls optional catalog policies. The zero value keeps only structural validation, while Validate uses StrictValidateOptions for backward compatible service startup checks.

Jump to

Keyboard shortcuts

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