feat(outbox): relay committed outbox events to Kafka

This commit is contained in:
shira committed 2026-10-06 03:01:53 +03:00
1 parent 78f1651f6b
commit 6c3b34f73e
42 files changed
+3731 -45

No files matched your search

+41
View File
@@ -41,6 +41,24 @@ type Config struct {
SeaweedFSRegion string
SeaweedFSTimeout time.Duration
KafkaBrokers []string
// KafkaEventsTopic receives every published domain event.
KafkaEventsTopic string
KafkaEventsTopicPartitions int32
// KafkaEventsTopicReplicationFactor is -1 for the broker default.
KafkaEventsTopicReplicationFactor int16
// KafkaEventsTopicMinInsyncReplicas is 0 for the broker default.
KafkaEventsTopicMinInsyncReplicas int16
// KafkaProvisionTopics lets the relay create a missing events topic.
KafkaProvisionTopics bool
// RelayEnabled runs the outbox relay next to the HTTP servers.
RelayEnabled bool
RelayBatchSize int
RelayPollInterval time.Duration
RelayProduceTimeout time.Duration
// RelayStatementTimeout bounds each SQL statement of a relay pass.
RelayStatementTimeout time.Duration
RelayBackoffInitial time.Duration
RelayBackoffMax time.Duration
// EmailProvider selects the only active mail transport. Settings of the
// other transports are not loaded.
EmailProvider EmailProvider
@@ -94,6 +112,12 @@ func LoadFromEnv(lookup LookupEnv) (Config, error) {
if err := config.loadRedis(lookup); err != nil {
return Config{}, err
}
if err := config.loadKafkaTopics(lookup); err != nil {
return Config{}, err
}
if err := config.loadRelay(lookup); err != nil {
return Config{}, err
}
if err := config.loadMail(lookup); err != nil {
return Config{}, err
}
@@ -138,6 +162,9 @@ func (config Config) Validate() error {
if err := config.ValidateKafka(); err != nil {
return err
}
if err := config.ValidateRelay(); err != nil {
return err
}
if err := config.ValidateMail(); err != nil {
return err
}
@@ -195,6 +222,20 @@ func boolOrDefault(lookup LookupEnv, key string, fallback bool) (bool, error) {
}
}
// intOrDefault parses a decimal integer, ignoring surrounding spaces. An empty
// value is an error rather than the default.
func intOrDefault(lookup LookupEnv, key string, fallback int) (int, error) {
value, ok := lookup(key)
if !ok {
return fallback, nil
}
number, err := strconv.Atoi(strings.TrimSpace(value))
if err != nil {
return 0, fmt.Errorf("config.intOrDefault - %s must be an integer", key)
}
return number, nil
}
func durationOrDefault(lookup LookupEnv, key string, fallback time.Duration) (time.Duration, error) {
value, ok := lookup(key)
if !ok {