integrated rabbitmq

alpha
alex 2022-12-26 20:50:17 +01:00
parent 2e6cbef3e1
commit 0e25f2b407
5 changed files with 37 additions and 22 deletions

17
main.go
View File

@ -4,7 +4,6 @@ import (
"clickandjoin.app/emailserver/mailer" "clickandjoin.app/emailserver/mailer"
"clickandjoin.app/emailserver/modules/config" "clickandjoin.app/emailserver/modules/config"
"clickandjoin.app/emailserver/modules/rabbitmq" "clickandjoin.app/emailserver/modules/rabbitmq"
"clickandjoin.app/emailserver/modules/structs"
"github.com/sirupsen/logrus" "github.com/sirupsen/logrus"
) )
@ -17,23 +16,9 @@ func init() {
logrus.Println("Debug:", config.Cfg.Debug) logrus.Println("Debug:", config.Cfg.Debug)
rabbitmq.Init()
mailer.Init() mailer.Init()
} }
func main() { func main() {
logrus.Println("test") rabbitmq.Init()
test := struct {
Url string
Username string
ActivationCode string
}{
Url: "https://test.de",
Username: "Ben",
ActivationCode: "912 211",
}
mailer.NewMail(structs.Mail{To: []string{"info@clickandjoin.de"}, TemplateId: "emailVerification", LanguageId: "de", BodyData: test})
} }

View File

@ -1,9 +1,12 @@
package rabbitmq package rabbitmq
import ( import (
"encoding/json"
"fmt" "fmt"
"clickandjoin.app/emailserver/mailer"
"clickandjoin.app/emailserver/modules/config" "clickandjoin.app/emailserver/modules/config"
"clickandjoin.app/emailserver/modules/structs"
amqp "github.com/rabbitmq/amqp091-go" amqp "github.com/rabbitmq/amqp091-go"
"github.com/sirupsen/logrus" "github.com/sirupsen/logrus"
) )
@ -62,7 +65,27 @@ func Init() {
go func() { go func() {
for d := range msgs { for d := range msgs {
logrus.Printf("Received a message: %s", d.Body) logrus.Debugln("RECV MAIL")
mailMessage := structs.RabbitMqMailMessage{}
if err := json.Unmarshal(d.Body, &mailMessage); err != nil {
logrus.Errorln("Failed to unmarshal json message, err:", err)
continue
}
err = mailer.NewMail(structs.Mail{
To: []string{"info@clickandjoin.de"},
TemplateId: mailMessage.TemplateId,
LanguageId: mailMessage.LanguageId,
BodyData: mailMessage.BodyData})
if err != nil {
logrus.Errorln("Failed to send new mail, err:", err)
continue
}
d.Ack(false)
} }
}() }()

View File

@ -5,3 +5,10 @@ type RabbitMqMessage struct {
Rec string Rec string
Body any Body any
} }
type RabbitMqMailMessage struct {
UserMail string `json:"m"`
TemplateId string `json:"t"`
LanguageId string `json:"l"`
BodyData map[string]interface{} `json:"b"`
}

View File

@ -3,10 +3,10 @@
<body> <body>
<h1>%header%</h1> <h1>%header%</h1>
<p>%informationText%</p> <p>%informationText%</p>
<p>{{.ActivationCode}}</p> <p><b>{{.activation_code}}</b></p>
<a <a
href="{{.Url}}" href="{{.url}}"
style=" style="
padding: 8px 20px; padding: 8px 20px;
background-color: #4b72fa; background-color: #4b72fa;
@ -21,6 +21,6 @@
>%buttonText%</a >%buttonText%</a
> >
<p>%alternativeUrl% <a href="{{.Url}}">{{.Url}}</a></p> <p>%alternativeUrl% <a href="{{.url}}">{{.url}}</a></p>
</body> </body>
</html> </html>

View File

@ -6,8 +6,8 @@
"de": "Ihr E-Mail-Bestätigungscode" "de": "Ihr E-Mail-Bestätigungscode"
}, },
"header": { "header": {
"en": "Hello {{.Username}}", "en": "Good day,",
"de": "Hallo {{.Username}}," "de": "Guten Tag,"
}, },
"informationText": { "informationText": {
"en": "to confirm your identity we need to verify your email.", "en": "to confirm your identity we need to verify your email.",