This commit is contained in:
shoopea 2019-06-28 17:42:33 +08:00
parent 362800da22
commit 37945c5b60

View File

@ -168,11 +168,24 @@ func MQKeepAliveWorker() {
k := v.(*MQKeepAlive)
k.Date = x.Date
} else {
clt := MQClient{}
clt.Connection, err = amqp.Dial("amqp://" + cfg.Rabbit.User + ":" + cfg.Rabbit.Password + "@" + cfg.Rabbit.Host + "/" + x.Queue)
clt := MQClient{
User: cfg.Rabbit.User,
Password: cfg.Rabbit.Password,
Host: cfg.Rabbit.Host,
Path: x.Queue,
SSL: false,
}
clt.Connection, err = amqp.Dial("amqp://" + c.User + ":" + c.Password + "@" + c.Host + "/" + c.Path)
logOnError(err, "MQKeepAliveWorker : Failed to connect to RabbitMQ")
if err != nil {
clt.Connection.Close()
} else {
clt.Channel, err = clt.Connection.Channel()
logOnError(err, "MQKeepAliveWorker : Failed to open a channel")
if err != nil {
clt.Channel.Close()
clt.Connection.Close()
} else {
clt.Queue, err = clt.Channel.QueueDeclare(
"msg", // name
false, // durable
@ -182,6 +195,12 @@ func MQKeepAliveWorker() {
nil, // arguments
)
logOnError(err, "MQKeepAliveWorker : Failed to declare a queue")
if err != nil {
clt.Channel.Close()
clt.Connection.Close()
}
}
}
clientsKeepAlive.Store(x.UserID64, &x)
clientsQueue[x.UserID64] = &clt