This commit is contained in:
shoopea 2019-07-01 10:38:52 +08:00
parent 1ca4769504
commit 5c6a38c7b9

View File

@ -175,7 +175,7 @@ func MQKeepAliveWorker() {
Path: x.Queue,
SSL: false,
}
clt.Connection, err = amqp.Dial("amqp://" + c.User + ":" + c.Password + "@" + c.Host + "/" + c.Path)
clt.Connection, err = amqp.Dial("amqp://" + clt.User + ":" + clt.Password + "@" + clt.Host + "/" + clt.Path)
logOnError(err, "MQKeepAliveWorker : Failed to connect to RabbitMQ")
if err != nil {
clt.Connection.Close()
@ -236,7 +236,7 @@ func MQTGCmdWorker(id int, cmds <-chan TGCommand) {
if _, ok := clientsKeepAlive.Load(c.FromUserID64); ok {
j, err := json.Marshal(c)
logOnError(err, "MQTGCmdWorker["+strconv.Itoa(id)+"] : Marshal(c)")
//log.Printf("MQTGCmdWorker["+strconv.Itoa(id)+"] : new command.\n%s\n", string(j))
log.Printf("MQTGCmdWorker["+strconv.Itoa(id)+"] : new command.\n%s\n", string(j))
for clientsQueue[c.FromUserID64].Connection.IsClosed() {
log.Printf("MQKeepAliveWorker : Resetting MQ connection for #%d.\n", c.FromUserID64)
clientsQueue[c.FromUserID64].Connection, err = amqp.Dial("amqp://" + clientsQueue[c.FromUserID64].User + ":" + clientsQueue[c.FromUserID64].Password + "@" + clientsQueue[c.FromUserID64].Host + "/" + clientsQueue[c.FromUserID64].Path)
@ -274,15 +274,16 @@ func MQTGCmdWorker(id int, cmds <-chan TGCommand) {
}
err = clientsQueue[c.FromUserID64].Channel.Publish(
"", // exchange
"", // exchange
clientsQueue[c.FromUserID64].Queue.Name, // routing key
false, // mandatory
false, // immediate
false, // mandatory
false, // immediate
amqp.Publishing{
ContentType: "application/json",
Body: []byte(j),
})
logOnError(err, "MQTGCmdWorker["+strconv.Itoa(id)+"] : Publishing message.")
log.Printf("MQTGCmdWorker[" + strconv.Itoa(id) + "] : Message published.")
} else {
log.Printf("MQTGCmdWorker["+strconv.Itoa(id)+"] : client %d offline.\n", c.FromUserID64)
}