diff --git a/amqp.go b/amqp.go index 9255899..74c49a0 100644 --- a/amqp.go +++ b/amqp.go @@ -143,17 +143,6 @@ type Session struct { isReady bool } -const ( - // When reconnecting to the server after connection failure - reconnectDelay = 5 * time.Second - - // When setting up the channel after a channel exception - reInitDelay = 2 * time.Second - - // When resending messages the server didn't confirm - resendDelay = 5 * time.Second -) - var ( errNotConnected = errors.New("not connected to a server") errAlreadyClosed = errors.New("already closed: not connected to the server") diff --git a/const.go b/const.go new file mode 100644 index 0000000..c5cc903 --- /dev/null +++ b/const.go @@ -0,0 +1,16 @@ +package main + +import ( + "time" +) + +const ( + // When reconnecting to the server after connection failure + reconnectDelay = 5 * time.Second + + // When setting up the channel after a channel exception + reInitDelay = 2 * time.Second + + // When resending messages the server didn't confirm + resendDelay = 5 * time.Second +) diff --git a/stomp.go b/stomp.go index 6055452..bca05ae 100644 --- a/stomp.go +++ b/stomp.go @@ -2,6 +2,7 @@ package main import ( "net/url" + "time" stomp "github.com/go-stomp/stomp/v3" log "github.com/sirupsen/logrus" @@ -78,13 +79,15 @@ sendMessageLoop: msg) if err != nil { + log.Errorln("Failed to publish message:", err) reconnectLoop: for { reconnectError := session.handleReconnect() if reconnectError == nil { break reconnectLoop } else { - log.Errorln("Failed to reconnect:", reconnectError.Error()) + log.Errorln("Failed to reconnect, retrying:", reconnectError.Error()) + <-time.After(reconnectDelay) } } } else {