This commit is contained in:
Adam Majer 2024-08-14 18:24:02 +02:00
parent 98b4ca0918
commit abe7fe9c40

View File

@ -1,6 +1,7 @@
package main package main
import ( import (
"context"
"crypto/tls" "crypto/tls"
"encoding/json" "encoding/json"
"fmt" "fmt"
@ -84,7 +85,10 @@ func ConnectToExchangeForPublish(host, username, password string) {
return 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", ContentType: "application/json",
AppId: RabbitForwarderPath, AppId: RabbitForwarderPath,
Body: []byte(msg.Body), Body: []byte(msg.Body),
@ -94,7 +98,7 @@ func ConnectToExchangeForPublish(host, username, password string) {
}) })
if err != nil { if err != nil {
if connection.IsClosed() { if ch.IsClosed() || connection.IsClosed() {
select { select {
case messageQueue <- msg: case messageQueue <- msg:
log.Printf("requed ...") log.Printf("requed ...")