rabbitmq/amqp091-go Connection/Channel does not reconnect if rabbitmq server restart/down and no cluster supported.
To simply developers, here is auto reconnect wrap with detail comments.
- add import
import "github.com/smallcase/go-amqp-reconnect/rabbitmq"
- Replace
amqp.Connection
/amqp.Channel
withrabbitmq.Connection
/rabbitmq.Channel
go run example/close/demo.go
go run example/reconnect/demo.go
import "github.com/smallcase/go-amqp-reconnect/rabbitmq"
rabbitmq.DialCluster([]string{"amqp://usr:pwd@127.0.0.1:5672/vhost","amqp://usr:pwd@127.0.0.1:5673/vhost","amqp://usr:pwd@127.0.0.1:5674/vhost"})
You can set reconnect delay seconds with environment variable "AMQP_RECONN_DELAY_SECONDS" e.g.
# Default to 3s.
export AMQP_RECONN_DELAY_SECONDS=10