Skip to content

Commit

Permalink
Move handle reconnection inside publish
Browse files Browse the repository at this point in the history
  • Loading branch information
kazeborja committed Jan 19, 2022
1 parent 8d6463e commit 3acda19
Showing 1 changed file with 23 additions and 18 deletions.
41 changes: 23 additions & 18 deletions stomp.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,20 +23,10 @@ func StartStomp(config *Config, queue *ConfirmationQueue) {
for {
msg, err := queue.Dequeue()
if err != nil {
return err
log.Errorln("Failed to read from queue:", err)
continue
}
stompSession.publish(msg)
if err != nil {
reconnectLoop:
for {
reconnectError := stompSession.handleReconnect()
if reconnectError == nil {
break reconnectLoop
} else {
log.Errorln("Failed to reconnect:", reconnectError.Error())
}
}
}
}

}
Expand Down Expand Up @@ -79,11 +69,26 @@ func (session *StompSession) handleReconnect() error {

// publish will send the message to the stomp message bus
// It will also handle any error in sending by calling handleReconnect
func (session *StompSession) publish(msg []byte) error {
err := session.conn.Send(
session.topic,
"text/plain",
msg)
func (session *StompSession) publish(msg []byte) {
sendMessageLoop:
for {
err := session.conn.Send(
session.topic,
"text/plain",
msg)

return err
if err != nil {
reconnectLoop:
for {
reconnectError := session.handleReconnect()
if reconnectError == nil {
break reconnectLoop
} else {
log.Errorln("Failed to reconnect:", reconnectError.Error())
}
}
} else {
break sendMessageLoop
}
}
}

0 comments on commit 3acda19

Please sign in to comment.