Created
March 10, 2021 09:34
-
-
Save creative-cranels/e27ff8c0f0def3281898a3a70a8c7eda to your computer and use it in GitHub Desktop.
This file contains hidden or 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
// init kafka | |
kafkaURL := fmt.Sprintf("%v:%v", configData.Kafka.Host, configData.Kafka.Port) | |
kafkaReader := kafka.NewReader( | |
kafka.ReaderConfig{ | |
Brokers: []string{kafkaURL}, | |
Topic: configData.Kafka.Topic, | |
GroupID: configData.Kafka.GroupID, | |
MaxBytes: configData.Kafka.MaxBytes, | |
}, | |
) | |
for { | |
msg, err := app.Kafka.ReadMessage(context.Background()) | |
if err != nil { | |
panic(err) | |
} | |
var accepted *models.ConsumerData | |
err = json.Unmarshal(msg.Key, &accepted) | |
if err != nil { | |
continue | |
} | |
status := handler.SendEmail(accepted) | |
if !status { | |
return errors.New("email wasn't sent") | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment