Disabled rabbitmq auto-ack
parent
9c32e1b9ff
commit
67ba48a3db
2
go.mod
2
go.mod
|
@ -6,5 +6,5 @@ require (
|
|||
github.com/BurntSushi/toml v0.3.1
|
||||
github.com/gofiber/fiber/v2 v2.12.0
|
||||
github.com/sirupsen/logrus v1.8.1
|
||||
github.com/streadway/amqp v1.0.0 // indirect
|
||||
github.com/streadway/amqp v1.0.0
|
||||
)
|
||||
|
|
|
@ -31,7 +31,7 @@ type Mail struct {
|
|||
BodyData interface{}
|
||||
}
|
||||
|
||||
func NewMail(to []string, templateId int, languageId int, bodyData interface{}) {
|
||||
func NewMail(to []string, templateId int, languageId int, bodyData interface{}) error {
|
||||
log.Infoln("new mail", templateId, bodyData)
|
||||
|
||||
mail := Mail{
|
||||
|
@ -48,12 +48,17 @@ func NewMail(to []string, templateId int, languageId int, bodyData interface{})
|
|||
|
||||
if err != nil {
|
||||
log.Fatalln("error parsing", err)
|
||||
return err
|
||||
}
|
||||
|
||||
mail.Send(body)
|
||||
if err = mail.Send(body); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
func (m *Mail) Send(body string) {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (m *Mail) Send(body string) error {
|
||||
msg := "From: " + cfg.Mail.From + "\n" +
|
||||
"To: " + strings.Join(m.To, ",") + "\n" +
|
||||
"Subject: " + m.Subject + "\n" +
|
||||
|
@ -64,8 +69,10 @@ func (m *Mail) Send(body string) {
|
|||
|
||||
if err != nil {
|
||||
log.Warnln("smtp error:", err)
|
||||
return err
|
||||
} else {
|
||||
log.Debugln("send mail")
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -49,15 +49,19 @@ func Init() {
|
|||
log.Debug("RabbitMQ connected")
|
||||
|
||||
msgs, err := ch.Consume(
|
||||
"mails",
|
||||
"",
|
||||
true,
|
||||
false,
|
||||
false,
|
||||
false,
|
||||
nil,
|
||||
"mails", // queue
|
||||
"", // consumer
|
||||
false, // auto-ack
|
||||
false, // exclusive
|
||||
false, // no-local
|
||||
false, // no-wait
|
||||
nil, // args
|
||||
)
|
||||
|
||||
if err != nil {
|
||||
log.Fatalln("Consume err", err)
|
||||
}
|
||||
|
||||
forever := make(chan []byte)
|
||||
|
||||
go func() {
|
||||
|
@ -74,7 +78,9 @@ func Init() {
|
|||
|
||||
log.Infoln("input", mail)
|
||||
|
||||
mailer.NewMail([]string{mail.Mail}, mail.TemplateId, mail.LanguageId, mail.BodyData)
|
||||
if err = mailer.NewMail([]string{mail.Mail}, mail.TemplateId, mail.LanguageId, mail.BodyData); err == nil {
|
||||
d.Ack(false)
|
||||
}
|
||||
}
|
||||
}()
|
||||
|
||||
|
|
Loading…
Reference in New Issue