test
This commit is contained in:
parent
e70e4677cd
commit
6b320ff0ee
14
mq.go
14
mq.go
@ -7,5 +7,19 @@ import (
|
||||
func (c *MQClient) Open() error {
|
||||
conn, err := amqp.Dial("amqp://" + c.User + ":" + c.Password + "@" + c.Host + "/" + c.Path)
|
||||
c.Connection = conn
|
||||
|
||||
if err != nil {
|
||||
c.Connection.Close()
|
||||
return err
|
||||
}
|
||||
|
||||
ch, err := c.Connection.Channel()
|
||||
c.Channel = ch
|
||||
if err != nil {
|
||||
c.Channel.Close()
|
||||
c.Connection.Close()
|
||||
return err
|
||||
}
|
||||
|
||||
return err
|
||||
}
|
||||
|
12
workers.go
12
workers.go
@ -27,18 +27,7 @@ func MQGetMsgWorker(id int, msgs chan<- ChatWarsMessage) {
|
||||
|
||||
err := c.Open()
|
||||
|
||||
logOnError(err, "MQGetMsgWorker["+strconv.Itoa(id)+"] : Failed to connect to RabbitMQ")
|
||||
if err != nil {
|
||||
c.Connection.Close()
|
||||
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 {
|
||||
c.Channel.Close()
|
||||
time.Sleep(15 * time.Second)
|
||||
} else {
|
||||
q, err := c.Channel.QueueDeclare(
|
||||
"msg", // name
|
||||
false, // durable
|
||||
@ -83,7 +72,6 @@ func MQGetMsgWorker(id int, msgs chan<- ChatWarsMessage) {
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
log.Printf("MQGetMsgWorker[" + strconv.Itoa(id) + "] : Closing.")
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user