Skip to content

auto reconnecting example for github.com/streadway/amqp Connection & Channel

License

Notifications You must be signed in to change notification settings

smallcase/go-amqp-reconnect

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

16 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

streadway/amqp Conneciton/Channel auto reconnect wrap

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.

How to change existing code

  1. add import import "github.com/smallcase/go-amqp-reconnect/rabbitmq"
  2. Replace amqp.Connection/amqp.Channel with rabbitmq.Connection/rabbitmq.Channel

Example

Close by developer

go run example/close/demo.go

Auto reconnect

go run example/reconnect/demo.go

RabbitMQ Cluster with Reconnect

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"})

Set reconnect delay seconds

You can set reconnect delay seconds with environment variable "AMQP_RECONN_DELAY_SECONDS" e.g.

# Default to 3s.
export AMQP_RECONN_DELAY_SECONDS=10 

About

auto reconnecting example for github.com/streadway/amqp Connection & Channel

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Go 100.0%