This commit is contained in:
shoopea 2019-06-28 16:34:15 +08:00
parent f7673e7cf1
commit 4728679b7d
2 changed files with 21 additions and 21 deletions

21
mq.go
View File

@ -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
}

View File

@ -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(