From 4728679b7dff19612226df905cef4003e248de7c Mon Sep 17 00:00:00 2001 From: shoopea Date: Fri, 28 Jun 2019 16:34:15 +0800 Subject: [PATCH] test --- mq.go | 21 +-------------------- workers.go | 21 ++++++++++++++++++++- 2 files changed, 21 insertions(+), 21 deletions(-) diff --git a/mq.go b/mq.go index c2722be..e0a5280 100644 --- a/mq.go +++ b/mq.go @@ -1,24 +1,5 @@ package main import ( - "github.com/streadway/amqp" +//"github.com/streadway/amqp" ) - -func Open(c *MQClient) error { - var err error - c.Connection, err = amqp.Dial("amqp://" + c.User + ":" + c.Password + "@" + c.Host + "/" + c.Path) - - if err != nil { - c.Connection.Close() - return err - } - - c.Channel, err = c.Connection.Channel() - if err != nil { - c.Channel.Close() - c.Connection.Close() - return err - } - - return err -} diff --git a/workers.go b/workers.go index 8de03be..d1b9601 100644 --- a/workers.go +++ b/workers.go @@ -13,6 +13,25 @@ import ( tb "gopkg.in/tucnak/telebot.v2" ) +func (c *MQClient) Open() error { + var err error + c.Connection, err = amqp.Dial("amqp://" + c.User + ":" + c.Password + "@" + c.Host + "/" + c.Path) + + if err != nil { + c.Connection.Close() + return err + } + + c.Channel, err = c.Connection.Channel() + if err != nil { + c.Channel.Close() + c.Connection.Close() + return err + } + + return err +} + func MQGetMsgWorker(id int, msgs chan<- ChatWarsMessage) { //log.Printf("MQGetMsgWorker[" + strconv.Itoa(id) + "] : Starting.") var x ChatWarsMessage @@ -24,7 +43,7 @@ func MQGetMsgWorker(id int, msgs chan<- ChatWarsMessage) { c.Path = cfg.Rabbit.Path c.SSL = false - err := Open(c) + err := c.Open() if err != nil { q, err := c.Channel.QueueDeclare(