From abe7fe9c40936699dc2fd062aff35025cdfd21554a3a9955701ae398d372a899 Mon Sep 17 00:00:00 2001 From: Adam Majer Date: Wed, 14 Aug 2024 18:24:02 +0200 Subject: [PATCH] . --- gitea-events-rabbitmq-publisher/rabbitmq.go | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/gitea-events-rabbitmq-publisher/rabbitmq.go b/gitea-events-rabbitmq-publisher/rabbitmq.go index 8b14537..a7f54ec 100644 --- a/gitea-events-rabbitmq-publisher/rabbitmq.go +++ b/gitea-events-rabbitmq-publisher/rabbitmq.go @@ -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 ...")