Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add description of the reconnection behavior. #16

Merged
merged 2 commits into from
Jan 5, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<p align="center"><img src="https://habrastorage.org/webt/-0/x1/z4/-0x1z48ndvvopw_baizloa6r1hs.png"></p>

[![GoDoc](https://godoc.org/github.com/furdarius/rabbitroutine?status.svg)](https://godoc.org/github.com/furdarius/rabbitroutine)
[![PkgGoDev](https://pkg.go.dev/badge/github.com/furdarius/rabbitroutine)](https://pkg.go.dev/github.com/furdarius/rabbitroutine)
[![Build Status](https://travis-ci.org/furdarius/rabbitroutine.svg?branch=master)](https://travis-ci.org/furdarius/rabbitroutine)
[![Go Report Card](https://goreportcard.com/badge/github.com/furdarius/rabbitroutine)](https://goreportcard.com/report/github.com/furdarius/rabbitroutine)

Expand Down
9 changes: 7 additions & 2 deletions connector.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,14 @@ const (

// Config stores reconnect options.
type Config struct {
// Max reconnect attempts.
// ReconnectAttempts is a number that defines how many reconnect attempts would be made after the connection was broke off.
// After a new connection have been established this number is reset.
// So, when a next broke off happens there will be not less than ReconnectAttempts attempts to reconnect.
// In case of maximum reconnect attempts exceeded* Dial or DialConfig func will just return error and that's it.
// It's your turn to handle this situation.
// But in generall it's better have unlimited ReconnectAttemts and log errors using Connector.AddRetriedListener (see examples dir)
ReconnectAttempts uint
// How long to wait between reconnect.
// How long to wait between reconnect attempts.
Wait time.Duration
}

Expand Down
6 changes: 6 additions & 0 deletions publisher.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,12 @@ func NewEnsurePublisher(p *Pool) *EnsurePublisher {
// that msg have been successfully received by the server.
// Returns error if no queue is bound that matches the routing key.
// It will blocks until is either message is successfully delivered, context has cancelled or error received.
//
// While reconnecting is in process Publishing can't be finished, because amqp.Channel can't be received.
// Publisher doesn't know about the state of the connection, so for publisher reconniction is the same as "request took too long to be finished".
// "Too long" is defined by context.Context that is passed as first argument to Publish.
// If context has been cancelled, Publish returns context.DeadlineExceeded error.
// If connection was reestablished and Publish had enough time to be finished, then request would be finished successfully.
func (p *EnsurePublisher) Publish(ctx context.Context, exchange, key string, msg amqp.Publishing) error {
k, err := p.pool.ChannelWithConfirm(ctx)
if err != nil {
Expand Down