This commit is contained in:
shoopea 2019-06-28 16:07:57 +08:00
parent 3731e36e5f
commit ffff09ca65

View File

@ -34,12 +34,13 @@ func MQGetMsgWorker(id int, msgs chan<- ChatWarsMessage) {
time.Sleep(15 * time.Second)
} else {
ch, err := c.Connection.Channel()
c.Channel = ch
logOnError(err, "MQGetMsgWorker["+strconv.Itoa(id)+"] : Failed to open a channel")
if err != nil {
ch.Close()
c.Channel.Close()
time.Sleep(15 * time.Second)
} else {
q, err := ch.QueueDeclare(
q, err := c.Channel.QueueDeclare(
"msg", // name
false, // durable
false, // delete when unused
@ -49,8 +50,8 @@ func MQGetMsgWorker(id int, msgs chan<- ChatWarsMessage) {
)
logOnError(err, "MQGetMsgWorker["+strconv.Itoa(id)+"] : Failed to declare a queue")
if err != nil {
ch.Close()
conn.Close()
c.Channel.Close()
c.Connection.Close()
time.Sleep(15 * time.Second)
} else {
m, err := ch.Consume(
@ -64,8 +65,8 @@ func MQGetMsgWorker(id int, msgs chan<- ChatWarsMessage) {
)
logOnError(err, "MQGetMsgWorker["+strconv.Itoa(id)+"] : Failed to register a consumer")
if err != nil {
ch.Close()
conn.Close()
c.Channel.Close()
c.Connection.Close()
time.Sleep(15 * time.Second)
} else {
for d := range m {
@ -76,8 +77,8 @@ func MQGetMsgWorker(id int, msgs chan<- ChatWarsMessage) {
msgs <- x
}
}
ch.Close()
conn.Close()
c.Channel.Close()
c.Connection.Close()
}
}