Go's AMQP library by design does not permit redialing on connection closures out of the box, since a new topology of exchange queue mapping needs to be generated on every reconnection. This necessitates the need for explicitly listening to connection closure events on the NotifyClose()
channel to perform redials. The snippet below describes the redialing to the broker backend
for {
conn, err := amqp.Dial("connection_string")
notify := conn.NotifyClose(make(chan *amqp.Error)) // channel to receive error events from broker
ch, err := conn.Channel()
msgs, err := ch.consume(
for {
select { //check connection
case err = <-notify:
//work with error
break // perform reconnection
case d = <-msgs:
// work with the message
}
}
)
}
This is a reliability problem, and as such the implementation for it should be centralized as part of the Dial()
method.