Skip to content

Commit

Permalink
don't read topic and consumer group id from runtime configuration
Browse files Browse the repository at this point in the history
These won't be changing at runtime, so there's no need to complicate the
initialization by making these configurable. The topic's prefix is
configurable, and that's the part that will change from environment to
environment at runtime.

BACK-2554
  • Loading branch information
ewollesen committed Oct 31, 2024
1 parent d6b82b5 commit 28fdf06
Showing 1 changed file with 4 additions and 13 deletions.
17 changes: 4 additions & 13 deletions data/service/service/standard.go
Original file line number Diff line number Diff line change
Expand Up @@ -483,22 +483,13 @@ func (s *Standard) initializeAlertsEventsHandler() error {
return err
}

// In addition to the CloudEventsConfig, additional specific config values
// are needed.
config := &struct {
KafkaAlertsTopics []string `envconfig:"KAFKA_ALERTS_TOPICS" default:"alerts,deviceData.alerts"`
KafkaAlertsGroupID string `envconfig:"KAFKA_ALERTS_CONSUMER_GROUP" required:"true"`
}{}
if err := envconfig.Process("", config); err != nil {
return errors.Wrap(err, "Unable to process envconfig")
}

topics := []string{"data.alerts", "data.deviceData.alerts"}
// Some kafka topics use a `<env>-` as a prefix. But MongoDB CDC topics are created with
// `<env>.`. This code is using CDC topics, so ensuring that a `.` is used for alerts events
// lines everything up as expected.
topicPrefix := strings.ReplaceAll(commonConfig.KafkaTopicPrefix, "-", ".")
prefixedTopics := make([]string, 0, len(config.KafkaAlertsTopics))
for _, topic := range config.KafkaAlertsTopics {
prefixedTopics := make([]string, 0, len(topics))
for _, topic := range topics {
prefixedTopics = append(prefixedTopics, topicPrefix+topic)
}

Expand All @@ -517,7 +508,7 @@ func (s *Standard) initializeAlertsEventsHandler() error {

runnerCfg := dataEvents.SaramaRunnerConfig{
Brokers: commonConfig.KafkaBrokers,
GroupID: config.KafkaAlertsGroupID,
GroupID: "alerts",
Topics: prefixedTopics,
Sarama: commonConfig.SaramaConfig,
MessageConsumer: &dataEvents.AlertsEventsConsumer{
Expand Down

0 comments on commit 28fdf06

Please sign in to comment.