.
This commit is contained in:
parent
98b4ca0918
commit
abe7fe9c40
@ -1,6 +1,7 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"crypto/tls"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
@ -84,7 +85,10 @@ func ConnectToExchangeForPublish(host, username, password string) {
|
||||
return
|
||||
}
|
||||
|
||||
err = ch.Publish("pubsub", msg.Topic, false, false, rabbitmq.Publishing{
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
|
||||
defer cancel()
|
||||
|
||||
err = ch.PublishWithContext(ctx, "pubsub", msg.Topic, false, false, rabbitmq.Publishing{
|
||||
ContentType: "application/json",
|
||||
AppId: RabbitForwarderPath,
|
||||
Body: []byte(msg.Body),
|
||||
@ -94,7 +98,7 @@ func ConnectToExchangeForPublish(host, username, password string) {
|
||||
})
|
||||
|
||||
if err != nil {
|
||||
if connection.IsClosed() {
|
||||
if ch.IsClosed() || connection.IsClosed() {
|
||||
select {
|
||||
case messageQueue <- msg:
|
||||
log.Printf("requed ...")
|
||||
|
Loading…
Reference in New Issue
Block a user