auto reconnecting library for https://github.com/rabbitmq/amqp091-go, that doesn't reconnect on server shutdown To simply developers, here is auto reconnect wrap with detail comments.
This library based on https://github.com/isayme/go-amqp-reconnect, but also supports some external methods.
- rabbitmq.Dial(url) & rabbitmq.DialConfig(url, config) - creates connection with reconnect
- connection.Channel() - creates channel with reconnect
- connection.Close() - clearly closes channel without reconnect
- channel.Qos() - restore settings for channel
- channel.QueueDeclare() & channel.QueueDeclarePassive() - restore autoDeleted queues
- channel.ExchangeDeclare() & channel.ExchangeDeclarePassive() - restores autoDeleted exchanges
- channel.Close() - clearly closes channel without reconnect
Another methods call through aliases with mutex, to avoid race condition
- add import
import "github.com/AsidStorm/go-amqp-reconnect/rabbitmq"
- Replace
amqp.Connection
/amqp.Channel
withrabbitmq.Connection
/rabbitmq.Channel
!
You can set rabbitmq.Debug = true
variable to view debug messages
rabbitmq.ReconnectDelay
determines time that app wait for new reconnect try, defaults totime.Second * 3
go run examples/close_by_developer/demo.go -url=amqp://user:password@host:port/
go run examples/close_with_reconnect/demo.go -url=amqp://user:password@host:port/
after start, drop connection through RabbitMQ management panel on connection tabs, or restart RabbitMQ server
go run examples/graceful_shutdown/demo.go -url=amqp://user:password@host:port/
after start try to interrupt with (Ctrl or Cmd + C) app, see that all messages processed and only after that all connections closed