Skip to content

Latest commit

 

History

History
31 lines (23 loc) · 1006 Bytes

README.md

File metadata and controls

31 lines (23 loc) · 1006 Bytes

streadway/amqp Conneciton/Channel auto reconnect wrap

streadway/amqp 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/sirius1024/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/sirius1024/go-amqp-reconnect/rabbitmq"

rabbitmq.DialCluster([]string{"amqp://usr:[email protected]:5672/vhost","amqp://usr:[email protected]:5673/vhost","amqp://usr:[email protected]: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