Library that wraps sarama/kafka on high-level producer and consumer for the Asvins project
...
cfg := common_io.Config{}
err := config.Load("common_io_config.gcfg", &cfg)
if err != nil {
log.Fatal(err)
}
// Producer
producer, err = common_io.NewProducer(cfg)
if err != nil {
log.Fatal(err)
}
defer producer.TearDown()
// Consumer
consumer = common_io.NewConsumer(cfg)
consumer.HandleTopic("send_mail", mailer.SendMail)
if err = consumer.StartListening(); err != nil {
log.Fatal(err)
}
defer consumer.TearDown()
...
Below is an example of a common_io_config.gcfg
[modulename]
value = notification
[kafka]
brokerlist = 127.0.0.1:9092
maxretry = 5
[zookeeper]
addrlist = 127.0.0.1:2181
maxretry = 5
...
m := mailer.Mail{
To: []string{"asvins.poli@gmail.com"},
Subject: "Test from Asvins server",
Body: "Test Message from Asvins Servers.\n -- Asvins Team",
}
b, err := json.Marshal(&m)
if err != nil {
return errors.BadRequest(err.Error())
}
producer.Publish("send_mail", b)
...