Updated rabbitmq

master
Alex 2021-08-01 15:05:03 +02:00
parent 8c0f976ac4
commit 82f8520e8a
1 changed files with 6 additions and 46 deletions

View File

@ -37,51 +37,18 @@ func Init() {
log.Fatalln("Failed to open a channel", err)
}
//defer ch.Close()
Channel = ch
log.Debug("RabbitMQ connected")
/*
mailQueue, err := ch.QueueDeclare(
"mails", // name
false, // durable
false, // delete when unused
false, // exclusive
false, // no-wait
nil, // arguments
)
if err != nil {
log.Fatalln("Failed to declare a queue", err)
}
MailQueue = mailQueue */
declareQueue(ch, "mails", &MailQueue)
declareQueue(ch, "pictures", &PictureQueue)
/*
pictureQueue, err := ch.QueueDeclare(
"picture", // name
false, // durable
false, // delete when unused
false, // exclusive
false, // no-wait
nil, // arguments
)
if err != nil {
log.Fatalln("Failed to declare a queue", err)
}
PictureQueue = pictureQueue */
}
func declareQueue(channel *amqp.Channel, name string, queue *amqp.Queue) {
q, err := channel.QueueDeclare(
name, // name
false, // durable
true, // durable
false, // delete when unused
false, // exclusive
false, // no-wait
@ -92,11 +59,7 @@ func declareQueue(channel *amqp.Channel, name string, queue *amqp.Queue) {
log.Fatalln("Failed to declare a queue", err)
}
log.Debugln("declareQ", q.Name)
*queue = q
log.Infoln("queue", MailQueue)
}
func Publish(queue amqp.Queue, body string) {
@ -108,8 +71,9 @@ func Publish(queue amqp.Queue, body string) {
false, // mandatory
false, // immediate
amqp.Publishing{
ContentType: "application/json",
Body: []byte(body),
DeliveryMode: amqp.Persistent,
ContentType: "application/json",
Body: []byte(body),
})
if err != nil {
@ -117,10 +81,8 @@ func Publish(queue amqp.Queue, body string) {
}
}
func PublishMail(mail string, templateId int, languageId int, bodyData json.RawMessage) {
js := structs.RabbitmqMailMessage{Mail: mail, TemplateId: templateId, LanguageId: languageId, BodyData: &bodyData}
reqBody, err := json.MarshalIndent(&js, "", "\t")
func PublishMail(mailMessage structs.RabbitmqMailMessage) {
reqBody, err := json.MarshalIndent(&mailMessage, "", "\t")
if err != nil {
log.Infoln("error reqBody", err)
@ -130,8 +92,6 @@ func PublishMail(mail string, templateId int, languageId int, bodyData json.RawM
}
func PublishPicture(pictureMessage structs.RabbitmqPictureMessage) {
//js := structs.RabbitmqPictureMessage{Picture: picture, UserId: userId}
reqBody, err := json.MarshalIndent(&pictureMessage, "", "\t")
if err != nil {