-
Notifications
You must be signed in to change notification settings - Fork 70
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1369 from openmeterio/refactor/add-proper-dlq
feat: simplify dlq setup
- Loading branch information
Showing
14 changed files
with
453 additions
and
175 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,48 +1,23 @@ | ||
package config | ||
|
||
import ( | ||
"errors" | ||
"fmt" | ||
"time" | ||
|
||
"github.com/spf13/viper" | ||
) | ||
|
||
type BalanceWorkerConfiguration struct { | ||
DLQ DLQConfiguration | ||
Retry RetryConfiguration | ||
ConsumerGroupName string | ||
ConsumerConfiguration `mapstructure:",squash"` | ||
} | ||
|
||
func (c BalanceWorkerConfiguration) Validate() error { | ||
if err := c.DLQ.Validate(); err != nil { | ||
return fmt.Errorf("poision queue: %w", err) | ||
} | ||
|
||
if err := c.Retry.Validate(); err != nil { | ||
return fmt.Errorf("retry: %w", err) | ||
} | ||
|
||
if c.ConsumerGroupName == "" { | ||
return errors.New("consumer group name is required") | ||
if err := c.ConsumerConfiguration.Validate(); err != nil { | ||
return err | ||
} | ||
|
||
return nil | ||
} | ||
|
||
func ConfigureBalanceWorker(v *viper.Viper) { | ||
v.SetDefault("balanceWorker.dlq.enabled", true) | ||
ConfigureConsumer(v, "balanceWorker") | ||
v.SetDefault("balanceWorker.dlq.topic", "om_sys.balance_worker_dlq") | ||
v.SetDefault("balanceWorker.dlq.autoProvision.enabled", true) | ||
v.SetDefault("balanceWorker.dlq.autoProvision.partitions", 1) | ||
|
||
v.SetDefault("balanceWorker.dlq.throttle.enabled", true) | ||
// Let's throttle poision queue to 10 messages per second | ||
v.SetDefault("balanceWorker.dlq.throttle.count", 10) | ||
v.SetDefault("balanceWorker.dlq.throttle.duration", time.Second) | ||
|
||
v.SetDefault("balanceWorker.retry.maxRetries", 5) | ||
v.SetDefault("balanceWorker.retry.initialInterval", 100*time.Millisecond) | ||
|
||
v.SetDefault("balanceWorker.consumerGroupName", "om_balance_worker") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.