feat(events): add idempotent Kafka event consumer runtime

This commit is contained in:
shira committed 2026-10-06 03:59:57 +03:00
1 parent 565ef8d4f5
commit 3adb0ef9e4
47 files changed
+5018 -105

No files matched your search

+28
View File
@@ -59,6 +59,24 @@ type Config struct {
RelayStatementTimeout time.Duration
RelayBackoffInitial time.Duration
RelayBackoffMax time.Duration
// ConsumerEnabled runs the registered event consumers next to the HTTP
// servers.
ConsumerEnabled bool
// ConsumerGroupPrefix and a consumer name form the consumer group ID.
ConsumerGroupPrefix string
ConsumerMaxAttempts int
ConsumerBackoffInitial time.Duration
ConsumerBackoffMax time.Duration
// ConsumerHandlerTimeout bounds one consumer transaction.
ConsumerHandlerTimeout time.Duration
ConsumerMaxPollRecords int
ConsumerCommitTimeout time.Duration
// ConsumerShutdownGrace bounds the record in progress after shutdown
// begins.
ConsumerShutdownGrace time.Duration
// ConsumerRebalanceTimeout is the Kafka rebalance timeout of every
// consumer group member.
ConsumerRebalanceTimeout time.Duration
// EmailProvider selects the only active mail transport. Settings of the
// other transports are not loaded.
EmailProvider EmailProvider
@@ -118,6 +136,9 @@ func LoadFromEnv(lookup LookupEnv) (Config, error) {
if err := config.loadRelay(lookup); err != nil {
return Config{}, err
}
if err := config.loadConsumer(lookup); err != nil {
return Config{}, err
}
if err := config.loadMail(lookup); err != nil {
return Config{}, err
}
@@ -183,6 +204,11 @@ func (config Config) Validate() error {
if config.ShutdownTimeout <= 0 {
return errors.New("Config.Validate - SHUTDOWN_TIMEOUT must be positive")
}
// The consumer shutdown grace is checked against SHUTDOWN_TIMEOUT, so it
// follows that check.
if err := config.ValidateConsumer(); err != nil {
return err
}
switch config.LogLevel {
case "debug", "info", "warn", "error":
default:
@@ -207,6 +233,8 @@ func DatabaseURLFromEnv(lookup LookupEnv) string {
// boolOrDefault accepts only "true" or "false", ignoring case and surrounding
// spaces. strconv.ParseBool would also accept 1, t, and similar shorthands,
// which are easy to mistype in deployment files.
//
//nolint:unparam // Every setting names its own default; that all current defaults are true is a coincidence.
func boolOrDefault(lookup LookupEnv, key string, fallback bool) (bool, error) {
value, ok := lookup(key)
if !ok {