Updated rabbitmq
parent
8c0f976ac4
commit
82f8520e8a
|
@ -37,51 +37,18 @@ func Init() {
|
||||||
log.Fatalln("Failed to open a channel", err)
|
log.Fatalln("Failed to open a channel", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
//defer ch.Close()
|
|
||||||
|
|
||||||
Channel = ch
|
Channel = ch
|
||||||
|
|
||||||
log.Debug("RabbitMQ connected")
|
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, "mails", &MailQueue)
|
||||||
declareQueue(ch, "pictures", &PictureQueue)
|
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) {
|
func declareQueue(channel *amqp.Channel, name string, queue *amqp.Queue) {
|
||||||
q, err := channel.QueueDeclare(
|
q, err := channel.QueueDeclare(
|
||||||
name, // name
|
name, // name
|
||||||
false, // durable
|
true, // durable
|
||||||
false, // delete when unused
|
false, // delete when unused
|
||||||
false, // exclusive
|
false, // exclusive
|
||||||
false, // no-wait
|
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.Fatalln("Failed to declare a queue", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
log.Debugln("declareQ", q.Name)
|
|
||||||
|
|
||||||
*queue = q
|
*queue = q
|
||||||
|
|
||||||
log.Infoln("queue", MailQueue)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func Publish(queue amqp.Queue, body string) {
|
func Publish(queue amqp.Queue, body string) {
|
||||||
|
@ -108,8 +71,9 @@ func Publish(queue amqp.Queue, body string) {
|
||||||
false, // mandatory
|
false, // mandatory
|
||||||
false, // immediate
|
false, // immediate
|
||||||
amqp.Publishing{
|
amqp.Publishing{
|
||||||
ContentType: "application/json",
|
DeliveryMode: amqp.Persistent,
|
||||||
Body: []byte(body),
|
ContentType: "application/json",
|
||||||
|
Body: []byte(body),
|
||||||
})
|
})
|
||||||
|
|
||||||
if err != nil {
|
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) {
|
func PublishMail(mailMessage structs.RabbitmqMailMessage) {
|
||||||
js := structs.RabbitmqMailMessage{Mail: mail, TemplateId: templateId, LanguageId: languageId, BodyData: &bodyData}
|
reqBody, err := json.MarshalIndent(&mailMessage, "", "\t")
|
||||||
|
|
||||||
reqBody, err := json.MarshalIndent(&js, "", "\t")
|
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Infoln("error reqBody", err)
|
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) {
|
func PublishPicture(pictureMessage structs.RabbitmqPictureMessage) {
|
||||||
//js := structs.RabbitmqPictureMessage{Picture: picture, UserId: userId}
|
|
||||||
|
|
||||||
reqBody, err := json.MarshalIndent(&pictureMessage, "", "\t")
|
reqBody, err := json.MarshalIndent(&pictureMessage, "", "\t")
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
Loading…
Reference in New Issue